[gnome-shell-extensions/wip/rstrode/heads-up-display: 59/62] fileItem: Handle (multi) touch explicitly via touch events




commit e68751b031ce7643ddf4f7afd1008a6f7f69a30a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon May 31 19:31:50 2021 +0200

    fileItem: Handle (multi) touch explicitly via touch events
    
    Wayland does not get pointer emulated events, so we must handle TOUCH_BEGIN/
    END here for file clicking/tapping to work there.

 extensions/desktop-icons/fileItem.js | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/extensions/desktop-icons/fileItem.js b/extensions/desktop-icons/fileItem.js
index 143cb9b..1cb47e8 100644
--- a/extensions/desktop-icons/fileItem.js
+++ b/extensions/desktop-icons/fileItem.js
@@ -117,6 +117,7 @@ var FileItem = class {
         this._container.connect('motion-event', (actor, event) => this._onMotion(actor, event));
         this._container.connect('leave-event', (actor, event) => this._onLeave(actor, event));
         this._container.connect('button-release-event', (actor, event) => this._onReleaseButton(actor, 
event));
+        this._container.connect('touch-event', (actor, event) => this._onTouchEvent(actor, event));
 
         /* Set the metadata and update relevant UI */
         this._updateMetadataFromFileInfo(fileInfo);
@@ -648,16 +649,26 @@ var FileItem = class {
         DesktopIconsUtil.launchTerminal(this.file.get_path());
     }
 
+    _eventButton(event) {
+       // Emulate button1 press on touch events
+       if (event.type() == Clutter.EventType.TOUCH_BEGIN ||
+           event.type() == Clutter.EventType.TOUCH_END ||
+           event.type() == Clutter.EventType.TOUCH_UPDATE)
+           return 1;
+
+       return event.get_button();
+    }
+
     _updateClickState(event) {
         let settings = Clutter.Settings.get_default();
-        if ((event.get_button() == this._lastClickButton) &&
+        if ((this._eventButton(event) == this._lastClickButton) &&
             ((event.get_time() - this._lastClickTime) < settings.double_click_time))
             this._clickCount++;
         else
             this._clickCount = 1;
 
         this._lastClickTime = event.get_time();
-        this._lastClickButton = event.get_button();
+        this._lastClickButton = this._eventButton(event);
     }
 
     _getClickCount() {
@@ -666,7 +677,7 @@ var FileItem = class {
 
     _onPressButton(actor, event) {
         this._updateClickState(event);
-        let button = event.get_button();
+        let button = this._eventButton(event);
         if (button == 3) {
             if (!this.isSelected)
                 this.emit('selected', false, false, true);
@@ -725,7 +736,7 @@ var FileItem = class {
     }
 
     _onReleaseButton(actor, event) {
-        let button = event.get_button();
+        let button = this._eventButton(event);
         if (button == 1) {
             // primaryButtonPressed is TRUE only if the user has pressed the button
             // over an icon, and if (s)he has not started a drag&drop operation
@@ -744,6 +755,21 @@ var FileItem = class {
         return Clutter.EVENT_PROPAGATE;
     }
 
+    _onTouchEvent(actor, event) {
+        // Let x11 pointer emulation do the job on X11
+        if (!Meta.is_wayland_compositor())
+            return Clutter.EVENT_PROPAGATE;
+        if (!global.display.is_pointer_emulating_sequence(event.get_event_sequence()))
+            return Clutter.EVENT_PROPAGATE;
+
+        if (event.type() == Clutter.EventType.TOUCH_BEGIN)
+            this._onPressButton(actor, event);
+        else if (event.type() == Clutter.EventType.TOUCH_UPDATE)
+            this._onMotion(actor, event);
+        else if (event.type() == Clutter.EventType.TOUCH_END)
+            this._onReleaseButton(actor, event);
+    }
+
     get savedCoordinates() {
         return this._savedCoordinates;
     }


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