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

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