Blame SOURCES/desktop-icons-touch-support.patch

987b2c
From bcbf9709802e7644c5911615dabdee7d8ca07719 Mon Sep 17 00:00:00 2001
987b2c
From: Carlos Garnacho <carlosg@gnome.org>
987b2c
Date: Mon, 31 May 2021 19:29:34 +0200
987b2c
Subject: [PATCH 1/3] desktopManager: Handle TOUCH_UPDATE/END events explicitly
987b2c
 for rubberband
987b2c
987b2c
These events need specific handling for Wayland, as we do not get emulated
987b2c
pointer events in that platform. Handle these for rubberband selection.
987b2c
---
987b2c
 extensions/desktop-icons/desktopManager.js | 67 ++++++++++++++++------
987b2c
 1 file changed, 48 insertions(+), 19 deletions(-)
987b2c
987b2c
diff --git a/extensions/desktop-icons/desktopManager.js b/extensions/desktop-icons/desktopManager.js
987b2c
index 399aee0..a70cd98 100644
987b2c
--- a/extensions/desktop-icons/desktopManager.js
987b2c
+++ b/extensions/desktop-icons/desktopManager.js
987b2c
@@ -130,26 +130,49 @@ var DesktopManager = GObject.registerClass({
987b2c
             }
987b2c
             [x, y] = event.get_coords();
987b2c
             this._updateRubberBand(x, y);
987b2c
-            let x0, y0, x1, y1;
987b2c
-            if (x >= this._rubberBandInitialX) {
987b2c
-                x0 = this._rubberBandInitialX;
987b2c
-                x1 = x;
987b2c
-            } else {
987b2c
-                x1 = this._rubberBandInitialX;
987b2c
-                x0 = x;
987b2c
-            }
987b2c
-            if (y >= this._rubberBandInitialY) {
987b2c
-                y0 = this._rubberBandInitialY;
987b2c
-                y1 = y;
987b2c
-            } else {
987b2c
-                y1 = this._rubberBandInitialY;
987b2c
-                y0 = y;
987b2c
-            }
987b2c
-            for (let [fileUri, fileItem] of this._fileItems) {
987b2c
-                fileItem.emit('selected', true, true,
987b2c
-                              fileItem.intersectsWith(x0, y0, x1 - x0, y1 - y0));
987b2c
-            }
987b2c
+            this._updateSelection(x, y);
987b2c
         });
987b2c
+        this._rubberBandTouchId = global.stage.connect('touch-event', (actor, event) => {
987b2c
+            // Let x11 pointer emulation do the job on X11
987b2c
+            if (!Meta.is_wayland_compositor())
987b2c
+                return Clutter.EVENT_PROPAGATE;
987b2c
+            if (!global.display.is_pointer_emulating_sequence(event.get_event_sequence()))
987b2c
+                return Clutter.EVENT_PROPAGATE;
987b2c
+
987b2c
+            if (event.type() == Clutter.EventType.TOUCH_END) {
987b2c
+                this.endRubberBand();
987b2c
+                return Clutter.EVENT_STOP;
987b2c
+            } else if (event.type() == Clutter.EventType.TOUCH_UPDATE) {
987b2c
+                [x, y] = event.get_coords();
987b2c
+                this._updateRubberBand(x, y);
987b2c
+                this._updateSelection(x, y);
987b2c
+                return Clutter.EVENT_STOP;
987b2c
+            }
987b2c
+
987b2c
+            return Clutter.EVENT_PROPAGATE;
987b2c
+	});
987b2c
+    }
987b2c
+
987b2c
+    _updateSelection(x, y) {
987b2c
+        let x0, y0, x1, y1;
987b2c
+        if (x >= this._rubberBandInitialX) {
987b2c
+            x0 = this._rubberBandInitialX;
987b2c
+            x1 = x;
987b2c
+        } else {
987b2c
+            x1 = this._rubberBandInitialX;
987b2c
+            x0 = x;
987b2c
+        }
987b2c
+        if (y >= this._rubberBandInitialY) {
987b2c
+            y0 = this._rubberBandInitialY;
987b2c
+            y1 = y;
987b2c
+        } else {
987b2c
+            y1 = this._rubberBandInitialY;
987b2c
+            y0 = y;
987b2c
+        }
987b2c
+        for (let [fileUri, fileItem] of this._fileItems) {
987b2c
+            fileItem.emit('selected', true, true,
987b2c
+                          fileItem.intersectsWith(x0, y0, x1 - x0, y1 - y0));
987b2c
+        }
987b2c
     }
987b2c
 
