2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported addDragMonitor, removeDragMonitor, makeDraggable */
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, GLib, Meta, Shell, St } = imports.gi;
|
2009-03-11 15:21:45 -04:00
|
|
|
const Signals = imports.signals;
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const Main = imports.ui.main;
|
2010-03-22 15:25:43 -04:00
|
|
|
const Params = imports.misc.params;
|
2019-02-08 22:21:36 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2010-03-22 15:25:43 -04:00
|
|
|
|
2010-03-22 16:29:13 -04:00
|
|
|
// Time to scale down to maxDragActorSize
|
2019-08-01 19:13:10 -04:00
|
|
|
var SCALE_ANIMATION_TIME = 250;
|
2010-03-22 16:29:13 -04:00
|
|
|
// Time to animate to original position on cancel
|
2019-08-01 19:13:10 -04:00
|
|
|
var SNAP_BACK_ANIMATION_TIME = 250;
|
2010-05-20 10:44:45 -04:00
|
|
|
// Time to animate to original position on success
|
2019-08-01 19:13:10 -04:00
|
|
|
var REVERT_ANIMATION_TIME = 750;
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var DragMotionResult = {
|
2010-06-06 10:22:27 -04:00
|
|
|
NO_DROP: 0,
|
|
|
|
COPY_DROP: 1,
|
|
|
|
MOVE_DROP: 2,
|
|
|
|
CONTINUE: 3
|
|
|
|
};
|
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
var DragState = {
|
|
|
|
INIT: 0,
|
|
|
|
DRAGGING: 1,
|
|
|
|
CANCELLED: 2,
|
|
|
|
};
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var DRAG_CURSOR_MAP = {
|
2013-09-11 11:35:58 -04:00
|
|
|
0: Meta.Cursor.DND_UNSUPPORTED_TARGET,
|
|
|
|
1: Meta.Cursor.DND_COPY,
|
|
|
|
2: Meta.Cursor.DND_MOVE
|
2010-09-09 22:00:28 -04:00
|
|
|
};
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var DragDropResult = {
|
2010-06-06 10:22:27 -04:00
|
|
|
FAILURE: 0,
|
|
|
|
SUCCESS: 1,
|
|
|
|
CONTINUE: 2
|
|
|
|
};
|
2017-09-18 13:38:18 -04:00
|
|
|
var dragMonitors = [];
|
2010-06-06 10:22:27 -04:00
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
let eventHandlerActor = null;
|
|
|
|
let currentDraggable = null;
|
|
|
|
|
|
|
|
function _getEventHandlerActor() {
|
|
|
|
if (!eventHandlerActor) {
|
2013-05-08 21:53:20 -04:00
|
|
|
eventHandlerActor = new Clutter.Actor({ width: 0, height: 0 });
|
2010-05-06 17:18:10 -04:00
|
|
|
Main.uiGroup.add_actor(eventHandlerActor);
|
2009-09-22 16:15:28 -04:00
|
|
|
// We connect to 'event' rather than 'captured-event' because the capturing phase doesn't happen
|
|
|
|
// when you've grabbed the pointer.
|
2017-10-30 20:38:18 -04:00
|
|
|
eventHandlerActor.connect('event', (actor, event) => {
|
|
|
|
return currentDraggable._onEvent(actor, event);
|
|
|
|
});
|
2009-09-22 16:15:28 -04:00
|
|
|
}
|
|
|
|
return eventHandlerActor;
|
|
|
|
}
|
|
|
|
|
2010-06-06 10:22:27 -04:00
|
|
|
function addDragMonitor(monitor) {
|
|
|
|
dragMonitors.push(monitor);
|
|
|
|
}
|
|
|
|
|
2011-06-27 12:59:56 -04:00
|
|
|
function removeDragMonitor(monitor) {
|
2010-06-06 10:22:27 -04:00
|
|
|
for (let i = 0; i < dragMonitors.length; i++)
|
|
|
|
if (dragMonitors[i] == monitor) {
|
|
|
|
dragMonitors.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var _Draggable = class _Draggable {
|
|
|
|
constructor(actor, params) {
|
2010-03-22 16:29:13 -04:00
|
|
|
params = Params.parse(params, { manualMode: false,
|
2010-05-20 10:44:45 -04:00
|
|
|
restoreOnSuccess: false,
|
2010-03-22 16:29:13 -04:00
|
|
|
dragActorMaxSize: undefined,
|
|
|
|
dragActorOpacity: undefined });
|
2010-03-22 15:25:43 -04:00
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
this.actor = actor;
|
2017-12-05 16:41:17 -05:00
|
|
|
this._dragState = DragState.INIT;
|
|
|
|
|
2015-10-16 12:28:11 -04:00
|
|
|
if (!params.manualMode) {
|
2009-09-01 14:07:31 -04:00
|
|
|
this.actor.connect('button-press-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onButtonPress.bind(this));
|
2015-10-16 12:28:11 -04:00
|
|
|
this.actor.connect('touch-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onTouchEvent.bind(this));
|
2015-10-16 12:28:11 -04:00
|
|
|
}
|
2010-03-17 18:23:32 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this.actor.connect('destroy', () => {
|
2010-10-23 21:45:54 -04:00
|
|
|
this._actorDestroyed = true;
|
2013-01-18 20:25:14 -05:00
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
if (this._dragState == DragState.DRAGGING && this._dragCancellable)
|
2010-10-23 21:45:54 -04:00
|
|
|
this._cancelDrag(global.get_current_time());
|
2010-03-17 18:23:32 -04:00
|
|
|
this.disconnectAll();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2009-09-22 16:15:28 -04:00
|
|
|
this._onEventId = null;
|
2017-09-17 04:37:17 -04:00
|
|
|
this._touchSequence = null;
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2010-05-20 10:44:45 -04:00
|
|
|
this._restoreOnSuccess = params.restoreOnSuccess;
|
2010-03-22 16:29:13 -04:00
|
|
|
this._dragActorMaxSize = params.dragActorMaxSize;
|
|
|
|
this._dragActorOpacity = params.dragActorOpacity;
|
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
this._buttonDown = false; // The mouse button has been pressed and has not yet been released.
|
2010-05-20 10:44:45 -04:00
|
|
|
this._animationInProgress = false; // The drag is over and the item is in the process of animating to its original position (snapping back or reverting).
|
2013-01-18 20:25:14 -05:00
|
|
|
this._dragCancellable = true;
|
2010-11-19 11:09:48 -05:00
|
|
|
|
|
|
|
this._eventsGrabbed = false;
|
2018-09-10 11:57:34 -04:00
|
|
|
this._capturedEventId = 0;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onButtonPress(actor, event) {
|
2010-03-26 21:24:50 -04:00
|
|
|
if (event.get_button() != 1)
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2010-03-26 21:24:50 -04:00
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
if (Tweener.getTweenCount(actor))
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
this._buttonDown = true;
|
2018-09-07 09:13:18 -04:00
|
|
|
this._grabActor(event.get_device());
|
2009-02-10 11:15:59 -05:00
|
|
|
|
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
this._dragStartX = stageX;
|
|
|
|
this._dragStartY = stageY;
|
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-03-08 17:50:49 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onTouchEvent(actor, event) {
|
2019-03-04 11:14:22 -05:00
|
|
|
// We only handle touch events here on wayland. On X11
|
|
|
|
// we do get emulated pointer events, which already works
|
|
|
|
// for single-touch cases. Besides, the X11 passive touch grab
|
|
|
|
// set up by Mutter will make us see first the touch events
|
|
|
|
// and later the pointer events, so it will look like two
|
|
|
|
// unrelated series of events, we want to avoid double handling
|
|
|
|
// in these cases.
|
|
|
|
if (!Meta.is_wayland_compositor())
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2015-10-16 12:28:11 -04:00
|
|
|
if (event.type() != Clutter.EventType.TOUCH_BEGIN ||
|
|
|
|
!global.display.is_pointer_emulating_sequence(event.get_event_sequence()))
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (Tweener.getTweenCount(actor))
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
this._buttonDown = true;
|
2018-09-07 09:13:18 -04:00
|
|
|
this._grabActor(event.get_device(), event.get_event_sequence());
|
2015-10-16 12:28:11 -04:00
|
|
|
|
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
this._dragStartX = stageX;
|
|
|
|
this._dragStartY = stageY;
|
|
|
|
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-10-16 12:28:11 -04:00
|
|
|
|
2018-09-07 09:13:18 -04:00
|
|
|
_grabDevice(actor, pointer, touchSequence) {
|
|
|
|
if (touchSequence)
|
|
|
|
pointer.sequence_grab(touchSequence, actor);
|
2015-10-16 12:28:11 -04:00
|
|
|
else if (pointer)
|
|
|
|
pointer.grab (actor);
|
|
|
|
|
|
|
|
this._grabbedDevice = pointer;
|
2018-09-07 09:13:18 -04:00
|
|
|
this._touchSequence = touchSequence;
|
2018-09-10 11:57:34 -04:00
|
|
|
|
|
|
|
this._capturedEventId = global.stage.connect('captured-event', (actor, event) => {
|
|
|
|
let device = event.get_device();
|
|
|
|
if (device != this._grabbedDevice &&
|
|
|
|
device.get_device_type() != Clutter.InputDeviceType.KEYBOARD_DEVICE)
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-10-16 12:28:11 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ungrabDevice() {
|
2018-09-10 11:57:34 -04:00
|
|
|
if (this._capturedEventId != 0) {
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:28:11 -04:00
|
|
|
if (this._touchSequence)
|
|
|
|
this._grabbedDevice.sequence_ungrab (this._touchSequence);
|
|
|
|
else
|
|
|
|
this._grabbedDevice.ungrab();
|
|
|
|
|
|
|
|
this._touchSequence = null;
|
|
|
|
this._grabbedDevice = null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-10-16 12:28:11 -04:00
|
|
|
|
2018-09-07 09:13:18 -04:00
|
|
|
_grabActor(device, touchSequence) {
|
|
|
|
this._grabDevice(this.actor, device, touchSequence);
|
2009-09-22 16:15:28 -04:00
|
|
|
this._onEventId = this.actor.connect('event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onEvent.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ungrabActor() {
|
2011-02-28 16:34:19 -05:00
|
|
|
if (!this._onEventId)
|
|
|
|
return;
|
2013-02-20 10:55:02 -05:00
|
|
|
|
2015-10-16 12:28:11 -04:00
|
|
|
this._ungrabDevice();
|
2009-09-22 16:15:28 -04:00
|
|
|
this.actor.disconnect(this._onEventId);
|
|
|
|
this._onEventId = null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2018-09-07 09:13:18 -04:00
|
|
|
_grabEvents(device, touchSequence) {
|
2010-11-19 11:09:48 -05:00
|
|
|
if (!this._eventsGrabbed) {
|
2013-05-23 09:49:42 -04:00
|
|
|
this._eventsGrabbed = Main.pushModal(_getEventHandlerActor());
|
|
|
|
if (this._eventsGrabbed)
|
2018-09-07 09:13:18 -04:00
|
|
|
this._grabDevice(_getEventHandlerActor(), device, touchSequence);
|
2010-11-19 11:09:48 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ungrabEvents() {
|
2010-11-19 11:09:48 -05:00
|
|
|
if (this._eventsGrabbed) {
|
2015-10-16 12:28:11 -04:00
|
|
|
this._ungrabDevice();
|
2013-05-23 09:49:42 -04:00
|
|
|
Main.popModal(_getEventHandlerActor());
|
2010-11-19 11:09:48 -05:00
|
|
|
this._eventsGrabbed = false;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2018-09-07 09:13:18 -04:00
|
|
|
_eventIsRelease(event) {
|
|
|
|
if (event.type() == Clutter.EventType.BUTTON_RELEASE) {
|
|
|
|
let buttonMask = (Clutter.ModifierType.BUTTON1_MASK |
|
|
|
|
Clutter.ModifierType.BUTTON2_MASK |
|
|
|
|
Clutter.ModifierType.BUTTON3_MASK);
|
|
|
|
/* We only obey the last button release from the device,
|
|
|
|
* other buttons may get pressed/released during the DnD op.
|
|
|
|
*/
|
|
|
|
return (event.get_state() & buttonMask) == 0;
|
|
|
|
} else if (event.type() == Clutter.EventType.TOUCH_END) {
|
|
|
|
/* For touch, we only obey the pointer emulating sequence */
|
|
|
|
return global.display.is_pointer_emulating_sequence(event.get_event_sequence());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-01-27 19:12:56 -05:00
|
|
|
}
|
2018-09-07 09:13:18 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onEvent(actor, event) {
|
2018-09-10 11:57:34 -04:00
|
|
|
let device = event.get_device();
|
|
|
|
|
|
|
|
if (this._grabbedDevice &&
|
|
|
|
device != this._grabbedDevice &&
|
|
|
|
device.get_device_type() != Clutter.InputDeviceType.KEYBOARD_DEVICE)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
// We intercept BUTTON_RELEASE event to know that the button was released in case we
|
|
|
|
// didn't start the drag, to drop the draggable in case the drag was in progress, and
|
|
|
|
// to complete the drag and ensure that whatever happens to be under the pointer does
|
|
|
|
// not get triggered if the drag was cancelled with Esc.
|
2018-09-07 09:13:18 -04:00
|
|
|
if (this._eventIsRelease(event)) {
|
2009-09-22 16:15:28 -04:00
|
|
|
this._buttonDown = false;
|
2017-12-05 16:41:17 -05:00
|
|
|
if (this._dragState == DragState.DRAGGING) {
|
2009-09-22 16:15:28 -04:00
|
|
|
return this._dragActorDropped(event);
|
2017-12-05 16:41:17 -05:00
|
|
|
} else if ((this._dragActor != null || this._dragState == DragState.CANCELLED) &&
|
|
|
|
!this._animationInProgress) {
|
2009-09-22 16:15:28 -04:00
|
|
|
// Drag must have been cancelled with Esc.
|
|
|
|
this._dragComplete();
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2009-09-22 16:15:28 -04:00
|
|
|
} else {
|
|
|
|
// Drag has never started.
|
|
|
|
this._ungrabActor();
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2009-09-22 16:15:28 -04:00
|
|
|
}
|
|
|
|
// We intercept MOTION event to figure out if the drag has started and to draw
|
|
|
|
// this._dragActor under the pointer when dragging is in progress
|
2015-10-16 12:28:11 -04:00
|
|
|
} else if (event.type() == Clutter.EventType.MOTION ||
|
|
|
|
(event.type() == Clutter.EventType.TOUCH_UPDATE &&
|
|
|
|
global.display.is_pointer_emulating_sequence(event.get_event_sequence()))) {
|
2017-12-05 16:41:17 -05:00
|
|
|
if (this._dragActor && this._dragState == DragState.DRAGGING) {
|
2009-09-22 16:15:28 -04:00
|
|
|
return this._updateDragPosition(event);
|
2017-12-05 16:41:17 -05:00
|
|
|
} else if (this._dragActor == null && this._dragState != DragState.CANCELLED) {
|
2009-09-22 16:15:28 -04:00
|
|
|
return this._maybeStartDrag(event);
|
|
|
|
}
|
|
|
|
// We intercept KEY_PRESS event so that we can process Esc key press to cancel
|
|
|
|
// dragging and ignore all other key presses.
|
2017-12-05 16:41:17 -05:00
|
|
|
} else if (event.type() == Clutter.EventType.KEY_PRESS && this._dragState == DragState.DRAGGING) {
|
2009-09-22 16:15:28 -04:00
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
this._cancelDrag(event.get_time());
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2009-09-22 16:15:28 -04:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2013-02-20 10:55:02 -05:00
|
|
|
/**
|
|
|
|
* fakeRelease:
|
|
|
|
*
|
|
|
|
* Fake a release event.
|
|
|
|
* Must be called if you want to intercept release events on draggable
|
|
|
|
* actors for other purposes (for example if you're using
|
|
|
|
* PopupMenu.ignoreRelease())
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
fakeRelease() {
|
2013-02-20 10:55:02 -05:00
|
|
|
this._buttonDown = false;
|
|
|
|
this._ungrabActor();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-20 10:55:02 -05:00
|
|
|
|
2009-09-01 14:07:31 -04:00
|
|
|
/**
|
|
|
|
* startDrag:
|
|
|
|
* @stageX: X coordinate of event
|
|
|
|
* @stageY: Y coordinate of event
|
|
|
|
* @time: Event timestamp
|
|
|
|
*
|
|
|
|
* Directly initiate a drag and drop operation from the given actor.
|
|
|
|
* This function is useful to call if you've specified manualMode
|
|
|
|
* for the draggable.
|
|
|
|
*/
|
2018-09-07 09:13:18 -04:00
|
|
|
startDrag(stageX, stageY, time, sequence, device) {
|
2019-03-11 20:53:16 -04:00
|
|
|
if (currentDraggable)
|
|
|
|
return;
|
|
|
|
|
2018-09-07 09:13:18 -04:00
|
|
|
if (device == undefined) {
|
|
|
|
let event = Clutter.get_current_event();
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
device = event.get_device();
|
|
|
|
|
|
|
|
if (device == undefined) {
|
|
|
|
let manager = Clutter.DeviceManager.get_default();
|
|
|
|
device = manager.get_core_device(Clutter.InputDeviceType.POINTER_DEVICE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
currentDraggable = this;
|
2017-12-05 16:41:17 -05:00
|
|
|
this._dragState = DragState.DRAGGING;
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2012-03-19 18:40:48 -04:00
|
|
|
// Special-case St.Button: the pointer grab messes with the internal
|
|
|
|
// state, so force a reset to a reasonable state here
|
|
|
|
if (this.actor instanceof St.Button) {
|
|
|
|
this.actor.fake_release();
|
|
|
|
this.actor.hover = false;
|
|
|
|
}
|
|
|
|
|
2009-09-01 14:07:31 -04:00
|
|
|
this.emit('drag-begin', time);
|
2009-09-22 16:15:28 -04:00
|
|
|
if (this._onEventId)
|
|
|
|
this._ungrabActor();
|
2015-10-16 12:28:11 -04:00
|
|
|
|
2018-09-07 09:13:18 -04:00
|
|
|
this._grabEvents(device, sequence);
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.DND_IN_DRAG);
|
2009-09-01 14:07:31 -04:00
|
|
|
|
2010-03-22 16:29:13 -04:00
|
|
|
this._dragX = this._dragStartX = stageX;
|
|
|
|
this._dragY = this._dragStartY = stageY;
|
2009-09-01 14:07:31 -04:00
|
|
|
|
|
|
|
if (this.actor._delegate && this.actor._delegate.getDragActor) {
|
2012-11-27 15:06:12 -05:00
|
|
|
this._dragActor = this.actor._delegate.getDragActor();
|
2013-08-26 19:14:35 -04:00
|
|
|
Main.uiGroup.add_child(this._dragActor);
|
2012-09-26 11:42:56 -04:00
|
|
|
this._dragActor.raise_top();
|
|
|
|
Shell.util_set_hidden_from_pick(this._dragActor, true);
|
|
|
|
|
2009-09-01 14:07:31 -04:00
|
|
|
// Drag actor does not always have to be the same as actor. For example drag actor
|
|
|
|
// can be an image that's part of the actor. So to perform "snap back" correctly we need
|
|
|
|
// to know what was the drag actor source.
|
|
|
|
if (this.actor._delegate.getDragActorSource) {
|
|
|
|
this._dragActorSource = this.actor._delegate.getDragActorSource();
|
|
|
|
// If the user dragged from the source, then position
|
|
|
|
// the dragActor over it. Otherwise, center it
|
|
|
|
// around the pointer
|
|
|
|
let [sourceX, sourceY] = this._dragActorSource.get_transformed_position();
|
|
|
|
let x, y;
|
2010-03-09 19:15:43 -05:00
|
|
|
if (stageX > sourceX && stageX <= sourceX + this._dragActor.width &&
|
|
|
|
stageY > sourceY && stageY <= sourceY + this._dragActor.height) {
|
2009-09-01 14:07:31 -04:00
|
|
|
x = sourceX;
|
|
|
|
y = sourceY;
|
|
|
|
} else {
|
|
|
|
x = stageX - this._dragActor.width / 2;
|
|
|
|
y = stageY - this._dragActor.height / 2;
|
|
|
|
}
|
|
|
|
this._dragActor.set_position(x, y);
|
|
|
|
} else {
|
|
|
|
this._dragActorSource = this.actor;
|
|
|
|
}
|
|
|
|
this._dragOrigParent = undefined;
|
|
|
|
|
2010-03-05 16:57:09 -05:00
|
|
|
this._dragOffsetX = this._dragActor.x - this._dragStartX;
|
|
|
|
this._dragOffsetY = this._dragActor.y - this._dragStartY;
|
2009-09-01 14:07:31 -04:00
|
|
|
} else {
|
2009-09-22 16:15:28 -04:00
|
|
|
this._dragActor = this.actor;
|
2012-09-26 11:42:56 -04:00
|
|
|
|
2009-09-01 14:07:31 -04:00
|
|
|
this._dragActorSource = undefined;
|
2009-09-22 16:15:28 -04:00
|
|
|
this._dragOrigParent = this.actor.get_parent();
|
2009-09-01 14:07:31 -04:00
|
|
|
this._dragOrigX = this._dragActor.x;
|
|
|
|
this._dragOrigY = this._dragActor.y;
|
|
|
|
this._dragOrigScale = this._dragActor.scale_x;
|
|
|
|
|
|
|
|
// Set the actor's scale such that it will keep the same
|
2011-06-30 14:57:37 -04:00
|
|
|
// transformed size when it's reparented to the uiGroup
|
2009-09-22 16:15:28 -04:00
|
|
|
let [scaledWidth, scaledHeight] = this.actor.get_transformed_size();
|
2013-04-07 14:56:46 -04:00
|
|
|
this._dragActor.set_scale(scaledWidth / this.actor.width,
|
|
|
|
scaledHeight / this.actor.height);
|
2013-04-07 14:58:25 -04:00
|
|
|
|
|
|
|
let [actorStageX, actorStageY] = this.actor.get_transformed_position();
|
|
|
|
this._dragOffsetX = actorStageX - this._dragStartX;
|
|
|
|
this._dragOffsetY = actorStageY - this._dragStartY;
|
|
|
|
|
2013-08-26 19:14:35 -04:00
|
|
|
this._dragOrigParent.remove_actor(this._dragActor);
|
|
|
|
Main.uiGroup.add_child(this._dragActor);
|
2013-04-07 14:58:25 -04:00
|
|
|
this._dragActor.raise_top();
|
|
|
|
Shell.util_set_hidden_from_pick(this._dragActor, true);
|
2009-09-01 14:07:31 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
this._dragActorDestroyId = this._dragActor.connect('destroy', () => {
|
|
|
|
// Cancel ongoing animation (if any)
|
|
|
|
this._finishAnimation();
|
|
|
|
|
|
|
|
this._dragActor = null;
|
2018-09-10 08:24:57 -04:00
|
|
|
if (this._dragState == DragState.DRAGGING)
|
|
|
|
this._dragState = DragState.CANCELLED;
|
2017-12-05 16:41:17 -05:00
|
|
|
});
|
2010-03-22 16:29:13 -04:00
|
|
|
this._dragOrigOpacity = this._dragActor.opacity;
|
|
|
|
if (this._dragActorOpacity != undefined)
|
|
|
|
this._dragActor.opacity = this._dragActorOpacity;
|
|
|
|
|
|
|
|
this._snapBackX = this._dragStartX + this._dragOffsetX;
|
|
|
|
this._snapBackY = this._dragStartY + this._dragOffsetY;
|
|
|
|
this._snapBackScale = this._dragActor.scale_x;
|
|
|
|
|
|
|
|
if (this._dragActorMaxSize != undefined) {
|
|
|
|
let [scaledWidth, scaledHeight] = this._dragActor.get_transformed_size();
|
|
|
|
let currentSize = Math.max(scaledWidth, scaledHeight);
|
|
|
|
if (currentSize > this._dragActorMaxSize) {
|
|
|
|
let scale = this._dragActorMaxSize / currentSize;
|
|
|
|
let origScale = this._dragActor.scale_x;
|
|
|
|
let origDragOffsetX = this._dragOffsetX;
|
|
|
|
let origDragOffsetY = this._dragOffsetY;
|
|
|
|
|
|
|
|
// The position of the actor changes as we scale
|
|
|
|
// around the drag position, but we can't just tween
|
|
|
|
// to the final position because that tween would
|
|
|
|
// fight with updates as the user continues dragging
|
|
|
|
// the mouse; instead we do the position computations in
|
|
|
|
// an onUpdate() function.
|
|
|
|
Tweener.addTween(this._dragActor,
|
|
|
|
{ scale_x: scale * origScale,
|
|
|
|
scale_y: scale * origScale,
|
2019-08-01 19:13:10 -04:00
|
|
|
time: SCALE_ANIMATION_TIME / 1000,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad',
|
2019-06-29 11:37:59 -04:00
|
|
|
onUpdate: () => {
|
2010-03-22 16:29:13 -04:00
|
|
|
let currentScale = this._dragActor.scale_x / origScale;
|
|
|
|
this._dragOffsetX = currentScale * origDragOffsetX;
|
|
|
|
this._dragOffsetY = currentScale * origDragOffsetY;
|
|
|
|
this._dragActor.set_position(this._dragX + this._dragOffsetX,
|
|
|
|
this._dragY + this._dragOffsetY);
|
2019-06-29 11:37:59 -04:00
|
|
|
} });
|
2010-03-22 16:29:13 -04:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-01 14:07:31 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_maybeStartDrag(event) {
|
2009-02-10 11:15:59 -05:00
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
// See if the user has moved the mouse enough to trigger a drag
|
2019-03-11 21:14:07 -04:00
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
let threshold = St.Settings.get().drag_threshold * scaleFactor;
|
2018-09-10 11:57:34 -04:00
|
|
|
if (!currentDraggable &&
|
|
|
|
(Math.abs(stageX - this._dragStartX) > threshold ||
|
2009-02-10 11:15:59 -05:00
|
|
|
Math.abs(stageY - this._dragStartY) > threshold)) {
|
2018-09-07 09:13:18 -04:00
|
|
|
this.startDrag(stageX, stageY, event.get_time(), this._touchSequence, event.get_device());
|
2015-10-16 12:28:11 -04:00
|
|
|
this._updateDragPosition(event);
|
2009-02-10 11:15:59 -05:00
|
|
|
}
|
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2019-01-03 05:53:13 -05:00
|
|
|
_pickTargetActor() {
|
|
|
|
return this._dragActor.get_stage().get_actor_at_pos(Clutter.PickMode.ALL,
|
|
|
|
this._dragX, this._dragY);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-01-03 05:53:13 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateDragHover() {
|
2013-11-06 04:40:29 -05:00
|
|
|
this._updateHoverId = 0;
|
2019-01-03 05:53:13 -05:00
|
|
|
let target = this._pickTargetActor();
|
|
|
|
|
2013-07-02 02:04:08 -04:00
|
|
|
let dragEvent = {
|
|
|
|
x: this._dragX,
|
|
|
|
y: this._dragY,
|
|
|
|
dragActor: this._dragActor,
|
|
|
|
source: this.actor._delegate,
|
|
|
|
targetActor: target
|
|
|
|
};
|
2019-01-03 05:53:13 -05:00
|
|
|
|
|
|
|
let targetActorDestroyHandlerId;
|
|
|
|
let handleTargetActorDestroyClosure;
|
|
|
|
handleTargetActorDestroyClosure = () => {
|
|
|
|
target = this._pickTargetActor();
|
|
|
|
dragEvent.targetActor = target;
|
|
|
|
targetActorDestroyHandlerId =
|
|
|
|
target.connect('destroy', handleTargetActorDestroyClosure);
|
|
|
|
};
|
|
|
|
targetActorDestroyHandlerId =
|
|
|
|
target.connect('destroy', handleTargetActorDestroyClosure);
|
|
|
|
|
2013-07-02 02:04:08 -04:00
|
|
|
for (let i = 0; i < dragMonitors.length; i++) {
|
|
|
|
let motionFunc = dragMonitors[i].dragMotion;
|
|
|
|
if (motionFunc) {
|
|
|
|
let result = motionFunc(dragEvent);
|
|
|
|
if (result != DragMotionResult.CONTINUE) {
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(DRAG_CURSOR_MAP[result]);
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2010-09-09 22:00:28 -04:00
|
|
|
}
|
2010-06-06 10:22:27 -04:00
|
|
|
}
|
2013-07-02 02:04:08 -04:00
|
|
|
}
|
2019-01-03 05:53:13 -05:00
|
|
|
dragEvent.targetActor.disconnect(targetActorDestroyHandlerId);
|
2013-07-02 02:04:08 -04:00
|
|
|
|
|
|
|
while (target) {
|
|
|
|
if (target._delegate && target._delegate.handleDragOver) {
|
2019-01-31 09:08:00 -05:00
|
|
|
let [r_, targX, targY] = target.transform_stage_point(this._dragX, this._dragY);
|
2013-07-02 02:04:08 -04:00
|
|
|
// We currently loop through all parents on drag-over even if one of the children has handled it.
|
|
|
|
// We can check the return value of the function and break the loop if it's true if we don't want
|
|
|
|
// to continue checking the parents.
|
|
|
|
let result = target._delegate.handleDragOver(this.actor._delegate,
|
|
|
|
this._dragActor,
|
|
|
|
targX,
|
|
|
|
targY,
|
|
|
|
0);
|
|
|
|
if (result != DragMotionResult.CONTINUE) {
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(DRAG_CURSOR_MAP[result]);
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2009-03-11 15:21:45 -04:00
|
|
|
}
|
2009-09-01 14:07:31 -04:00
|
|
|
}
|
2013-07-02 02:04:08 -04:00
|
|
|
target = target.get_parent();
|
2009-02-10 11:15:59 -05:00
|
|
|
}
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.DND_IN_DRAG);
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-02 02:04:08 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_queueUpdateDragHover() {
|
2013-07-02 02:04:08 -04:00
|
|
|
if (this._updateHoverId)
|
2013-11-06 12:22:47 -05:00
|
|
|
return;
|
2013-07-02 02:04:08 -04:00
|
|
|
|
|
|
|
this._updateHoverId = GLib.idle_add(GLib.PRIORITY_DEFAULT,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateDragHover.bind(this));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._updateHoverId, '[gnome-shell] this._updateDragHover');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateDragPosition(event) {
|
2013-07-02 02:04:08 -04:00
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
this._dragX = stageX;
|
|
|
|
this._dragY = stageY;
|
|
|
|
this._dragActor.set_position(stageX + this._dragOffsetX,
|
|
|
|
stageY + this._dragOffsetY);
|
|
|
|
|
|
|
|
this._queueUpdateDragHover();
|
2009-02-10 11:15:59 -05:00
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_dragActorDropped(event) {
|
2009-02-10 11:15:59 -05:00
|
|
|
let [dropX, dropY] = event.get_coords();
|
2009-09-22 16:15:28 -04:00
|
|
|
let target = this._dragActor.get_stage().get_actor_at_pos(Clutter.PickMode.ALL,
|
|
|
|
dropX, dropY);
|
2010-06-06 10:22:27 -04:00
|
|
|
|
|
|
|
// We call observers only once per motion with the innermost
|
|
|
|
// target actor. If necessary, the observer can walk the
|
|
|
|
// parent itself.
|
|
|
|
let dropEvent = {
|
|
|
|
dropActor: this._dragActor,
|
|
|
|
targetActor: target,
|
|
|
|
clutterEvent: event
|
|
|
|
};
|
|
|
|
for (let i = 0; i < dragMonitors.length; i++) {
|
|
|
|
let dropFunc = dragMonitors[i].dragDrop;
|
|
|
|
if (dropFunc)
|
|
|
|
switch (dropFunc(dropEvent)) {
|
2019-02-01 07:21:00 -05:00
|
|
|
case DragDropResult.FAILURE:
|
|
|
|
case DragDropResult.SUCCESS:
|
|
|
|
return true;
|
|
|
|
case DragDropResult.CONTINUE:
|
|
|
|
continue;
|
2010-06-06 10:22:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 20:25:14 -05:00
|
|
|
// At this point it is too late to cancel a drag by destroying
|
|
|
|
// the actor, the fate of which is decided by acceptDrop and its
|
|
|
|
// side-effects
|
|
|
|
this._dragCancellable = false;
|
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
while (target) {
|
2010-01-20 14:01:37 -05:00
|
|
|
if (target._delegate && target._delegate.acceptDrop) {
|
2019-01-31 09:08:00 -05:00
|
|
|
let [r_, targX, targY] = target.transform_stage_point(dropX, dropY);
|
2010-05-20 10:13:27 -04:00
|
|
|
if (target._delegate.acceptDrop(this.actor._delegate,
|
|
|
|
this._dragActor,
|
|
|
|
targX,
|
|
|
|
targY,
|
2009-02-10 11:15:59 -05:00
|
|
|
event.get_time())) {
|
|
|
|
// If it accepted the drop without taking the actor,
|
2010-05-20 10:44:45 -04:00
|
|
|
// handle it ourselves.
|
2017-12-05 16:41:17 -05:00
|
|
|
if (this._dragActor && this._dragActor.get_parent() == Main.uiGroup) {
|
2010-05-20 10:44:45 -04:00
|
|
|
if (this._restoreOnSuccess) {
|
|
|
|
this._restoreDragActor(event.get_time());
|
|
|
|
return true;
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2010-05-20 10:44:45 -04:00
|
|
|
this._dragActor.destroy();
|
2019-01-29 16:02:57 -05:00
|
|
|
}
|
2010-05-20 10:44:45 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
this._dragState = DragState.INIT;
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
2009-07-23 17:34:01 -04:00
|
|
|
this.emit('drag-end', event.get_time(), true);
|
2009-09-22 16:15:28 -04:00
|
|
|
this._dragComplete();
|
2009-02-10 11:15:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target = target.get_parent();
|
|
|
|
}
|
|
|
|
|
2009-09-22 16:15:28 -04:00
|
|
|
this._cancelDrag(event.get_time());
|
|
|
|
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getRestoreLocation() {
|
2010-11-19 10:18:14 -05:00
|
|
|
let x, y, scale;
|
|
|
|
|
|
|
|
if (this._dragActorSource && this._dragActorSource.visible) {
|
|
|
|
// Snap the clone back to its source
|
|
|
|
[x, y] = this._dragActorSource.get_transformed_position();
|
2019-02-01 08:41:55 -05:00
|
|
|
let [sourceScaledWidth] = this._dragActorSource.get_transformed_size();
|
2017-06-29 21:22:42 -04:00
|
|
|
scale = sourceScaledWidth ? this._dragActor.width / sourceScaledWidth : 0;
|
2010-11-19 10:18:14 -05:00
|
|
|
} else if (this._dragOrigParent) {
|
|
|
|
// Snap the actor back to its original position within
|
|
|
|
// its parent, adjusting for the fact that the parent
|
|
|
|
// may have been moved or scaled
|
|
|
|
let [parentX, parentY] = this._dragOrigParent.get_transformed_position();
|
2019-02-01 08:41:55 -05:00
|
|
|
let [parentWidth] = this._dragOrigParent.get_size();
|
|
|
|
let [parentScaledWidth] = this._dragOrigParent.get_transformed_size();
|
2011-03-04 08:21:17 -05:00
|
|
|
let parentScale = 1.0;
|
|
|
|
if (parentWidth != 0)
|
|
|
|
parentScale = parentScaledWidth / parentWidth;
|
2011-02-11 12:19:12 -05:00
|
|
|
|
|
|
|
x = parentX + parentScale * this._dragOrigX;
|
|
|
|
y = parentY + parentScale * this._dragOrigY;
|
2010-11-19 10:18:14 -05:00
|
|
|
scale = this._dragOrigScale * parentScale;
|
|
|
|
} else {
|
|
|
|
// Snap back actor to its original stage position
|
|
|
|
x = this._snapBackX;
|
|
|
|
y = this._snapBackY;
|
|
|
|
scale = this._snapBackScale;
|
|
|
|
}
|
2010-05-20 10:44:45 -04:00
|
|
|
|
2010-11-19 10:18:14 -05:00
|
|
|
return [x, y, scale];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 10:44:45 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_cancelDrag(eventTime) {
|
2011-03-08 08:44:47 -05:00
|
|
|
this.emit('drag-cancelled', eventTime);
|
2017-12-05 16:41:17 -05:00
|
|
|
let wasCancelled = (this._dragState == DragState.CANCELLED);
|
|
|
|
this._dragState = DragState.CANCELLED;
|
2009-03-11 15:21:45 -04:00
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
if (this._actorDestroyed || wasCancelled) {
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
2010-11-19 11:09:48 -05:00
|
|
|
if (!this._buttonDown)
|
2011-01-30 17:39:50 -05:00
|
|
|
this._dragComplete();
|
2010-10-23 21:45:54 -04:00
|
|
|
this.emit('drag-end', eventTime, false);
|
2017-12-05 16:41:17 -05:00
|
|
|
if (!this._dragOrigParent && this._dragActor)
|
2011-01-30 18:04:56 -05:00
|
|
|
this._dragActor.destroy();
|
|
|
|
|
2010-10-23 21:45:54 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
let [snapBackX, snapBackY, snapBackScale] = this._getRestoreLocation();
|
|
|
|
|
2016-03-31 08:26:06 -04:00
|
|
|
this._animateDragEnd(eventTime,
|
|
|
|
{ x: snapBackX,
|
|
|
|
y: snapBackY,
|
|
|
|
scale_x: snapBackScale,
|
|
|
|
scale_y: snapBackScale,
|
2019-08-01 19:13:10 -04:00
|
|
|
time: SNAP_BACK_ANIMATION_TIME / 1000,
|
2016-03-31 08:26:06 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-05-20 10:44:45 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_restoreDragActor(eventTime) {
|
2017-12-05 16:41:17 -05:00
|
|
|
this._dragState = DragState.INIT;
|
2017-12-06 19:03:51 -05:00
|
|
|
let [restoreX, restoreY, restoreScale] = this._getRestoreLocation();
|
2010-05-20 10:44:45 -04:00
|
|
|
|
|
|
|
// fade the actor back in at its original location
|
|
|
|
this._dragActor.set_position(restoreX, restoreY);
|
2010-11-19 10:18:14 -05:00
|
|
|
this._dragActor.set_scale(restoreScale, restoreScale);
|
2010-05-20 10:44:45 -04:00
|
|
|
this._dragActor.opacity = 0;
|
|
|
|
|
2016-03-31 08:26:06 -04:00
|
|
|
this._animateDragEnd(eventTime,
|
2019-08-01 19:13:10 -04:00
|
|
|
{ time: REVERT_ANIMATION_TIME / 1000 });
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-03-31 08:26:06 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_animateDragEnd(eventTime, params) {
|
2010-05-20 10:44:45 -04:00
|
|
|
this._animationInProgress = true;
|
2016-03-31 08:26:06 -04:00
|
|
|
|
|
|
|
params['opacity'] = this._dragOrigOpacity;
|
|
|
|
params['transition'] = 'easeOutQuad';
|
|
|
|
params['onComplete'] = this._onAnimationComplete;
|
|
|
|
params['onCompleteScope'] = this;
|
|
|
|
params['onCompleteParams'] = [this._dragActor, eventTime];
|
|
|
|
|
|
|
|
// start the animation
|
2019-01-28 20:18:52 -05:00
|
|
|
Tweener.addTween(this._dragActor, params);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-03-31 08:26:06 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_finishAnimation() {
|
2016-03-31 08:26:06 -04:00
|
|
|
if (!this._animationInProgress)
|
2019-01-28 20:18:52 -05:00
|
|
|
return;
|
2016-03-31 08:26:06 -04:00
|
|
|
|
|
|
|
this._animationInProgress = false;
|
|
|
|
if (!this._buttonDown)
|
|
|
|
this._dragComplete();
|
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onAnimationComplete(dragActor, eventTime) {
|
2009-02-10 11:15:59 -05:00
|
|
|
if (this._dragOrigParent) {
|
2013-08-26 19:14:35 -04:00
|
|
|
Main.uiGroup.remove_child(this._dragActor);
|
|
|
|
this._dragOrigParent.add_actor(this._dragActor);
|
2009-02-10 11:15:59 -05:00
|
|
|
dragActor.set_scale(this._dragOrigScale, this._dragOrigScale);
|
|
|
|
dragActor.set_position(this._dragOrigX, this._dragOrigY);
|
2009-07-23 17:34:01 -04:00
|
|
|
} else {
|
2009-02-10 11:15:59 -05:00
|
|
|
dragActor.destroy();
|
2009-07-23 17:34:01 -04:00
|
|
|
}
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2016-03-31 08:26:06 -04:00
|
|
|
this.emit('drag-end', eventTime, false);
|
|
|
|
this._finishAnimation();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-22 16:15:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_dragComplete() {
|
2017-12-05 16:41:17 -05:00
|
|
|
if (!this._actorDestroyed && this._dragActor)
|
2011-01-30 17:39:50 -05:00
|
|
|
Shell.util_set_hidden_from_pick(this._dragActor, false);
|
|
|
|
|
|
|
|
this._ungrabEvents();
|
2013-09-10 21:06:25 -04:00
|
|
|
global.sync_pointer();
|
2010-11-17 05:00:35 -05:00
|
|
|
|
2013-09-11 15:09:09 -04:00
|
|
|
if (this._updateHoverId) {
|
|
|
|
GLib.source_remove(this._updateHoverId);
|
|
|
|
this._updateHoverId = 0;
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:41:17 -05:00
|
|
|
if (this._dragActor) {
|
|
|
|
this._dragActor.disconnect(this._dragActorDestroyId);
|
|
|
|
this._dragActor = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._dragState = DragState.INIT;
|
2009-09-22 16:15:28 -04:00
|
|
|
currentDraggable = null;
|
2009-02-10 11:15:59 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2009-02-10 11:15:59 -05:00
|
|
|
Signals.addSignalMethods(_Draggable.prototype);
|
|
|
|
|
2009-09-01 14:07:31 -04:00
|
|
|
/**
|
|
|
|
* makeDraggable:
|
|
|
|
* @actor: Source actor
|
2010-03-22 15:25:43 -04:00
|
|
|
* @params: (optional) Additional parameters
|
2009-09-01 14:07:31 -04:00
|
|
|
*
|
|
|
|
* Create an object which controls drag and drop for the given actor.
|
2010-03-22 15:25:43 -04:00
|
|
|
*
|
|
|
|
* If %manualMode is %true in @params, do not automatically start
|
|
|
|
* drag and drop on click
|
2010-03-22 16:29:13 -04:00
|
|
|
*
|
|
|
|
* If %dragActorMaxSize is present in @params, the drag actor will
|
|
|
|
* be scaled down to be no larger than that size in pixels.
|
|
|
|
*
|
|
|
|
* If %dragActorOpacity is present in @params, the drag actor will
|
|
|
|
* will be set to have that opacity during the drag.
|
|
|
|
*
|
|
|
|
* Note that when the drag actor is the source actor and the drop
|
|
|
|
* succeeds, the actor scale and opacity aren't reset; if the drop
|
|
|
|
* target wants to reuse the actor, it's up to the drop target to
|
|
|
|
* reset these values.
|
2009-09-01 14:07:31 -04:00
|
|
|
*/
|
2010-03-22 15:25:43 -04:00
|
|
|
function makeDraggable(actor, params) {
|
|
|
|
return new _Draggable(actor, params);
|
2009-03-11 15:21:45 -04:00
|
|
|
}
|