Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grab.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MoveGrab {

this.initialY = clone.targetY;
Easer.removeEase(clone);
let [gx, gy, $] = global.get_pointer();
let [gx, gy, $] = Utils.getPointerCoords();

let px = (gx - actor.x) / actor.width;
let py = (gy - actor.y) / actor.height;
Expand Down
41 changes: 40 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,42 @@ const Display = global.display;
export let version = Config.PACKAGE_VERSION.split('.').map(Number);

let warpRipple;

let signals, touchCoords;
let inTouch = false;

export function enable() {
warpRipple = new Ripples.Ripples(0.5, 0.5, 'ripple-pointer-location');
warpRipple.addTo(Main.uiGroup);

signals = new Signals();
signals.connect(global.stage, "captured-event", (actor, event) => {
switch (event.type()) {
case Clutter.EventType.TOUCH_BEGIN:
case Clutter.EventType.TOUCH_UPDATE:
inTouch = true;
break;
case Clutter.EventType.TOUCH_END:
case Clutter.EventType.TOUCH_CANCEL:
inTouch = false;
break;
default:
return Clutter.EVENT_PROPAGATE;
}

// was one of our touch events
touchCoords = event.get_coords();
return Clutter.EVENT_PROPAGATE;
});
}

export function disable() {
warpRipple?.destroy();
warpRipple = null;
markNewClonesSignalId = null;

signals.destroy();
signals = null;
}

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

/**
* Retrieves global pointer coordinates taking into account touch screen events.
* May not work for continuous tracking, see #766.
*/
export function getPointerCoords() {
if (inTouch) {
return touchCoords;
} else {
return global.get_pointer();
}
}

/**
* Returns monitor a pointer co-ordinates.
*/
Expand All @@ -176,7 +215,7 @@ export function monitorAtPoint(gx, gy) {
* Returns the monitor current pointer coordinates.
*/
export function monitorAtCurrentPoint() {
let [gx, gy, $] = global.get_pointer();
let [gx, gy, $] = getPointerCoords();
return monitorAtPoint(gx, gy);
}

Expand Down