987b2c
     endRubberBand() {
987b2c
@@ -157,8 +180,10 @@ var DesktopManager = GObject.registerClass({
987b2c
         Extension.lockActivitiesButton = false;
987b2c
         this._grabHelper.ungrab();
987b2c
         global.stage.disconnect(this._rubberBandId);
987b2c
+        global.stage.disconnect(this._rubberBandTouchId);
987b2c
         global.stage.disconnect(this._stageReleaseEventId);
987b2c
         this._rubberBandId = 0;
987b2c
+        this._rubberBandTouchId = 0;
987b2c
         this._stageReleaseEventId = 0;
987b2c
 
987b2c
         this._selection = new Set([...this._selection, ...this._currentSelection]);
987b2c
@@ -739,6 +764,10 @@ var DesktopManager = GObject.registerClass({
987b2c
             global.stage.disconnect(this._rubberBandId);
987b2c
         this._rubberBandId = 0;
987b2c
 
987b2c
+        if (this._rubberBandTouchId)
987b2c
+            global.stage.disconnect(this._rubberBandTouchId);
987b2c
+        this._rubberBandTouchId = 0;
987b2c
+
987b2c
         this._rubberBand.destroy();
987b2c
 
987b2c
         if (this._queryFileInfoCancellable)
987b2c
-- 
987b2c
2.31.1
987b2c
987b2c
987b2c
From 0733004ffeb517f7a80ff41e7181027e8b92b17e Mon Sep 17 00:00:00 2001
987b2c
From: Carlos Garnacho <carlosg@gnome.org>
987b2c
Date: Mon, 31 May 2021 19:31:03 +0200
987b2c
Subject: [PATCH 2/3] desktopGrid: Handle TOUCH_BEGIN events explicitly
987b2c
987b2c
We do not get pointer emulated events on Wayland, so touch events should
987b2c
be handled explicitly there. Handle starting rubberband selection via
987b2c
touch.
987b2c
---
987b2c
 extensions/desktop-icons/desktopGrid.js | 19 +++++++++++++++++++
987b2c
 1 file changed, 19 insertions(+)
987b2c
987b2c
diff --git a/extensions/desktop-icons/desktopGrid.js b/extensions/desktop-icons/desktopGrid.js
987b2c
index 94d2dfd..602fa7f 100644
987b2c
--- a/extensions/desktop-icons/desktopGrid.js
987b2c
+++ b/extensions/desktop-icons/desktopGrid.js
987b2c
@@ -21,6 +21,7 @@ const Clutter = imports.gi.Clutter;
987b2c
 const St = imports.gi.St;
987b2c
 const Gio = imports.gi.Gio;
987b2c
 const GLib = imports.gi.GLib;
987b2c
+const Meta = imports.gi.Meta;
987b2c
 const Shell = imports.gi.Shell;
987b2c
 
987b2c
 const Signals = imports.signals;
987b2c
@@ -123,6 +124,7 @@ var DesktopGrid = class {
987b2c
             () => this._backgroundDestroyed());
987b2c
 
987b2c
         this._grid.connect('button-press-event', (actor, event) => this._onPressButton(actor, event));
987b2c
+        this._grid.connect('touch-event', (actor, event) => this._onTouchEvent(actor, event));
987b2c
 
987b2c
         this._grid.connect('key-press-event', this._onKeyPress.bind(this));
987b2c
 
987b2c
@@ -506,6 +508,23 @@ var DesktopGrid = class {
987b2c
         return Clutter.EVENT_PROPAGATE;
987b2c
     }
987b2c
 
987b2c
+    _onTouchEvent(actor, event) {
987b2c
+        // Let x11 pointer emulation do the job on X11
987b2c
+        if (!Meta.is_wayland_compositor())
987b2c
+            return Clutter.EVENT_PROPAGATE;
987b2c
+
987b2c
+	if (event.type() == Clutter.EventType.TOUCH_BEGIN &&
987b2c
+	    global.display.is_pointer_emulating_sequence(event.get_event_sequence())) {
987b2c
+            Extension.desktopManager.clearSelection();
987b2c
+            let [x, y] = event.get_coords();
987b2c
+            let [gridX, gridY] = this._grid.get_transformed_position();
987b2c
+            Extension.desktopManager.startRubberBand(x, y, gridX, gridY);
987b2c
+            return Clutter.EVENT_STOP;
987b2c
+        }
987b2c
+
987b2c
+        return Clutter.EVENT_PROPAGATE;
987b2c
+    }
987b2c
+
987b2c
     _addDesktopBackgroundMenu() {
987b2c
         this.actor._desktopBackgroundMenu = this._createDesktopBackgroundMenu();
987b2c
         this.actor._desktopBackgroundManager = new PopupMenu.PopupMenuManager({ actor: this.actor });
987b2c
-- 
987b2c
2.31.1
987b2c
987b2c
987b2c
From 2d978ffc58562c4f4d00b1afb03da58be3102e29 Mon Sep 17 00:00:00 2001
987b2c
From: Carlos Garnacho <carlosg@gnome.org>
987b2c
Date: Mon, 31 May 2021 19:31:50 +0200
987b2c
Subject: [PATCH 3/3] fileItem: Handle (multi) touch explicitly via touch
987b2c
 events
987b2c
987b2c
Wayland does not get pointer emulated events, so we must handle TOUCH_BEGIN/
987b2c
END here for file clicking/tapping to work there.
987b2c
---
987b2c
 extensions/desktop-icons/fileItem.js | 34 ++++++++++++++++++++++++----
987b2c
 1 file changed, 30 insertions(+), 4 deletions(-)
987b2c
987b2c
diff --git a/extensions/desktop-icons/fileItem.js b/extensions/desktop-icons/fileItem.js
987b2c
index 143cb9b..1cb47e8 100644
987b2c
--- a/extensions/desktop-icons/fileItem.js
987b2c
+++ b/extensions/desktop-icons/fileItem.js
987b2c
@@ -117,6 +117,7 @@ var FileItem = class {
987b2c
         this._container.connect('motion-event', (actor, event) => this._onMotion(actor, event));
987b2c
         this._container.connect('leave-event', (actor, event) => this._onLeave(actor, event));
987b2c
         this._container.connect('button-release-event', (actor, event) => this._onReleaseButton(actor, event));
987b2c
+        this._container.connect('touch-event', (actor, event) => this._onTouchEvent(actor, event));
987b2c
 
987b2c
         /* Set the metadata and update relevant UI */
987b2c
         this._updateMetadataFromFileInfo(fileInfo);
987b2c
@@ -648,16 +649,26 @@ var FileItem = class {
987b2c
         DesktopIconsUtil.launchTerminal(this.file.get_path());
987b2c
     }
987b2c
 
987b2c
+    _eventButton(event) {
987b2c
+	// Emulate button1 press on touch events
987b2c
+	if (event.type() == Clutter.EventType.TOUCH_BEGIN ||
987b2c
+	    event.type() == Clutter.EventType.TOUCH_END ||
987b2c
+	    event.type() == Clutter.EventType.TOUCH_UPDATE)
987b2c
+	    return 1;
987b2c
+
987b2c
+	return event.get_button();
987b2c
+    }
987b2c
+
987b2c
     _updateClickState(event) {
987b2c
         let settings = Clutter.Settings.get_default();
987b2c
-        if ((event.get_button() == this._lastClickButton) &&
987b2c
+        if ((this._eventButton(event) == this._lastClickButton) &&
987b2c
             ((event.get_time() - this._lastClickTime) < settings.double_click_time))
987b2c
             this._clickCount++;
987b2c
         else
987b2c
             this._clickCount = 1;
987b2c
 
987b2c
         this._lastClickTime = event.get_time();
987b2c
-        this._lastClickButton = event.get_button();
987b2c
+        this._lastClickButton = this._eventButton(event);
987b2c
     }
987b2c
 
987b2c
     _getClickCount() {
987b2c
@@ -666,7 +677,7 @@ var FileItem = class {
987b2c
 
987b2c
     _onPressButton(actor, event) {
987b2c
         this._updateClickState(event);
987b2c
-        let button = event.get_button();
987b2c
+        let button = this._eventButton(event);
987b2c
         if (button == 3) {
987b2c
             if (!this.isSelected)
987b2c
                 this.emit('selected', false, false, true);
987b2c
@@ -725,7 +736,7 @@ var FileItem = class {
987b2c
     }
987b2c
 
987b2c
     _onReleaseButton(actor, event) {
987b2c
-        let button = event.get_button();
987b2c
+        let button = this._eventButton(event);
987b2c
         if (button == 1) {
987b2c
             // primaryButtonPressed is TRUE only if the user has pressed the button
987b2c
             // over an icon, and if (s)he has not started a drag&drop operation
987b2c
@@ -744,6 +755,21 @@ var FileItem = class {
987b2c
         return Clutter.EVENT_PROPAGATE;
987b2c
     }
987b2c
 
987b2c
+    _onTouchEvent(actor, event) {
987b2c
+        // Let x11 pointer emulation do the job on X11
987b2c
+        if (!Meta.is_wayland_compositor())
987b2c
+            return Clutter.EVENT_PROPAGATE;
987b2c
+        if (!global.display.is_pointer_emulating_sequence(event.get_event_sequence()))
987b2c
+            return Clutter.EVENT_PROPAGATE;
987b2c
+
987b2c
+        if (event.type() == Clutter.EventType.TOUCH_BEGIN)
987b2c
+            this._onPressButton(actor, event);
987b2c
+        else if (event.type() == Clutter.EventType.TOUCH_UPDATE)
987b2c
+            this._onMotion(actor, event);
987b2c
+        else if (event.type() == Clutter.EventType.TOUCH_END)
987b2c
+            this._onReleaseButton(actor, event);
987b2c
+    }
987b2c
+
987b2c
     get savedCoordinates() {
987b2c
         return this._savedCoordinates;
987b2c
     }
987b2c
-- 
987b2c
2.31.1
987b2c