Skip to content

Commit 3e0ceca

Browse files
authored
Add global coordinates broker but keep global cursor transform (#791)
This PR functionally fixes #764 but is non-ideal from a code quality standpoint. The cleaner version and discussion around it is and should remain in #766, this PR is a hotfix.
2 parents f8e982c + e05a16a commit 3e0ceca

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

grab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class MoveGrab {
6363

6464
this.initialY = clone.targetY;
6565
Easer.removeEase(clone);
66-
let [gx, gy, $] = global.get_pointer();
66+
let [gx, gy, $] = Utils.getPointerCoords();
6767

6868
let px = (gx - actor.x) / actor.width;
6969
let py = (gy - actor.y) / actor.height;

utils.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,42 @@ const Display = global.display;
1616
export let version = Config.PACKAGE_VERSION.split('.').map(Number);
1717

1818
let warpRipple;
19+
20+
let signals, touchCoords;
21+
let inTouch = false;
22+
1923
export function enable() {
2024
warpRipple = new Ripples.Ripples(0.5, 0.5, 'ripple-pointer-location');
2125
warpRipple.addTo(Main.uiGroup);
26+
27+
signals = new Signals();
28+
signals.connect(global.stage, "captured-event", (actor, event) => {
29+
switch (event.type()) {
30+
case Clutter.EventType.TOUCH_BEGIN:
31+
case Clutter.EventType.TOUCH_UPDATE:
32+
inTouch = true;
33+
break;
34+
case Clutter.EventType.TOUCH_END:
35+
case Clutter.EventType.TOUCH_CANCEL:
36+
inTouch = false;
37+
break;
38+
default:
39+
return Clutter.EVENT_PROPAGATE;
40+
}
41+
42+
// was one of our touch events
43+
touchCoords = event.get_coords();
44+
return Clutter.EVENT_PROPAGATE;
45+
});
2246
}
2347

2448
export function disable() {
2549
warpRipple?.destroy();
2650
warpRipple = null;
2751
markNewClonesSignalId = null;
52+
53+
signals.destroy();
54+
signals = null;
2855
}
2956

3057
export function assert(condition, message, ...dump) {
@@ -161,6 +188,18 @@ export function isInRect(x, y, r) {
161188
r.y <= y && y < r.y + r.height;
162189
}
163190

191+
/**
192+
* Retrieves global pointer coordinates taking into account touch screen events.
193+
* May not work for continuous tracking, see #766.
194+
*/
195+
export function getPointerCoords() {
196+
if (inTouch) {
197+
return touchCoords;
198+
} else {
199+
return global.get_pointer();
200+
}
201+
}
202+
164203
/**
165204
* Returns monitor a pointer co-ordinates.
166205
*/
@@ -176,7 +215,7 @@ export function monitorAtPoint(gx, gy) {
176215
* Returns the monitor current pointer coordinates.
177216
*/
178217
export function monitorAtCurrentPoint() {
179-
let [gx, gy, $] = global.get_pointer();
218+
let [gx, gy, $] = getPointerCoords();
180219
return monitorAtPoint(gx, gy);
181220
}
182221

0 commit comments

Comments
 (0)