[gnome-shell-extensions/wip/rstrode/heads-up-display: 57/62] desktopManager: Handle TOUCH_UPDATE/END events explicitly for rubberband




commit 8d5f64be17197605ac6ff6fb998d7605504e97c0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon May 31 19:29:34 2021 +0200

    desktopManager: Handle TOUCH_UPDATE/END events explicitly for rubberband
    
    These events need specific handling for Wayland, as we do not get emulated
    pointer events in that platform. Handle these for rubberband selection.

 extensions/desktop-icons/desktopManager.js | 67 +++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 19 deletions(-)
---
diff --git a/extensions/desktop-icons/desktopManager.js b/extensions/desktop-icons/desktopManager.js
index 399aee0..a70cd98 100644
--- a/extensions/desktop-icons/desktopManager.js
+++ b/extensions/desktop-icons/desktopManager.js
@@ -130,26 +130,49 @@ var DesktopManager = GObject.registerClass({
             }
             [x, y] = event.get_coords();
             this._updateRubberBand(x, y);
-            let x0, y0, x1, y1;
-            if (x >= this._rubberBandInitialX) {
-                x0 = this._rubberBandInitialX;
-                x1 = x;
-            } else {
-                x1 = this._rubberBandInitialX;
-                x0 = x;
-            }
-            if (y >= this._rubberBandInitialY) {
-                y0 = this._rubberBandInitialY;
-                y1 = y;
-            } else {
-                y1 = this._rubberBandInitialY;
-                y0 = y;
-            }
-            for (let [fileUri, fileItem] of this._fileItems) {
-                fileItem.emit('selected', true, true,
-                              fileItem.intersectsWith(x0, y0, x1 - x0, y1 - y0));
-            }
+            this._updateSelection(x, y);
         });
+        this._rubberBandTouchId = global.stage.connect('touch-event', (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_END) {
+                this.endRubberBand();
+                return Clutter.EVENT_STOP;
+            } else if (event.type() == Clutter.EventType.TOUCH_UPDATE) {
+                [x, y] = event.get_coords();
+                this._updateRubberBand(x, y);
+                this._updateSelection(x, y);
+                return Clutter.EVENT_STOP;
+            }
+
+            return Clutter.EVENT_PROPAGATE;
+       });
+    }
+
+    _updateSelection(x, y) {
+        let x0, y0, x1, y1;
+        if (x >= this._rubberBandInitialX) {
+            x0 = this._rubberBandInitialX;
+            x1 = x;
+        } else {
+            x1 = this._rubberBandInitialX;
+            x0 = x;
+        }
+        if (y >= this._rubberBandInitialY) {
+            y0 = this._rubberBandInitialY;
+            y1 = y;
+        } else {
+            y1 = this._rubberBandInitialY;
+            y0 = y;
+        }
+        for (let [fileUri, fileItem] of this._fileItems) {
+            fileItem.emit('selected', true, true,
+                          fileItem.intersectsWith(x0, y0, x1 - x0, y1 - y0));
+        }
     }
 
     endRubberBand() {
@@ -157,8 +180,10 @@ var DesktopManager = GObject.registerClass({
         Extension.lockActivitiesButton = false;
         this._grabHelper.ungrab();
         global.stage.disconnect(this._rubberBandId);
+        global.stage.disconnect(this._rubberBandTouchId);
         global.stage.disconnect(this._stageReleaseEventId);
         this._rubberBandId = 0;
+        this._rubberBandTouchId = 0;
         this._stageReleaseEventId = 0;
 
         this._selection = new Set([...this._selection, ...this._currentSelection]);
@@ -739,6 +764,10 @@ var DesktopManager = GObject.registerClass({
             global.stage.disconnect(this._rubberBandId);
         this._rubberBandId = 0;
 
+        if (this._rubberBandTouchId)
+            global.stage.disconnect(this._rubberBandTouchId);
+        this._rubberBandTouchId = 0;
+
         this._rubberBand.destroy();
 
         if (this._queryFileInfoCancellable)


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