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
20 changes: 8 additions & 12 deletions 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 All @@ -86,7 +86,8 @@ 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
|| evt.type() === Clutter.EventType.TOUCH_CANCEL) {
this.end();
}
else {
Expand Down Expand Up @@ -121,7 +122,7 @@ export class MoveGrab {
let clone = metaWindow.clone;
let space = this.initialSpace;

let [gx, gy, $] = global.get_pointer();
let [gx, gy, $] = Utils.getPointerCoords();
let point = {};
if (center) {
point = space.cloneContainer.apply_relative_transform_to_point(
Expand Down Expand Up @@ -177,7 +178,7 @@ export class MoveGrab {
}

spaceMotion(space, background, event) {
let [gx, gy, $] = global.get_pointer();
let [gx, gy, $] = Utils.getPointerCoords();
let [sx, sy] = space.globalToScroll(gx, gy, { useTarget: true });
this.selectDndZone(space, sx, sy);
}
Expand Down Expand Up @@ -308,12 +309,7 @@ export class MoveGrab {
motion(actor, event) {
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();
// We update global pointer to match touch event
Utils.warpPointer(gx, gy, false);
}
let [gx, gy, $] = Utils.getPointerCoords();
let [dx, dy] = this.pointerOffset;
let clone = metaWindow.clone;

Expand Down Expand Up @@ -370,7 +366,7 @@ export class MoveGrab {
let metaWindow = this.window;
let actor = metaWindow.get_compositor_private();
let clone = metaWindow.clone;
let [gx, gy, $] = global.get_pointer();
let [gx, gy, $] = Utils.getPointerCoords();

this.zoneActors.forEach(actor => actor.destroy());
let params = {
Expand Down Expand Up @@ -498,7 +494,7 @@ export class MoveGrab {
Utils.later_add(Meta.LaterType.IDLE, () => {
if (!global.display.end_grab_op && this.wasTiled) {
// move to current cursor position
let [x, y, _mods] = global.get_pointer();
let [x, y, _mods] = Utils.getPointerCoords();
Comment on lines 496 to +497
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely unwarranted -- if we want touch coords to remain separate from a UX standpoint, this just won't cut it. Then again, I'm not even sure how that may relate to drag-and-drop softlock, so I'll wait until I get my code to work before I undo this change.

getVirtualPointer().notify_absolute_motion(
Clutter.get_current_event_time(),
x, y);
Expand Down
38 changes: 37 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,41 @@ const Display = global.display;
export let version = Config.PACKAGE_VERSION.split('.').map(Number);

let warpRipple;

let touchSignal = null;
let inTouch = false;
let touchCoords = null;

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

touchSignal = global.stage.connect("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;

global.stage.disconnect(touchSignal);
}

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

/**
* Retrieves global pointer coordinates taking into account touch screen events.
*/
export function getPointerCoords() {
if (inTouch)
return touchCoords;
else
return global.get_pointer();
}

/**
* Returns monitor a pointer co-ordinates.
*/
Expand All @@ -176,7 +212,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