Skip to content

Commit 61af4a8

Browse files
committed
Improve touchpad click detection
1 parent ea2401c commit 61af4a8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/qml/pages/TouchpadPage.qml

+15-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Page {
5050
property bool holding: false
5151
property bool wasMoved: false
5252
property bool scrolling: false
53+
property int pressedTime: -1
5354

5455
PageHeader {
5556
id: header
@@ -125,11 +126,16 @@ Page {
125126
acceptedButtons: Qt.AllButtons // FIXME: is ignored
126127

127128
onPressed: {
129+
console.log("pressed", wasMoved, mouse.x, mouse.y)
128130
wasMoved = false
131+
lastX = mouse.x
132+
lastY = mouse.y
133+
pressedTime = Date.now()
129134
scrolling = ((touchpad.x + touchpad.width - mouse.x) < Theme.itemSizeSmall)
130135
}
131136

132137
onPositionChanged: {
138+
console.log("moved", pressed, mouse.x - lastX, mouse.y - lastY)
133139
if (pressed) {
134140
if (lastX !== 0xDEAD && plugin !== null) {
135141
if (scrolling) {
@@ -146,14 +152,19 @@ Page {
146152
}
147153

148154
onReleased: {
155+
console.log("released")
149156
lastX = lastY = 0xDEAD
150157
scrolling = false
151158
}
152159

153160
onClicked: {
154-
if (!wasMoved && plugin !== null) {
161+
console.log("clicked", wasMoved)
162+
if (plugin !== null) {
155163
if (!holding) {
156-
plugin.sendCommand({"singleclick": true})
164+
var clickPeriod = Date.now() - pressedTime
165+
if (clickPeriod <= 500) {
166+
plugin.sendCommand({"singleclick": true})
167+
}
157168
} else {
158169
plugin.sendCommand({"singlerelease": true})
159170
holding = false
@@ -162,6 +173,7 @@ Page {
162173
}
163174

164175
onDoubleClicked: {
176+
console.log("double clicked", wasMoved)
165177
if (!wasMoved && plugin !== null) {
166178
if (!holding) {
167179
plugin.sendCommand({"doubleclick": true})
@@ -173,6 +185,7 @@ Page {
173185
}
174186

175187
onPressAndHold: {
188+
console.log("pressed and hold", wasMoved)
176189
if (!wasMoved && plugin !== null) {
177190
plugin.sendCommand({"singlehold": true})
178191
holding = true

0 commit comments

Comments
 (0)