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