From 4667b4704d8927ffb1a44b453512b30bc9f2f728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 5 May 2022 20:55:20 +0200 Subject: [PATCH] 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: --- 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 f3045ec5..198a30db 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;