2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-05 09:47:27 -05:00
|
|
|
|
2020-04-21 12:04:56 -04:00
|
|
|
const { Clutter } = imports.gi;
|
2011-01-05 09:47:27 -05:00
|
|
|
const Signals = imports.signals;
|
2019-02-08 22:21:36 -05:00
|
|
|
|
2011-01-05 09:47:27 -05:00
|
|
|
const DND = imports.ui.dnd;
|
2019-02-08 22:21:36 -05:00
|
|
|
const Main = imports.ui.main;
|
2011-01-05 09:47:27 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var XdndHandler = class {
|
|
|
|
constructor() {
|
2011-01-05 09:47:27 -05: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-08 21:53:20 -04:00
|
|
|
this._dummy = new Clutter.Actor({ width: 1, height: 1, opacity: 0 });
|
2013-02-15 01:58:21 -05:00
|
|
|
Main.uiGroup.add_actor(this._dummy);
|
2011-01-05 09:47:27 -05:00
|
|
|
this._dummy.hide();
|
|
|
|
|
2020-04-21 12:04:56 -04:00
|
|
|
var dnd = global.backend.get_dnd();
|
2017-12-01 19:27:35 -05: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));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-05 09:47:27 -05:00
|
|
|
|
|
|
|
// Called when the user cancels the drag (i.e release the button)
|
2017-10-30 20:03:21 -04:00
|
|
|
_onLeave() {
|
2021-08-15 18:36:59 -04:00
|
|
|
global.window_group.disconnectObject(this);
|
2011-03-04 02:57:46 -05:00
|
|
|
if (this._cursorWindowClone) {
|
|
|
|
this._cursorWindowClone.destroy();
|
|
|
|
this._cursorWindowClone = null;
|
|
|
|
}
|
|
|
|
|
2011-01-05 09:47:27 -05:00
|
|
|
this.emit('drag-end');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-05 09:47:27 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onEnter() {
|
2021-08-15 18:36:59 -04:00
|
|
|
global.window_group.connectObject('notify::visible',
|
|
|
|
this._onWindowGroupVisibilityChanged.bind(this), this);
|
2011-01-05 09:47:27 -05:00
|
|
|
|
|
|
|
this.emit('drag-begin', global.get_current_time());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-05 09:47:27 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onWindowGroupVisibilityChanged() {
|
2011-01-05 09:47:27 -05: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-04 21:24:27 -05:00
|
|
|
if (!cursorWindow.get_meta_window().is_override_redirect())
|
2011-01-05 09:47:27 -05:00
|
|
|
return;
|
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
const constraintPosition = new Clutter.BindConstraint({
|
|
|
|
coordinate: Clutter.BindCoordinate.POSITION,
|
|
|
|
source: cursorWindow,
|
|
|
|
});
|
2011-01-05 09:47:27 -05:00
|
|
|
|
|
|
|
this._cursorWindowClone = new Clutter.Clone({ source: cursorWindow });
|
2013-03-03 14:15:28 -05:00
|
|
|
Main.uiGroup.add_actor(this._cursorWindowClone);
|
2011-01-05 09:47:27 -05:00
|
|
|
|
|
|
|
// Make sure that the clone has the same position as the source
|
2019-01-31 08:43:52 -05:00
|
|
|
this._cursorWindowClone.add_constraint(constraintPosition);
|
2011-01-05 09:47:27 -05:00
|
|
|
} else {
|
2019-08-19 22:10:46 -04:00
|
|
|
if (!this._cursorWindowClone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._cursorWindowClone.destroy();
|
|
|
|
this._cursorWindowClone = null;
|
2011-01-05 09:47:27 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-05 09:47:27 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPositionChanged(obj, x, y) {
|
2013-02-22 13:58:38 -05:00
|
|
|
let pickedActor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
|
2011-01-05 09:47:27 -05:00
|
|
|
|
|
|
|
// Make sure that the cursor window is on top
|
|
|
|
if (this._cursorWindowClone)
|
2019-11-05 14:17:19 -05:00
|
|
|
Main.uiGroup.set_child_above_sibling(this._cursorWindowClone, null);
|
2011-01-05 09:47:27 -05:00
|
|
|
|
|
|
|
let dragEvent = {
|
2019-08-19 15:06:04 -04:00
|
|
|
x,
|
|
|
|
y,
|
2020-08-12 14:59:01 -04:00
|
|
|
dragActor: this._cursorWindowClone ?? this._dummy,
|
2011-01-05 09:47:27 -05:00
|
|
|
source: this,
|
2019-08-20 17:43:54 -04:00
|
|
|
targetActor: pickedActor,
|
2011-01-05 09:47:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2019-01-29 14:36:54 -05:00
|
|
|
if (pickedActor._delegate && pickedActor._delegate.handleDragOver) {
|
2019-01-31 09:08:00 -05:00
|
|
|
let [r_, targX, targY] = pickedActor.transform_stage_point(x, y);
|
2019-01-29 14:36:54 -05:00
|
|
|
let result = pickedActor._delegate.handleDragOver(this,
|
|
|
|
dragEvent.dragActor,
|
|
|
|
targX,
|
|
|
|
targY,
|
|
|
|
global.get_current_time());
|
|
|
|
if (result != DND.DragMotionResult.CONTINUE)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pickedActor = pickedActor.get_parent();
|
2011-01-05 09:47:27 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2011-01-05 09:47:27 -05:00
|
|
|
Signals.addSignalMethods(XdndHandler.prototype);
|