summaryrefslogtreecommitdiffstats
path: root/js/ui/xdndHandler.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
commitf9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch)
treece9e8db2d4e8799780fa72ae8f1953039373e2ee /js/ui/xdndHandler.js
parentInitial commit. (diff)
downloadgnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.tar.xz
gnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.zip
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/ui/xdndHandler.js')
-rw-r--r--js/ui/xdndHandler.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/js/ui/xdndHandler.js b/js/ui/xdndHandler.js
new file mode 100644
index 0000000..13d012d
--- /dev/null
+++ b/js/ui/xdndHandler.js
@@ -0,0 +1,118 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const { Clutter } = imports.gi;
+const Signals = imports.signals;
+
+const DND = imports.ui.dnd;
+const Main = imports.ui.main;
+
+var XdndHandler = class {
+ constructor() {
+ // 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
+ this._dummy = new Clutter.Actor({ width: 1, height: 1, opacity: 0 });
+ Main.uiGroup.add_actor(this._dummy);
+ this._dummy.hide();
+
+ var dnd = global.backend.get_dnd();
+ 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));
+
+ this._windowGroupVisibilityHandlerId = 0;
+ }
+
+ // Called when the user cancels the drag (i.e release the button)
+ _onLeave() {
+ if (this._windowGroupVisibilityHandlerId != 0) {
+ global.window_group.disconnect(this._windowGroupVisibilityHandlerId);
+ this._windowGroupVisibilityHandlerId = 0;
+ }
+ if (this._cursorWindowClone) {
+ this._cursorWindowClone.destroy();
+ this._cursorWindowClone = null;
+ }
+
+ this.emit('drag-end');
+ }
+
+ _onEnter() {
+ this._windowGroupVisibilityHandlerId =
+ global.window_group.connect('notify::visible',
+ this._onWindowGroupVisibilityChanged.bind(this));
+
+ this.emit('drag-begin', global.get_current_time());
+ }
+
+ _onWindowGroupVisibilityChanged() {
+ 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?
+ if (!cursorWindow.get_meta_window().is_override_redirect())
+ return;
+
+ let constraintPosition = new Clutter.BindConstraint({ coordinate: Clutter.BindCoordinate.POSITION,
+ source: cursorWindow });
+
+ this._cursorWindowClone = new Clutter.Clone({ source: cursorWindow });
+ Main.uiGroup.add_actor(this._cursorWindowClone);
+
+ // Make sure that the clone has the same position as the source
+ this._cursorWindowClone.add_constraint(constraintPosition);
+ } else {
+ if (!this._cursorWindowClone)
+ return;
+
+ this._cursorWindowClone.destroy();
+ this._cursorWindowClone = null;
+ }
+ }
+
+ _onPositionChanged(obj, x, y) {
+ let pickedActor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
+
+ // Make sure that the cursor window is on top
+ if (this._cursorWindowClone)
+ Main.uiGroup.set_child_above_sibling(this._cursorWindowClone, null);
+
+ let dragEvent = {
+ x,
+ 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) {
+ let [r_, targX, targY] = pickedActor.transform_stage_point(x, y);
+ let result = pickedActor._delegate.handleDragOver(this,
+ dragEvent.dragActor,
+ targX,
+ targY,
+ global.get_current_time());
+ if (result != DND.DragMotionResult.CONTINUE)
+ return;
+ }
+ pickedActor = pickedActor.get_parent();
+ }
+ }
+};
+Signals.addSignalMethods(XdndHandler.prototype);