window-list: Activate window on hover during drag operations

Reimplement the common task list behavior of activating windows
when hovering over a task list item during a drag operation.

https://bugzilla.gnome.org/show_bug.cgi?id=693561
This commit is contained in:
Florian Müllner
2013-03-23 16:26:17 +01:00
parent e6e31c16b7
commit 91aa1cfbc0

View File

@@ -1,9 +1,11 @@
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const DND = imports.ui.dnd;
const Hash = imports.misc.hash;
const Lang = imports.lang;
const Main = imports.ui.main;
@@ -15,6 +17,7 @@ const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const ICON_TEXTURE_SIZE = 24;
const DND_ACTIVATE_TIMEOUT = 500;
const GroupingMode = {
NEVER: 0,
@@ -434,6 +437,19 @@ const WindowList = new Lang.Class({
this._updateMessageTrayAnchor();
}));
this._dragBeginId =
Main.xdndHandler.connect('drag-begin',
Lang.bind(this, this._onDragBegin));
this._dragEndId =
Main.xdndHandler.connect('drag-end',
Lang.bind(this, this._onDragEnd));
this._dragMonitor = {
dragMotion: Lang.bind(this, this._onDragMotion)
};
this._dndTimeoutId = 0;
this._dndWindow = null;
this._settings = Convenience.getSettings();
this._groupingModeChangedId =
this._settings.connect('changed::grouping-mode',
@@ -564,6 +580,59 @@ const WindowList = new Lang.Class({
}
},
_onDragBegin: function() {
DND.addDragMonitor(this._dragMonitor);
},
_onDragEnd: function() {
DND.removeDragMonitor(this._dragMonitor);
this._removeActivateTimeout();
},
_onDragMotion: function(dragEvent) {
if (Main.overview.visible ||
!this.actor.contains(dragEvent.targetActor)) {
this._removeActivateTimeout();
return DND.DragMotionResult.CONTINUE;
}
let hoveredWindow = null;
if (dragEvent.targetActor._delegate)
hoveredWindow = dragEvent.targetActor._delegate.metaWindow;
if (!hoveredWindow ||
this._dndWindow == hoveredWindow)
return DND.DragMotionResult.CONTINUE;
this._removeActivateTimeout();
this._dndWindow = hoveredWindow;
this._dndTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
DND_ACTIVATE_TIMEOUT,
Lang.bind(this, this._activateWindow));
return DND.DragMotionResult.CONTINUE;
},
_removeActivateTimeout: function() {
if (this._dndTimeoutId)
GLib.source_remove (this._dndTimeoutId);
this._dndTimeoutId = 0;
this._dndWindow = null;
},
_activateWindow: function() {
let [x, y] = global.get_pointer();
let pickedActor = global.stage.get_actor_at_pos(Clutter.PickMode.ALL, x, y);
if (this._dndWindow && this.actor.contains(pickedActor))
this._dndWindow.activate(global.get_current_time());
this._dndWindow = null;
this._dndTimeoutId = 0;
return false;
},
_onDestroy: function() {
Main.ctrlAltTabManager.removeGroup(this.actor);