bdce19
From f8ec838485ae81cf2e8ab2b899ad4154c7c06fbd Mon Sep 17 00:00:00 2001
bdce19
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
bdce19
Date: Thu, 21 Apr 2022 16:34:50 +0200
bdce19
Subject: [PATCH 1/2] window-list: Fix primary button action on touch
bdce19
bdce19
If a click event was triggered via touch rather than a pointer
bdce19
device, the button parameter is 0 rather than a mouse button
bdce19
number.
bdce19
bdce19
Account for that to make sure that touch events are not misinterpreted
bdce19
as right clicks.
bdce19
bdce19
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/issues/146
bdce19
bdce19
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/233>
bdce19
---
bdce19
 extensions/window-list/extension.js | 4 ++--
bdce19
 1 file changed, 2 insertions(+), 2 deletions(-)
bdce19
bdce19
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
bdce19
index 1f854aa2..fedc4195 100644
bdce19
--- a/extensions/window-list/extension.js
bdce19
+++ b/extensions/window-list/extension.js
bdce19
@@ -358,7 +358,7 @@ class WindowButton extends BaseButton {
bdce19
             return;
bdce19
         }
bdce19
 
bdce19
-        if (button == 1)
bdce19
+        if (!button || button === 1)
bdce19
             _minimizeOrActivateWindow(this.metaWindow);
bdce19
         else
bdce19
             _openMenu(this._contextMenu);
bdce19
@@ -601,7 +601,7 @@ class AppButton extends BaseButton {
bdce19
         if (contextMenuWasOpen)
bdce19
             this._contextMenu.close();
bdce19
 
bdce19
-        if (button == 1) {
bdce19
+        if (!button || button === 1) {
bdce19
             if (menuWasOpen)
bdce19
                 return;
bdce19
 
bdce19
-- 
bdce19
2.36.1
bdce19
bdce19
bdce19
From d3cf07f8065935736e8a79d06ec79c971c453453 Mon Sep 17 00:00:00 2001
bdce19
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
bdce19
Date: Thu, 5 May 2022 20:55:20 +0200
bdce19
Subject: [PATCH 2/2] window-list: Open menu on long press
bdce19
bdce19
Right-click isn't available on touch, so implement long-press as
bdce19
an alternative.
bdce19
bdce19
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/issues/146
bdce19
bdce19
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/233>
bdce19
---
bdce19
 extensions/window-list/extension.js | 45 +++++++++++++++++++++++++++++
bdce19
 1 file changed, 45 insertions(+)
bdce19
bdce19
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
bdce19
index fedc4195..0baaeecb 100644
bdce19
--- a/extensions/window-list/extension.js
bdce19
+++ b/extensions/window-list/extension.js
bdce19
@@ -229,6 +229,9 @@ class BaseButton {
bdce19
         this.actor.connect('clicked', this._onClicked.bind(this));
bdce19
         this.actor.connect('destroy', this._onDestroy.bind(this));
bdce19
         this.actor.connect('popup-menu', this._onPopupMenu.bind(this));
bdce19
+        this.actor.connect('button-press-event', this._onButtonPress.bind(this));
bdce19
+        this.actor.connect('button-release-event', this._onButtonRelease.bind(this));
bdce19
+        this.actor.connect('touch-event', this._onTouch.bind(this));
bdce19
 
bdce19
         this._contextMenuManager = new PopupMenu.PopupMenuManager(this);
bdce19
 
bdce19
@@ -250,6 +253,48 @@ class BaseButton {
bdce19
         return this.actor.has_style_class_name('focused');
bdce19
     }
bdce19
 
bdce19
+    _setLongPressTimeout() {
bdce19
+        if (this._longPressTimeoutId)
bdce19
+            return;
bdce19
+
bdce19
+        const { longPressDuration } = Clutter.Settings.get_default();
bdce19
+        this._longPressTimeoutId =
bdce19
+            GLib.timeout_add(GLib.PRIORITY_DEFAULT, longPressDuration, () => {
bdce19
+                delete this._longPressTimeoutId;
bdce19
+
bdce19
+                if (this._canOpenPopupMenu() && !this._contextMenu.isOpen)
bdce19
+                    _openMenu(this._contextMenu);
bdce19
+                return GLib.SOURCE_REMOVE;
bdce19
+            });
bdce19
+    }
bdce19
+
bdce19
+    _removeLongPressTimeout() {
bdce19
+        if (!this._longPressTimeoutId)
bdce19
+            return;
bdce19
+        GLib.source_remove(this._longPressTimeoutId);
bdce19
+        delete this._longPressTimeoutId;
bdce19
+    }
bdce19
+
bdce19
+    _onButtonPress(button, event) {
bdce19
+        if (event.get_button() === 1)
bdce19
+            this._setLongPressTimeout();
bdce19
+        return Clutter.EVENT_PROPAGATE;
bdce19
+    }
bdce19
+
bdce19
+    _onButtonRelease() {
bdce19
+        this._removeLongPressTimeout();
bdce19
+        return Clutter.EVENT_PROPAGATE;
bdce19
+    }
bdce19
+
bdce19
+    _onTouch(event) {
bdce19
+        const type = event.get_type();
bdce19
+        if (type === Clutter.EventType.TOUCH_BEGIN)
bdce19
+            this._setLongPressTimeout();
bdce19
+        else if (type === Clutter.EventType.TOUCH_END)
bdce19
+            this._removeLongPressTimeout();
bdce19
+        return Clutter.EVENT_PROPAGATE;
bdce19
+    }
bdce19
+
bdce19
     activate() {
bdce19
         if (this.active)
bdce19
             return;
bdce19
-- 
bdce19
2.36.1
bdce19