[gnome-shell-extensions] window-list: Open menu on long press



commit 4667b4704d8927ffb1a44b453512b30bc9f2f728
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu May 5 20:55:20 2022 +0200

    window-list: Open menu on long press
    
    Right-click isn't available on touch, so implement long-press as
    an alternative.
    
    https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/issues/146
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/233>

 extensions/window-list/extension.js | 42 +++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
---
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
index f3045ec..198a30d 100644
--- a/extensions/window-list/extension.js
+++ b/extensions/window-list/extension.js
@@ -246,6 +246,48 @@ class BaseButton extends St.Button {
         this._updateVisibility();
     }
 
+    _setLongPressTimeout() {
+        if (this._longPressTimeoutId)
+            return;
+
+        const { longPressDuration } = Clutter.Settings.get_default();
+        this._longPressTimeoutId =
+            GLib.timeout_add(GLib.PRIORITY_DEFAULT, longPressDuration, () => {
+                delete this._longPressTimeoutId;
+
+                if (this._canOpenPopupMenu() && !this._contextMenu.isOpen)
+                    this._openMenu(this._contextMenu);
+                return GLib.SOURCE_REMOVE;
+            });
+    }
+
+    _removeLongPressTimeout() {
+        if (!this._longPressTimeoutId)
+            return;
+        GLib.source_remove(this._longPressTimeoutId);
+        delete this._longPressTimeoutId;
+    }
+
+    vfunc_button_press_event(buttonEvent) {
+        if (buttonEvent.button === 1)
+            this._setLongPressTimeout();
+        return super.vfunc_button_press_event(buttonEvent);
+    }
+
+    vfunc_button_release_event(buttonEvent) {
+        this._removeLongPressTimeout();
+
+        return super.vfunc_button_release_event(buttonEvent);
+    }
+
+    vfunc_touch_event(touchEvent) {
+        if (touchEvent.type === Clutter.EventType.TOUCH_BEGIN)
+            this._setLongPressTimeout();
+        else if (touchEvent.type === Clutter.EventType.TOUCH_END)
+            this._removeLongPressTimeout();
+        return super.vfunc_touch_event(touchEvent);
+    }
+
     activate() {
         if (this.active)
             return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]