Skip to content

Commit

Permalink
#64: workaround for long-press tap handler
Browse files Browse the repository at this point in the history
  • Loading branch information
antroids committed Dec 9, 2024
1 parent 0c638f2 commit 556ddaa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
4 changes: 4 additions & 0 deletions package/contents/ui/MouseHandlers.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ Item {
signal invokeKWinShortcut(string shortcut)

WidgetDragHandler {
id: dragHandler
Component.onCompleted: {
invokeKWinShortcut.connect(handlers.invokeKWinShortcut);
}
onInvokeKWinShortcut: tapHandler.stopLongPressTimer()
}

WidgetTapHandler {
id: tapHandler
Component.onCompleted: {
invokeKWinShortcut.connect(handlers.invokeKWinShortcut);
}
onInvokeKWinShortcut: dragHandler.stopDrag()
}

WidgetWheelHandler {
Expand Down
13 changes: 10 additions & 3 deletions package/contents/ui/WidgetDragHandler.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import QtQuick
import org.kde.plasma.plasmoid

/*
* Drag handler implemented in that strange way as workaround for cases, when window layout changed during the drag interaction.
*/
PointHandler {
property bool dragInProgress: false
property var cfg: plasmoid.configuration
Expand All @@ -19,19 +22,23 @@ PointHandler {
return Math.sqrt(dx * dx + dy * dy);
}

function stopDrag() {
dragInProgress = false;
}

enabled: cfg.windowTitleDragEnabled
dragThreshold: cfg.windowTitleDragThreshold
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onActiveChanged: function () {
if (active && (!cfg.windowTitleDragOnlyMaximized || tasksModel.activeWindow.maximized) && tasksModel.activeWindow.movable)
if (active && (!cfg.windowTitleDragOnlyMaximized || tasksModel.activeWindow.maximized))
dragInProgress = true;
else
dragInProgress = false;
stopDrag();
}
onPointChanged: function () {
if (active && dragInProgress && point && point.pressPosition && point.position) {
if (distance(point.pressPosition, point.position) > dragThreshold) {
dragInProgress = false;
stopDrag();
if (point.pressedButtons & Qt.LeftButton && cfg.widgetMouseAreaLeftDragAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaLeftDragAction);
else if (point.pressedButtons & Qt.MiddleButton && cfg.widgetMouseAreaMiddleDragAction != "")
Expand Down
38 changes: 33 additions & 5 deletions package/contents/ui/WidgetTapHandler.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@

import QtQuick

/*
* Tap handler implemented in that strange way as workaround for cases, when window layout changed during the long press interaction.
*/
TapHandler {
id: tapHandler

property var cfg: plasmoid.configuration
property Timer longPressTimer: Timer {
property int pressedButtons: 0
interval: Qt.styleHints.mousePressAndHoldInterval
onTriggered: function () {
if (pressedButtons & Qt.LeftButton && cfg.widgetMouseAreaLeftLongPressAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaLeftLongPressAction);
else if (pressedButtons & Qt.MiddleButton && cfg.widgetMouseAreaMiddleLongPressAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaMiddleLongPressAction);
}
}

signal invokeKWinShortcut(string shortcut)

enabled: cfg.widgetMouseAreaClickEnabled
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
longPressThreshold: 0
exclusiveSignals: TapHandler.SingleTap | TapHandler.DoubleTap
onSingleTapped: function (eventPoint, button) {
if (button === Qt.LeftButton && cfg.widgetMouseAreaLeftClickAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaLeftClickAction);
Expand All @@ -25,10 +42,21 @@ TapHandler {
else if (button === Qt.MiddleButton && cfg.widgetMouseAreaMiddleDoubleClickAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaMiddleDoubleClickAction);
}
onLongPressed: function () {
if (point.pressedButtons & Qt.LeftButton && cfg.widgetMouseAreaLeftLongPressAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaLeftLongPressAction);
else if (point.pressedButtons & Qt.MiddleButton && cfg.widgetMouseAreaMiddleLongPressAction != "")
invokeKWinShortcut(cfg.widgetMouseAreaMiddleLongPressAction);

onPointChanged: function () {
if (point.pressedButtons & acceptedButtons) {
restartLongPressTimer(point.pressedButtons);
} else {
stopLongPressTimer();
}
}

function restartLongPressTimer(pressedButtons) {
longPressTimer.restart();
longPressTimer.pressedButtons = pressedButtons;
}

function stopLongPressTimer() {
longPressTimer.stop();
}
}
2 changes: 1 addition & 1 deletion package/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Id": "com.github.antroids.application-title-bar",
"Name": "Application Title Bar",
"License": "GPL-3.0+",
"Version": "0.7.6",
"Version": "0.7.7",
"Website": "https://github.com/antroids/application-title-bar",
"FormFactors": [
"desktop"
Expand Down

0 comments on commit 556ddaa

Please sign in to comment.