2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2013-02-15 06:58:21 +00:00
|
|
|
const Main = imports.ui.main;
|
2013-09-11 15:50:18 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2011-01-05 14:47:27 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const DND = imports.ui.dnd;
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var XdndHandler = class {
|
|
|
|
constructor() {
|
2011-01-05 14:47:27 +00:00
|
|
|
// Used to display a clone of the cursor window when the
|
|
|
|
// window group is hidden (like it happens in the overview)
|
|
|
|
this._cursorWindowClone = null;
|
|
|
|
|
|
|
|
// Used as a drag actor in case we don't have a cursor window clone
|
2013-05-09 01:53:20 +00:00
|
|
|
this._dummy = new Clutter.Actor({ width: 1, height: 1, opacity: 0 });
|
2013-02-15 06:58:21 +00:00
|
|
|
Main.uiGroup.add_actor(this._dummy);
|
2011-01-05 14:47:27 +00:00
|
|
|
this._dummy.hide();
|
|
|
|
|
2013-09-11 15:50:18 +00:00
|
|
|
if (!Meta.is_wayland_compositor())
|
|
|
|
global.init_xdnd();
|
2011-01-05 14:47:27 +00:00
|
|
|
|
2016-12-24 08:56:52 +00:00
|
|
|
var dnd = Meta.get_backend().get_dnd();
|
2017-12-02 00:27:35 +00:00
|
|
|
dnd.connect('dnd-enter', this._onEnter.bind(this));
|
|
|
|
dnd.connect('dnd-position-change', this._onPositionChanged.bind(this));
|
|
|
|
dnd.connect('dnd-leave', this._onLeave.bind(this));
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
this._windowGroupVisibilityHandlerId = 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
// Called when the user cancels the drag (i.e release the button)
|
2017-10-31 00:03:21 +00:00
|
|
|
_onLeave() {
|
2011-01-05 14:47:27 +00:00
|
|
|
if (this._windowGroupVisibilityHandlerId != 0) {
|
2011-03-04 07:57:46 +00:00
|
|
|
global.window_group.disconnect(this._windowGroupVisibilityHandlerId);
|
2011-01-05 14:47:27 +00:00
|
|
|
this._windowGroupVisibilityHandlerId = 0;
|
|
|
|
}
|
2011-03-04 07:57:46 +00:00
|
|
|
if (this._cursorWindowClone) {
|
|
|
|
this._cursorWindowClone.destroy();
|
|
|
|
this._cursorWindowClone = null;
|
|
|
|
}
|
|
|
|
|
2011-01-05 14:47:27 +00:00
|
|
|
this.emit('drag-end');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-05 14:47:27 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onEnter() {
|
2011-01-05 14:47:27 +00:00
|
|
|
this._windowGroupVisibilityHandlerId =
|
|
|
|
global.window_group.connect('notify::visible',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onWindowGroupVisibilityChanged.bind(this));
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
this.emit('drag-begin', global.get_current_time());
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-05 14:47:27 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onWindowGroupVisibilityChanged() {
|
2011-01-05 14:47:27 +00:00
|
|
|
if (!global.window_group.visible) {
|
|
|
|
if (this._cursorWindowClone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let windows = global.get_window_actors();
|
|
|
|
let cursorWindow = windows[windows.length - 1];
|
|
|
|
|
|
|
|
// FIXME: more reliable way?
|
2013-11-05 02:24:27 +00:00
|
|
|
if (!cursorWindow.get_meta_window().is_override_redirect())
|
2011-01-05 14:47:27 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-26 19:38:22 +00:00
|
|
|
let constraint_position = new Clutter.BindConstraint({ coordinate : Clutter.BindCoordinate.POSITION,
|
|
|
|
source: cursorWindow});
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
this._cursorWindowClone = new Clutter.Clone({ source: cursorWindow });
|
2013-03-03 19:15:28 +00:00
|
|
|
Main.uiGroup.add_actor(this._cursorWindowClone);
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
// Make sure that the clone has the same position as the source
|
2011-01-26 19:38:22 +00:00
|
|
|
this._cursorWindowClone.add_constraint(constraint_position);
|
2011-01-05 14:47:27 +00:00
|
|
|
} else {
|
2011-03-04 07:57:46 +00:00
|
|
|
if (this._cursorWindowClone) {
|
2011-01-05 14:47:27 +00:00
|
|
|
this._cursorWindowClone.destroy();
|
|
|
|
this._cursorWindowClone = null;
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-05 14:47:27 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onPositionChanged(obj, x, y) {
|
2013-02-22 18:58:38 +00:00
|
|
|
let pickedActor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
|
2011-01-05 14:47:27 +00:00
|
|
|
|
|
|
|
// Make sure that the cursor window is on top
|
|
|
|
if (this._cursorWindowClone)
|
|
|
|
this._cursorWindowClone.raise_top();
|
|
|
|
|
|
|
|
let dragEvent = {
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
dragActor: this._cursorWindowClone ? this._cursorWindowClone : this._dummy,
|
|
|
|
source: this,
|
|
|
|
targetActor: pickedActor
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let i = 0; i < DND.dragMonitors.length; i++) {
|
|
|
|
let motionFunc = DND.dragMonitors[i].dragMotion;
|
|
|
|
if (motionFunc) {
|
|
|
|
let result = motionFunc(dragEvent);
|
|
|
|
if (result != DND.DragMotionResult.CONTINUE)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (pickedActor) {
|
|
|
|
if (pickedActor._delegate && pickedActor._delegate.handleDragOver) {
|
2012-02-11 10:07:04 +00:00
|
|
|
let [r, targX, targY] = pickedActor.transform_stage_point(x, y);
|
2011-01-05 14:47:27 +00:00
|
|
|
let result = pickedActor._delegate.handleDragOver(this,
|
|
|
|
dragEvent.dragActor,
|
2012-02-11 10:07:04 +00:00
|
|
|
targX,
|
|
|
|
targY,
|
2011-01-05 14:47:27 +00:00
|
|
|
global.get_current_time());
|
|
|
|
if (result != DND.DragMotionResult.CONTINUE)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pickedActor = pickedActor.get_parent();
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2011-01-05 14:47:27 +00:00
|
|
|
Signals.addSignalMethods(XdndHandler.prototype);
|