From b732874e10ddd5cba5986552f4f6493a781efe7e Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Sun, 10 Dec 2023 22:51:19 +0100 Subject: [PATCH 1/5] Partial fix for touch window drag-and-drop --- grab.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/grab.js b/grab.js index 512a65bce..af2fc9b50 100644 --- a/grab.js +++ b/grab.js @@ -85,6 +85,12 @@ export class MoveGrab { center && clone.set_pivot_point(0, 0); this.signals.connect(this.actor, "button-release-event", this.end.bind(this)); + this.signals.connect(this.actor, "touch-event", (evt) => { + if (evt.type() == Clutter.EventType.TOUCH_END) + this.end(); + else if (evt.type() == Clutter.EventType.TOUCH_UPDATE) + this.motion(this.actor, evt); + }); this.signals.connect(this.actor, "motion-event", this.motion.bind(this)); this.signals.connect(global.display, "window-entered-monitor", this.beginDnD.bind(this) From eec4b6d59d5964cc2d9433800724d6a6bdc64699 Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Sun, 10 Dec 2023 23:20:35 +0100 Subject: [PATCH 2/5] Fixed coordinate retrieval in update function --- grab.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/grab.js b/grab.js index af2fc9b50..2568684bc 100644 --- a/grab.js +++ b/grab.js @@ -85,11 +85,11 @@ export class MoveGrab { center && clone.set_pivot_point(0, 0); this.signals.connect(this.actor, "button-release-event", this.end.bind(this)); - this.signals.connect(this.actor, "touch-event", (evt) => { + this.signals.connect(this.actor, "touch-event", (act, evt) => { if (evt.type() == Clutter.EventType.TOUCH_END) this.end(); - else if (evt.type() == Clutter.EventType.TOUCH_UPDATE) - this.motion(this.actor, evt); + else + this.motion(act, evt); }); this.signals.connect(this.actor, "motion-event", this.motion.bind(this)); this.signals.connect(global.display, "window-entered-monitor", @@ -307,6 +307,8 @@ export class MoveGrab { let metaWindow = this.window; // let [gx, gy] = event.get_coords(); let [gx, gy, $] = global.get_pointer(); + if (event.type() == Clutter.EventType.TOUCH_UPDATE) + [gx, gy] = event.get_coords(); let [dx, dy] = this.pointerOffset; let clone = metaWindow.clone; From 042449e7fc0b7819e48f494de19c085c36af2d68 Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Sun, 28 Jan 2024 12:42:48 +0100 Subject: [PATCH 3/5] Warp global pointer to follow touch event This is an incomplete solution, as the drag-and-drop event isn't properly finished in touch cases, requiring a trackpad swipe to "unlock" the situation. Also, while simple, moving the global pointer goes against expected touch behavior in GNOME, which is that touch events do not move the mouse. This could be adressed by memorizing and restoring the pointer as the event starts. --- grab.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grab.js b/grab.js index 2568684bc..cdbab38f3 100644 --- a/grab.js +++ b/grab.js @@ -307,8 +307,10 @@ export class MoveGrab { let metaWindow = this.window; // let [gx, gy] = event.get_coords(); let [gx, gy, $] = global.get_pointer(); - if (event.type() == Clutter.EventType.TOUCH_UPDATE) + if (event.type() == Clutter.EventType.TOUCH_UPDATE) { [gx, gy] = event.get_coords(); + Clutter.get_default_backend().get_default_seat().warp_pointer(gx, gy); + } let [dx, dy] = this.pointerOffset; let clone = metaWindow.clone; From cd978689e8624f240752a9b800003907fb982c3d Mon Sep 17 00:00:00 2001 From: Jay Ta'ala Date: Sun, 28 Jan 2024 23:32:34 +1100 Subject: [PATCH 4/5] A little cleanup, applying linter recommendations, and improving and using PaperWM's built-in `warpPointer` method. --- grab.js | 10 ++++++---- utils.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/grab.js b/grab.js index cdbab38f3..825000328 100644 --- a/grab.js +++ b/grab.js @@ -86,10 +86,12 @@ export class MoveGrab { this.signals.connect(this.actor, "button-release-event", this.end.bind(this)); this.signals.connect(this.actor, "touch-event", (act, evt) => { - if (evt.type() == Clutter.EventType.TOUCH_END) + if (evt.type() === Clutter.EventType.TOUCH_END) { this.end(); - else + } + else { this.motion(act, evt); + } }); this.signals.connect(this.actor, "motion-event", this.motion.bind(this)); this.signals.connect(global.display, "window-entered-monitor", @@ -307,9 +309,9 @@ export class MoveGrab { let metaWindow = this.window; // let [gx, gy] = event.get_coords(); let [gx, gy, $] = global.get_pointer(); - if (event.type() == Clutter.EventType.TOUCH_UPDATE) { + if (event.type() === Clutter.EventType.TOUCH_UPDATE) { [gx, gy] = event.get_coords(); - Clutter.get_default_backend().get_default_seat().warp_pointer(gx, gy); + Utils.warpPointer(gx, gy, false); } let [dx, dy] = this.pointerOffset; let clone = metaWindow.clone; diff --git a/utils.js b/utils.js index 86f12bfb0..a8d1429d7 100644 --- a/utils.js +++ b/utils.js @@ -209,12 +209,14 @@ export function warpPointerToMonitor(monitor, center = false) { /** * Warps pointer to x, y coordinates. + * Optionally shows a ripple effect after warp. */ -export function warpPointer(x, y) { - let backend = Clutter.get_default_backend(); - let seat = backend.get_default_seat(); +export function warpPointer(x, y, ripple = true) { + const seat = Clutter.get_default_backend().get_default_seat(); seat.warp_pointer(x, y); - warpRipple.playAnimation(x, y); + if (ripple) { + warpRipple.playAnimation(x, y); + } } /** From 7335e55e809340e7c83162ada65ccd2f46fd5e51 Mon Sep 17 00:00:00 2001 From: TheSola10 Date: Sun, 28 Jan 2024 13:53:23 +0100 Subject: [PATCH 5/5] Added quick comment Also a quick workaround to circumvent GitHub approval restrictions --- grab.js | 1 + 1 file changed, 1 insertion(+) diff --git a/grab.js b/grab.js index 825000328..5aee3ec45 100644 --- a/grab.js +++ b/grab.js @@ -311,6 +311,7 @@ export class MoveGrab { let [gx, gy, $] = global.get_pointer(); if (event.type() === Clutter.EventType.TOUCH_UPDATE) { [gx, gy] = event.get_coords(); + // We update global pointer to match touch event Utils.warpPointer(gx, gy, false); } let [dx, dy] = this.pointerOffset;