From 61af4a86a57d1f1179f9b71a581d268245969814 Mon Sep 17 00:00:00 2001 From: Richard Liebscher Date: Sat, 20 Apr 2024 14:29:53 +0200 Subject: [PATCH] Improve touchpad click detection --- app/qml/pages/TouchpadPage.qml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/qml/pages/TouchpadPage.qml b/app/qml/pages/TouchpadPage.qml index 03eba3a..be0af13 100644 --- a/app/qml/pages/TouchpadPage.qml +++ b/app/qml/pages/TouchpadPage.qml @@ -50,6 +50,7 @@ Page { property bool holding: false property bool wasMoved: false property bool scrolling: false + property int pressedTime: -1 PageHeader { id: header @@ -125,11 +126,16 @@ Page { acceptedButtons: Qt.AllButtons // FIXME: is ignored onPressed: { + console.log("pressed", wasMoved, mouse.x, mouse.y) wasMoved = false + lastX = mouse.x + lastY = mouse.y + pressedTime = Date.now() scrolling = ((touchpad.x + touchpad.width - mouse.x) < Theme.itemSizeSmall) } onPositionChanged: { + console.log("moved", pressed, mouse.x - lastX, mouse.y - lastY) if (pressed) { if (lastX !== 0xDEAD && plugin !== null) { if (scrolling) { @@ -146,14 +152,19 @@ Page { } onReleased: { + console.log("released") lastX = lastY = 0xDEAD scrolling = false } onClicked: { - if (!wasMoved && plugin !== null) { + console.log("clicked", wasMoved) + if (plugin !== null) { if (!holding) { - plugin.sendCommand({"singleclick": true}) + var clickPeriod = Date.now() - pressedTime + if (clickPeriod <= 500) { + plugin.sendCommand({"singleclick": true}) + } } else { plugin.sendCommand({"singlerelease": true}) holding = false @@ -162,6 +173,7 @@ Page { } onDoubleClicked: { + console.log("double clicked", wasMoved) if (!wasMoved && plugin !== null) { if (!holding) { plugin.sendCommand({"doubleclick": true}) @@ -173,6 +185,7 @@ Page { } onPressAndHold: { + console.log("pressed and hold", wasMoved) if (!wasMoved && plugin !== null) { plugin.sendCommand({"singlehold": true}) holding = true