2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
|
2011-01-30 21:18:12 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2012-12-24 09:20:39 -05:00
|
|
|
const Background = imports.ui.background;
|
2011-01-30 21:18:12 -05:00
|
|
|
const DND = imports.ui.dnd;
|
|
|
|
const Main = imports.ui.main;
|
2011-02-09 15:48:11 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2011-01-30 21:18:12 -05:00
|
|
|
const Workspace = imports.ui.workspace;
|
2011-02-09 15:48:11 -05:00
|
|
|
const WorkspacesView = imports.ui.workspacesView;
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-06-01 09:49:46 -04:00
|
|
|
// The maximum size of a thumbnail is 1/10 the width and height of the screen
|
2019-01-28 20:27:05 -05:00
|
|
|
let MAX_THUMBNAIL_SCALE = 1 / 10.;
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var RESCALE_ANIMATION_TIME = 0.2;
|
|
|
|
var SLIDE_ANIMATION_TIME = 0.2;
|
2011-02-11 17:05:35 -05:00
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
// When we create workspaces by dragging, we add a "cut" into the top and
|
|
|
|
// bottom of each workspace so that the user doesn't have to hit the
|
|
|
|
// placeholder exactly.
|
2017-07-18 13:47:27 -04:00
|
|
|
var WORKSPACE_CUT_SIZE = 10;
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var WORKSPACE_KEEP_ALIVE_TIME = 100;
|
2012-02-17 09:57:27 -05:00
|
|
|
|
2018-11-08 04:47:25 -05:00
|
|
|
var MUTTER_SCHEMA = 'org.gnome.mutter';
|
2012-07-24 11:45:07 -04:00
|
|
|
|
2012-11-24 12:49:59 -05:00
|
|
|
/* A layout manager that requests size only for primary_actor, but then allocates
|
|
|
|
all using a fixed layout */
|
2017-10-30 21:23:39 -04:00
|
|
|
var PrimaryActorLayout = GObject.registerClass(
|
|
|
|
class PrimaryActorLayout extends Clutter.FixedLayout {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(primaryActor) {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init();
|
2012-11-24 12:49:59 -05:00
|
|
|
|
|
|
|
this.primaryActor = primaryActor;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2012-11-24 12:49:59 -05:00
|
|
|
return this.primaryActor.get_preferred_width(forHeight);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2012-11-24 12:49:59 -05:00
|
|
|
return this.primaryActor.get_preferred_height(forWidth);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-11-24 12:49:59 -05:00
|
|
|
});
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var WindowClone = class {
|
|
|
|
constructor(realWindow) {
|
2012-11-24 12:49:59 -05:00
|
|
|
this.clone = new Clutter.Clone({ source: realWindow });
|
|
|
|
|
|
|
|
/* Can't use a Shell.GenericContainer because of DND and reparenting... */
|
|
|
|
this.actor = new Clutter.Actor({ layout_manager: new PrimaryActorLayout(this.clone),
|
2011-02-02 22:54:33 -05:00
|
|
|
reactive: true });
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor._delegate = this;
|
2012-11-24 12:49:59 -05:00
|
|
|
this.actor.add_child(this.clone);
|
2011-01-30 21:18:12 -05:00
|
|
|
this.realWindow = realWindow;
|
|
|
|
this.metaWindow = realWindow.meta_window;
|
|
|
|
|
2018-01-19 09:01:16 -05:00
|
|
|
this.clone._updateId = this.realWindow.connect('notify::position',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onPositionChanged.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
this.clone._destroyId = this.realWindow.connect('destroy', () => {
|
2012-11-24 12:49:59 -05:00
|
|
|
// First destroy the clone and then destroy everything
|
|
|
|
// This will ensure that we never see it in the _disconnectSignals loop
|
|
|
|
this.clone.destroy();
|
|
|
|
this.destroy();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-02-02 22:54:33 -05:00
|
|
|
this._onPositionChanged();
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor.connect('button-release-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onButtonRelease.bind(this));
|
2015-10-16 12:12:45 -04:00
|
|
|
this.actor.connect('touch-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onTouchEvent.bind(this));
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
this._draggable = DND.makeDraggable(this.actor,
|
|
|
|
{ restoreOnSuccess: true,
|
|
|
|
dragActorMaxSize: Workspace.WINDOW_DND_SIZE,
|
|
|
|
dragActorOpacity: Workspace.DRAGGING_WINDOW_OPACITY });
|
2017-12-01 19:27:35 -05:00
|
|
|
this._draggable.connect('drag-begin', this._onDragBegin.bind(this));
|
|
|
|
this._draggable.connect('drag-cancelled', this._onDragCancelled.bind(this));
|
|
|
|
this._draggable.connect('drag-end', this._onDragEnd.bind(this));
|
2011-01-30 21:18:12 -05:00
|
|
|
this.inDrag = false;
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let iter = win => {
|
2012-11-24 12:49:59 -05:00
|
|
|
let actor = win.get_compositor_private();
|
|
|
|
|
|
|
|
if (!actor)
|
|
|
|
return false;
|
|
|
|
if (!win.is_attached_dialog())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this._doAddAttachedDialog(win, actor);
|
|
|
|
win.foreach_transient(iter);
|
|
|
|
|
|
|
|
return true;
|
2017-10-30 20:38:18 -04:00
|
|
|
};
|
2012-11-24 12:49:59 -05:00
|
|
|
this.metaWindow.foreach_transient(iter);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2013-01-18 20:22:15 -05:00
|
|
|
// Find the actor just below us, respecting reparenting done
|
|
|
|
// by DND code
|
2017-10-30 20:03:21 -04:00
|
|
|
getActualStackAbove() {
|
2013-01-18 20:22:15 -05:00
|
|
|
if (this._stackAbove == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (this.inDrag) {
|
|
|
|
if (this._stackAbove._delegate)
|
|
|
|
return this._stackAbove._delegate.getActualStackAbove();
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this._stackAbove;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-18 20:22:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setStackAbove(actor) {
|
2011-01-30 21:18:12 -05:00
|
|
|
this._stackAbove = actor;
|
2013-01-18 20:22:15 -05:00
|
|
|
|
|
|
|
// Don't apply the new stacking now, it will be applied
|
|
|
|
// when dragging ends and window are stacked again
|
|
|
|
if (actor.inDrag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let actualAbove = this.getActualStackAbove();
|
|
|
|
if (actualAbove == null)
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor.lower_bottom();
|
|
|
|
else
|
2013-01-18 20:22:15 -05:00
|
|
|
this.actor.raise(actualAbove);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor.destroy();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addAttachedDialog(win) {
|
2012-11-24 12:49:59 -05:00
|
|
|
this._doAddAttachedDialog(win, win.get_compositor_private());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doAddAttachedDialog(metaDialog, realDialog) {
|
2012-11-24 12:49:59 -05:00
|
|
|
let clone = new Clutter.Clone({ source: realDialog });
|
|
|
|
this._updateDialogPosition(realDialog, clone);
|
|
|
|
|
2018-01-19 09:01:16 -05:00
|
|
|
clone._updateId = realDialog.connect('notify::position', dialog => {
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateDialogPosition(dialog, clone);
|
|
|
|
});
|
2017-10-30 20:38:18 -04:00
|
|
|
clone._destroyId = realDialog.connect('destroy', () => {
|
2012-11-24 12:49:59 -05:00
|
|
|
clone.destroy();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2012-11-24 12:49:59 -05:00
|
|
|
this.actor.add_child(clone);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateDialogPosition(realDialog, cloneDialog) {
|
2012-11-24 12:49:59 -05:00
|
|
|
let metaDialog = realDialog.meta_window;
|
2014-09-18 17:02:45 -04:00
|
|
|
let dialogRect = metaDialog.get_frame_rect();
|
|
|
|
let rect = this.metaWindow.get_frame_rect();
|
2012-11-24 12:49:59 -05:00
|
|
|
|
|
|
|
cloneDialog.set_position(dialogRect.x - rect.x, dialogRect.y - rect.y);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPositionChanged() {
|
2011-02-02 22:54:33 -05:00
|
|
|
this.actor.set_position(this.realWindow.x, this.realWindow.y);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-02 22:54:33 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_disconnectSignals() {
|
2017-10-30 20:38:18 -04:00
|
|
|
this.actor.get_children().forEach(child => {
|
2012-11-24 12:49:59 -05:00
|
|
|
let realWindow = child.source;
|
2011-02-02 22:54:33 -05:00
|
|
|
|
2018-01-19 09:01:16 -05:00
|
|
|
realWindow.disconnect(child._updateId);
|
2012-11-24 12:49:59 -05:00
|
|
|
realWindow.disconnect(child._destroyId);
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-02 22:54:33 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy() {
|
2012-11-24 12:49:59 -05:00
|
|
|
this._disconnectSignals();
|
2011-02-02 22:54:33 -05:00
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor._delegate = null;
|
|
|
|
|
|
|
|
if (this.inDrag) {
|
|
|
|
this.emit('drag-end');
|
|
|
|
this.inDrag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.disconnectAll();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onButtonRelease(actor, event) {
|
2011-01-30 21:18:12 -05:00
|
|
|
this.emit('selected', event.get_time());
|
2011-02-09 19:19:35 -05:00
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onTouchEvent(actor, event) {
|
2015-10-16 12:12:45 -04:00
|
|
|
if (event.type() != Clutter.EventType.TOUCH_END ||
|
|
|
|
!global.display.is_pointer_emulating_sequence(event.get_event_sequence()))
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
this.emit('selected', event.get_time());
|
|
|
|
return Clutter.EVENT_STOP;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-10-16 12:12:45 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragBegin(draggable, time) {
|
2011-01-30 21:18:12 -05:00
|
|
|
this.inDrag = true;
|
|
|
|
this.emit('drag-begin');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragCancelled(draggable, time) {
|
2011-12-02 10:54:27 -05:00
|
|
|
this.emit('drag-cancelled');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-12-02 10:54:27 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragEnd(draggable, time, snapback) {
|
2011-01-30 21:18:12 -05:00
|
|
|
this.inDrag = false;
|
|
|
|
|
|
|
|
// We may not have a parent if DnD completed successfully, in
|
|
|
|
// which case our clone will shortly be destroyed and replaced
|
|
|
|
// with a new one on the target workspace.
|
|
|
|
if (this.actor.get_parent() != null) {
|
|
|
|
if (this._stackAbove == null)
|
|
|
|
this.actor.lower_bottom();
|
|
|
|
else
|
|
|
|
this.actor.raise(this._stackAbove);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.emit('drag-end');
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2011-01-30 21:18:12 -05:00
|
|
|
Signals.addSignalMethods(WindowClone.prototype);
|
|
|
|
|
|
|
|
|
2018-06-18 10:38:46 -04:00
|
|
|
var ThumbnailState = {
|
2019-01-28 20:27:05 -05:00
|
|
|
NEW: 0,
|
|
|
|
ANIMATING_IN: 1,
|
2011-02-12 14:40:49 -05:00
|
|
|
NORMAL: 2,
|
2019-01-28 20:27:05 -05:00
|
|
|
REMOVING: 3,
|
|
|
|
ANIMATING_OUT: 4,
|
|
|
|
ANIMATED_OUT: 5,
|
|
|
|
COLLAPSING: 6,
|
|
|
|
DESTROYED: 7
|
2011-02-12 14:40:49 -05:00
|
|
|
};
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
/**
|
|
|
|
* @metaWorkspace: a #Meta.Workspace
|
|
|
|
*/
|
2017-10-30 21:19:44 -04:00
|
|
|
var WorkspaceThumbnail = class {
|
|
|
|
constructor(metaWorkspace) {
|
2011-01-30 21:18:12 -05:00
|
|
|
this.metaWorkspace = metaWorkspace;
|
2011-06-13 09:54:05 -04:00
|
|
|
this.monitorIndex = Main.layoutManager.primaryIndex;
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2012-01-11 17:24:42 -05:00
|
|
|
this._removed = false;
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
this.actor = new St.Widget({ clip_to_allocation: true,
|
2012-02-14 11:33:26 -05:00
|
|
|
style_class: 'workspace-thumbnail' });
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor._delegate = this;
|
|
|
|
|
2013-02-22 06:23:56 -05:00
|
|
|
this._contents = new Clutter.Actor();
|
|
|
|
this.actor.add_child(this._contents);
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2012-12-24 09:20:39 -05:00
|
|
|
this._createBackground();
|
2011-02-13 16:53:15 -05:00
|
|
|
|
2018-01-19 11:37:20 -05:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(this.monitorIndex);
|
|
|
|
this.setPorthole(workArea.x, workArea.y, workArea.width, workArea.height);
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let windows = global.get_window_actors().filter(actor => {
|
2013-02-07 02:26:56 -05:00
|
|
|
let win = actor.meta_window;
|
2013-01-14 12:38:02 -05:00
|
|
|
return win.located_on_workspace(metaWorkspace);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
// Create clones for windows that should be visible in the Overview
|
|
|
|
this._windows = [];
|
2012-01-11 17:59:17 -05:00
|
|
|
this._allWindows = [];
|
|
|
|
this._minimizedChangedIds = [];
|
2011-01-30 21:18:12 -05:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2012-01-11 17:59:17 -05:00
|
|
|
let minimizedChangedId =
|
2011-05-31 12:49:36 -04:00
|
|
|
windows[i].meta_window.connect('notify::minimized',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateMinimized.bind(this));
|
2012-01-11 17:59:17 -05:00
|
|
|
this._allWindows.push(windows[i].meta_window);
|
|
|
|
this._minimizedChangedIds.push(minimizedChangedId);
|
2011-05-31 12:49:36 -04:00
|
|
|
|
2012-01-11 17:59:17 -05:00
|
|
|
if (this._isMyWindow(windows[i]) && this._isOverviewWindow(windows[i])) {
|
2011-01-30 21:18:12 -05:00
|
|
|
this._addWindowClone(windows[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track window changes
|
|
|
|
this._windowAddedId = this.metaWorkspace.connect('window-added',
|
2019-01-29 14:36:54 -05:00
|
|
|
this._windowAdded.bind(this));
|
2011-01-30 21:18:12 -05:00
|
|
|
this._windowRemovedId = this.metaWorkspace.connect('window-removed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._windowRemoved.bind(this));
|
2018-01-03 02:55:38 -05:00
|
|
|
this._windowEnteredMonitorId = global.display.connect('window-entered-monitor',
|
|
|
|
this._windowEnteredMonitor.bind(this));
|
|
|
|
this._windowLeftMonitorId = global.display.connect('window-left-monitor',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._windowLeftMonitor.bind(this));
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
this.state = ThumbnailState.NORMAL;
|
|
|
|
this._slidePosition = 0; // Fully slid in
|
|
|
|
this._collapseFraction = 0; // Not collapsed
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createBackground() {
|
2012-12-24 09:20:39 -05:00
|
|
|
this._bgManager = new Background.BackgroundManager({ monitorIndex: Main.layoutManager.primaryIndex,
|
|
|
|
container: this._contents,
|
2014-08-11 12:15:45 -04:00
|
|
|
vignette: false });
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-24 09:20:39 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setPorthole(x, y, width, height) {
|
2011-02-13 16:53:15 -05:00
|
|
|
this.actor.set_size(width, height);
|
|
|
|
this._contents.set_position(-x, -y);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-13 16:53:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_lookupIndex(metaWindow) {
|
2018-11-19 06:28:29 -05:00
|
|
|
return this._windows.findIndex(w => w.metaWindow == metaWindow);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
syncStacking(stackIndices) {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._windows.sort((a, b) => {
|
|
|
|
let indexA = stackIndices[a.metaWindow.get_stable_sequence()];
|
|
|
|
let indexB = stackIndices[b.metaWindow.get_stable_sequence()];
|
|
|
|
return indexA - indexB;
|
|
|
|
});
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
|
|
|
if (i == 0) {
|
2014-08-11 12:15:45 -04:00
|
|
|
clone.setStackAbove(this._bgManager.backgroundActor);
|
2011-01-30 21:18:12 -05:00
|
|
|
} else {
|
|
|
|
let previousClone = this._windows[i - 1];
|
|
|
|
clone.setStackAbove(previousClone.actor);
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
set slidePosition(slidePosition) {
|
|
|
|
this._slidePosition = slidePosition;
|
|
|
|
this.actor.queue_relayout();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
get slidePosition() {
|
|
|
|
return this._slidePosition;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
set collapseFraction(collapseFraction) {
|
|
|
|
this._collapseFraction = collapseFraction;
|
|
|
|
this.actor.queue_relayout();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
get collapseFraction() {
|
|
|
|
return this._collapseFraction;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doRemoveWindow(metaWin) {
|
2018-07-09 06:19:00 -04:00
|
|
|
let clone = this._removeWindowClone(metaWin);
|
|
|
|
if (clone)
|
|
|
|
clone.destroy();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doAddWindow(metaWin) {
|
2012-01-11 17:24:42 -05:00
|
|
|
if (this._removed)
|
2011-01-30 21:18:12 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
let win = metaWin.get_compositor_private();
|
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
// Newly-created windows are added to a workspace before
|
|
|
|
// the compositor finds out about them...
|
2017-10-30 20:38:18 -04:00
|
|
|
let id = Mainloop.idle_add(() => {
|
|
|
|
if (!this._removed &&
|
|
|
|
metaWin.get_compositor_private() &&
|
|
|
|
metaWin.get_workspace() == this.metaWorkspace)
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(id, '[gnome-shell] this._doAddWindow');
|
2011-01-30 21:18:12 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-14 16:56:22 -04:00
|
|
|
if (!this._allWindows.includes(metaWin)) {
|
2012-01-17 17:50:31 -05:00
|
|
|
let minimizedChangedId = metaWin.connect('notify::minimized',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateMinimized.bind(this));
|
2012-01-17 17:50:31 -05:00
|
|
|
this._allWindows.push(metaWin);
|
|
|
|
this._minimizedChangedIds.push(minimizedChangedId);
|
|
|
|
}
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
// We might have the window in our list already if it was on all workspaces and
|
|
|
|
// now was moved to this workspace
|
2018-11-19 06:28:28 -05:00
|
|
|
if (this._lookupIndex(metaWin) != -1)
|
2011-02-28 14:19:30 -05:00
|
|
|
return;
|
|
|
|
|
2012-11-24 12:49:59 -05:00
|
|
|
if (!this._isMyWindow(win))
|
2011-01-30 21:18:12 -05:00
|
|
|
return;
|
|
|
|
|
2012-11-24 12:49:59 -05:00
|
|
|
if (this._isOverviewWindow(win)) {
|
|
|
|
this._addWindowClone(win);
|
|
|
|
} else if (metaWin.is_attached_dialog()) {
|
|
|
|
let parent = metaWin.get_transient_for();
|
|
|
|
while (parent.is_attached_dialog())
|
2018-07-23 08:22:34 -04:00
|
|
|
parent = parent.get_transient_for();
|
2012-11-24 12:49:59 -05:00
|
|
|
|
2018-11-19 06:28:28 -05:00
|
|
|
let idx = this._lookupIndex(parent);
|
2012-11-24 12:49:59 -05:00
|
|
|
if (idx < 0) {
|
|
|
|
// parent was not created yet, it will take care
|
|
|
|
// of the dialog when created
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let clone = this._windows[idx];
|
|
|
|
clone.addAttachedDialog(metaWin);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_windowAdded(metaWorkspace, metaWin) {
|
2011-02-28 14:19:30 -05:00
|
|
|
this._doAddWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-28 14:19:30 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_windowRemoved(metaWorkspace, metaWin) {
|
2012-01-11 17:59:17 -05:00
|
|
|
let index = this._allWindows.indexOf(metaWin);
|
|
|
|
if (index != -1) {
|
|
|
|
metaWin.disconnect(this._minimizedChangedIds[index]);
|
|
|
|
this._allWindows.splice(index, 1);
|
|
|
|
this._minimizedChangedIds.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
this._doRemoveWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-28 14:19:30 -05:00
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
_windowEnteredMonitor(metaDisplay, monitorIndex, metaWin) {
|
2011-02-28 14:19:30 -05:00
|
|
|
if (monitorIndex == this.monitorIndex) {
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-28 14:19:30 -05:00
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
_windowLeftMonitor(metaDisplay, monitorIndex, metaWin) {
|
2011-02-28 14:19:30 -05:00
|
|
|
if (monitorIndex == this.monitorIndex) {
|
|
|
|
this._doRemoveWindow(metaWin);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-28 14:19:30 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateMinimized(metaWin) {
|
2011-05-31 12:49:36 -04:00
|
|
|
if (metaWin.minimized)
|
|
|
|
this._doRemoveWindow(metaWin);
|
|
|
|
else
|
|
|
|
this._doAddWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-05-31 12:49:36 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2013-03-25 11:31:56 -04:00
|
|
|
if (this.actor)
|
2019-01-29 14:36:54 -05:00
|
|
|
this.actor.destroy();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
workspaceRemoved() {
|
2012-01-11 17:24:42 -05:00
|
|
|
if (this._removed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._removed = true;
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this.metaWorkspace.disconnect(this._windowAddedId);
|
|
|
|
this.metaWorkspace.disconnect(this._windowRemovedId);
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.disconnect(this._windowEnteredMonitorId);
|
|
|
|
global.display.disconnect(this._windowLeftMonitorId);
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2012-01-11 17:59:17 -05:00
|
|
|
for (let i = 0; i < this._allWindows.length; i++)
|
|
|
|
this._allWindows[i].disconnect(this._minimizedChangedIds[i]);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-01-11 17:24:42 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy(actor) {
|
2012-01-11 17:24:42 -05:00
|
|
|
this.workspaceRemoved();
|
2011-05-31 12:49:36 -04:00
|
|
|
|
2013-03-25 11:31:56 -04:00
|
|
|
if (this._bgManager) {
|
2019-01-29 14:36:54 -05:00
|
|
|
this._bgManager.destroy();
|
|
|
|
this._bgManager = null;
|
2013-03-25 11:31:56 -04:00
|
|
|
}
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this._windows = [];
|
|
|
|
this.actor = null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2013-01-14 12:38:02 -05:00
|
|
|
// Tests if @actor belongs to this workspace and monitor
|
2017-10-30 20:03:21 -04:00
|
|
|
_isMyWindow(actor) {
|
2013-01-14 12:38:02 -05:00
|
|
|
let win = actor.meta_window;
|
|
|
|
return win.located_on_workspace(this.metaWorkspace) &&
|
2013-01-14 12:38:02 -05:00
|
|
|
(win.get_monitor() == this.monitorIndex);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
// Tests if @win should be shown in the Overview
|
2017-10-30 20:03:21 -04:00
|
|
|
_isOverviewWindow(win) {
|
2014-01-30 12:04:18 -05:00
|
|
|
return !win.get_meta_window().skip_taskbar &&
|
2011-05-31 12:49:36 -04:00
|
|
|
win.get_meta_window().showing_on_its_workspace();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
// Create a clone of a (non-desktop) window and add it to the window list
|
2017-10-30 20:03:21 -04:00
|
|
|
_addWindowClone(win) {
|
2011-01-30 21:18:12 -05:00
|
|
|
let clone = new WindowClone(win);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
clone.connect('selected', (clone, time) => {
|
|
|
|
this.activate(time);
|
|
|
|
});
|
|
|
|
clone.connect('drag-begin', () => {
|
|
|
|
Main.overview.beginWindowDrag(clone.metaWindow);
|
|
|
|
});
|
|
|
|
clone.connect('drag-cancelled', () => {
|
|
|
|
Main.overview.cancelledWindowDrag(clone.metaWindow);
|
|
|
|
});
|
|
|
|
clone.connect('drag-end', () => {
|
|
|
|
Main.overview.endWindowDrag(clone.metaWindow);
|
|
|
|
});
|
2018-07-09 06:19:00 -04:00
|
|
|
clone.actor.connect('destroy', () => {
|
|
|
|
this._removeWindowClone(clone.metaWindow);
|
|
|
|
});
|
2011-02-13 16:53:15 -05:00
|
|
|
this._contents.add_actor(clone.actor);
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2011-02-14 16:09:10 -05:00
|
|
|
if (this._windows.length == 0)
|
2014-08-11 12:15:45 -04:00
|
|
|
clone.setStackAbove(this._bgManager.backgroundActor);
|
2011-02-14 16:09:10 -05:00
|
|
|
else
|
|
|
|
clone.setStackAbove(this._windows[this._windows.length - 1].actor);
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this._windows.push(clone);
|
|
|
|
|
|
|
|
return clone;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2018-07-09 06:19:00 -04:00
|
|
|
_removeWindowClone(metaWin) {
|
|
|
|
// find the position of the window in our list
|
2018-11-19 06:28:28 -05:00
|
|
|
let index = this._lookupIndex(metaWin);
|
2018-07-09 06:19:00 -04:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return this._windows.splice(index, 1).pop();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-09 06:19:00 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activate(time) {
|
2011-02-14 17:09:04 -05:00
|
|
|
if (this.state > ThumbnailState.NORMAL)
|
|
|
|
return;
|
|
|
|
|
2011-02-09 17:43:09 -05:00
|
|
|
// a click on the already current workspace should go back to the main view
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let activeWorkspace = workspaceManager.get_active_workspace();
|
|
|
|
if (this.metaWorkspace == activeWorkspace)
|
2011-02-09 17:43:09 -05:00
|
|
|
Main.overview.hide();
|
|
|
|
else
|
|
|
|
this.metaWorkspace.activate(time);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
// Draggable target interface used only by ThumbnailsBox
|
2017-10-30 20:03:21 -04:00
|
|
|
handleDragOverInternal(source, time) {
|
2011-03-21 18:20:36 -04:00
|
|
|
if (source == Main.xdndHandler) {
|
|
|
|
this.metaWorkspace.activate(time);
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
2011-02-14 17:09:04 -05:00
|
|
|
if (this.state > ThumbnailState.NORMAL)
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
|
2011-02-14 17:13:25 -05:00
|
|
|
if (source.realWindow && !this._isMyWindow(source.realWindow))
|
2011-01-30 21:18:12 -05:00
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
|
|
|
if (source.shellWorkspaceLaunch)
|
|
|
|
return DND.DragMotionResult.COPY_DROP;
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
acceptDropInternal(source, time) {
|
2011-02-14 17:09:04 -05:00
|
|
|
if (this.state > ThumbnailState.NORMAL)
|
|
|
|
return false;
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
if (source.realWindow) {
|
|
|
|
let win = source.realWindow;
|
|
|
|
if (this._isMyWindow(win))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let metaWindow = win.get_meta_window();
|
2011-02-28 14:19:30 -05:00
|
|
|
|
|
|
|
// We need to move the window before changing the workspace, because
|
|
|
|
// the move itself could cause a workspace change if the window enters
|
|
|
|
// the primary monitor
|
|
|
|
if (metaWindow.get_monitor() != this.monitorIndex)
|
2011-03-17 13:48:09 -04:00
|
|
|
metaWindow.move_to_monitor(this.monitorIndex);
|
2011-02-28 14:19:30 -05:00
|
|
|
|
2013-10-09 18:10:01 -04:00
|
|
|
metaWindow.change_workspace_by_index(this.metaWorkspace.index(), false);
|
2011-01-30 21:18:12 -05:00
|
|
|
return true;
|
|
|
|
} else if (source.shellWorkspaceLaunch) {
|
2011-08-11 05:35:23 -04:00
|
|
|
source.shellWorkspaceLaunch({ workspace: this.metaWorkspace ? this.metaWorkspace.index() : -1,
|
2011-01-30 16:09:58 -05:00
|
|
|
timestamp: time });
|
2011-01-30 21:18:12 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2011-01-30 21:18:12 -05:00
|
|
|
Signals.addSignalMethods(WorkspaceThumbnail.prototype);
|
2011-02-09 15:48:11 -05:00
|
|
|
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var ThumbnailsBox = GObject.registerClass(
|
|
|
|
class ThumbnailsBox extends St.Widget {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init({ reactive: true,
|
2018-07-06 04:01:39 -04:00
|
|
|
style_class: 'workspace-thumbnails',
|
|
|
|
request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
|
|
|
|
|
2019-04-09 19:26:39 -04:00
|
|
|
this._delegate = this;
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-02-12 16:33:42 -05:00
|
|
|
let indicator = new St.Bin({ style_class: 'workspace-thumbnail-indicator' });
|
2011-02-09 15:48:11 -05:00
|
|
|
|
|
|
|
// We don't want the indicator to affect drag-and-drop
|
|
|
|
Shell.util_set_hidden_from_pick(indicator, true);
|
|
|
|
|
|
|
|
this._indicator = indicator;
|
2018-07-06 04:01:39 -04:00
|
|
|
this.add_actor(indicator);
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2019-01-11 17:50:09 -05:00
|
|
|
// The porthole is the part of the screen we're showing in the thumbnails
|
|
|
|
this._porthole = { width: global.stage.width, height: global.stage.height,
|
|
|
|
x: global.stage.x, y: global.stage.y };
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
this._dropWorkspace = -1;
|
2011-05-04 22:47:07 -04:00
|
|
|
this._dropPlaceholderPos = -1;
|
|
|
|
this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' });
|
2018-07-06 04:01:39 -04:00
|
|
|
this.add_actor(this._dropPlaceholder);
|
2012-12-16 17:52:33 -05:00
|
|
|
this._spliceIndex = -1;
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
this._targetScale = 0;
|
|
|
|
this._scale = 0;
|
2011-02-12 14:40:49 -05:00
|
|
|
this._pendingScaleUpdate = false;
|
|
|
|
this._stateUpdateQueued = false;
|
2011-02-12 16:14:12 -05:00
|
|
|
this._animatingIndicator = false;
|
2011-02-12 16:33:42 -05:00
|
|
|
this._indicatorY = 0; // only used when _animatingIndicator is true
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
this._stateCounts = {};
|
2011-02-24 12:17:05 -05:00
|
|
|
for (let key in ThumbnailState)
|
2011-02-12 14:40:49 -05:00
|
|
|
this._stateCounts[ThumbnailState[key]] = 0;
|
2011-02-09 15:48:11 -05:00
|
|
|
|
|
|
|
this._thumbnails = [];
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
this.connect('button-press-event', () => Clutter.EVENT_STOP);
|
|
|
|
this.connect('button-release-event', this._onButtonRelease.bind(this));
|
|
|
|
this.connect('touch-event', this._onTouchEvent.bind(this));
|
2012-02-10 12:59:05 -05:00
|
|
|
|
2012-12-13 10:39:52 -05:00
|
|
|
Main.overview.connect('showing',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._createThumbnails.bind(this));
|
2012-12-13 10:39:52 -05:00
|
|
|
Main.overview.connect('hidden',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._destroyThumbnails.bind(this));
|
2012-12-13 10:39:52 -05:00
|
|
|
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('item-drag-begin',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onDragBegin.bind(this));
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('item-drag-end',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onDragEnd.bind(this));
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('item-drag-cancelled',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onDragCancelled.bind(this));
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('window-drag-begin',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onDragBegin.bind(this));
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('window-drag-end',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onDragEnd.bind(this));
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('window-drag-cancelled',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onDragCancelled.bind(this));
|
2012-07-24 11:45:07 -04:00
|
|
|
|
2018-11-08 04:47:25 -05:00
|
|
|
this._settings = new Gio.Settings({ schema_id: MUTTER_SCHEMA });
|
2012-07-24 11:45:07 -04:00
|
|
|
this._settings.connect('changed::dynamic-workspaces',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateSwitcherVisibility.bind(this));
|
2017-06-09 06:26:11 -04:00
|
|
|
|
2018-07-20 11:27:33 -04:00
|
|
|
Main.layoutManager.connect('monitors-changed', () => {
|
|
|
|
this._destroyThumbnails();
|
|
|
|
if (Main.overview.visible)
|
|
|
|
this._createThumbnails();
|
|
|
|
});
|
2018-04-25 16:03:16 -04:00
|
|
|
|
2019-01-11 17:50:09 -05:00
|
|
|
global.display.connect('workareas-changed',
|
|
|
|
this._updatePorthole.bind(this));
|
|
|
|
|
2018-04-25 16:03:16 -04:00
|
|
|
this._switchWorkspaceNotifyId = 0;
|
|
|
|
this._nWorkspacesNotifyId = 0;
|
|
|
|
this._syncStackingId = 0;
|
|
|
|
this._workareasChangedId = 0;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-07-24 11:45:07 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSwitcherVisibility() {
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
this.visible =
|
2012-07-24 11:45:07 -04:00
|
|
|
this._settings.get_boolean('dynamic-workspaces') ||
|
2018-01-03 02:55:38 -05:00
|
|
|
workspaceManager.n_workspaces > 1;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_activateThumbnailAtPoint(stageX, stageY, time) {
|
2018-07-06 04:01:39 -04:00
|
|
|
let [r, x, y] = this.transform_stage_point(stageX, stageY);
|
2012-02-10 12:59:05 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < this._thumbnails.length; i++) {
|
2019-01-28 20:18:52 -05:00
|
|
|
let thumbnail = this._thumbnails[i];
|
2012-02-10 12:59:05 -05:00
|
|
|
let [w, h] = thumbnail.actor.get_transformed_size();
|
|
|
|
if (y >= thumbnail.actor.y && y <= thumbnail.actor.y + h) {
|
2015-10-16 12:27:09 -04:00
|
|
|
thumbnail.activate(time);
|
2012-02-10 12:59:05 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2015-10-16 12:27:09 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onButtonRelease(actor, event) {
|
2015-10-16 12:27:09 -04:00
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
this._activateThumbnailAtPoint(stageX, stageY, event.get_time());
|
|
|
|
return Clutter.EVENT_STOP;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2015-10-16 12:27:09 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onTouchEvent(actor, event) {
|
2015-10-16 12:27:09 -04:00
|
|
|
if (event.type() == Clutter.EventType.TOUCH_END &&
|
|
|
|
global.display.is_pointer_emulating_sequence(event.get_event_sequence())) {
|
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
this._activateThumbnailAtPoint(stageX, stageY, event.get_time());
|
|
|
|
}
|
2012-02-10 12:59:05 -05:00
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-02-10 12:59:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragBegin() {
|
2011-11-27 10:23:17 -05:00
|
|
|
this._dragCancelled = false;
|
|
|
|
this._dragMonitor = {
|
2017-12-01 19:27:35 -05:00
|
|
|
dragMotion: this._onDragMotion.bind(this)
|
2011-11-27 10:23:17 -05:00
|
|
|
};
|
|
|
|
DND.addDragMonitor(this._dragMonitor);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragEnd() {
|
2011-11-27 10:23:17 -05:00
|
|
|
if (this._dragCancelled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._endDrag();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragCancelled() {
|
2011-11-27 10:23:17 -05:00
|
|
|
this._dragCancelled = true;
|
|
|
|
this._endDrag();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_endDrag() {
|
2011-11-27 10:23:17 -05:00
|
|
|
this._clearDragPlaceholder();
|
|
|
|
DND.removeDragMonitor(this._dragMonitor);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDragMotion(dragEvent) {
|
2018-07-06 04:01:39 -04:00
|
|
|
if (!this.contains(dragEvent.targetActor))
|
2011-11-27 10:23:17 -05:00
|
|
|
this._onLeave();
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onLeave() {
|
2011-11-27 10:23:17 -05:00
|
|
|
this._clearDragPlaceholder();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-11-27 10:23:17 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearDragPlaceholder() {
|
2012-02-21 14:46:27 -05:00
|
|
|
if (this._dropPlaceholderPos == -1)
|
|
|
|
return;
|
|
|
|
|
2011-11-27 10:23:17 -05:00
|
|
|
this._dropPlaceholderPos = -1;
|
2018-07-06 04:01:39 -04:00
|
|
|
this.queue_relayout();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
// Draggable target interface
|
2017-10-30 20:03:21 -04:00
|
|
|
handleDragOver(source, actor, x, y, time) {
|
2012-02-10 12:59:05 -05:00
|
|
|
if (!source.realWindow && !source.shellWorkspaceLaunch && source != Main.xdndHandler)
|
2011-05-04 22:47:07 -04:00
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
|
2012-09-22 18:57:57 -04:00
|
|
|
let canCreateWorkspaces = Meta.prefs_get_dynamic_workspaces();
|
2018-07-06 04:01:39 -04:00
|
|
|
let spacing = this.get_theme_node().get_length('spacing');
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
this._dropWorkspace = -1;
|
|
|
|
let placeholderPos = -1;
|
|
|
|
let targetBase;
|
2011-11-23 05:00:30 -05:00
|
|
|
if (this._dropPlaceholderPos == 0)
|
2012-02-10 12:59:05 -05:00
|
|
|
targetBase = this._dropPlaceholder.y;
|
2011-11-23 05:00:30 -05:00
|
|
|
else
|
2012-02-10 12:59:05 -05:00
|
|
|
targetBase = this._thumbnails[0].actor.y;
|
|
|
|
let targetTop = targetBase - spacing - WORKSPACE_CUT_SIZE;
|
|
|
|
let length = this._thumbnails.length;
|
|
|
|
for (let i = 0; i < length; i ++) {
|
2011-05-04 22:47:07 -04:00
|
|
|
// Allow the reorder target to have a 10px "cut" into
|
|
|
|
// each side of the thumbnail, to make dragging onto the
|
|
|
|
// placeholder easier
|
2012-02-10 12:59:05 -05:00
|
|
|
let [w, h] = this._thumbnails[i].actor.get_transformed_size();
|
2011-05-04 22:47:07 -04:00
|
|
|
let targetBottom = targetBase + WORKSPACE_CUT_SIZE;
|
2012-02-10 12:59:05 -05:00
|
|
|
let nextTargetBase = targetBase + h + spacing;
|
2019-01-28 20:27:05 -05:00
|
|
|
let nextTargetTop = nextTargetBase - spacing - ((i == length - 1) ? 0 : WORKSPACE_CUT_SIZE);
|
2011-05-04 22:47:07 -04:00
|
|
|
|
|
|
|
// Expand the target to include the placeholder, if it exists.
|
|
|
|
if (i == this._dropPlaceholderPos)
|
|
|
|
targetBottom += this._dropPlaceholder.get_height();
|
|
|
|
|
2012-09-22 18:57:57 -04:00
|
|
|
if (y > targetTop && y <= targetBottom && source != Main.xdndHandler && canCreateWorkspaces) {
|
2012-02-10 12:59:05 -05:00
|
|
|
placeholderPos = i;
|
2011-05-04 22:47:07 -04:00
|
|
|
break;
|
2012-02-10 12:59:05 -05:00
|
|
|
} else if (y > targetBottom && y <= nextTargetTop) {
|
|
|
|
this._dropWorkspace = i;
|
2019-01-28 20:18:52 -05:00
|
|
|
break;
|
2011-05-04 22:47:07 -04:00
|
|
|
}
|
2012-02-10 12:59:05 -05:00
|
|
|
|
|
|
|
targetBase = nextTargetBase;
|
|
|
|
targetTop = nextTargetTop;
|
2011-05-04 22:47:07 -04:00
|
|
|
}
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
if (this._dropPlaceholderPos != placeholderPos) {
|
|
|
|
this._dropPlaceholderPos = placeholderPos;
|
2018-07-06 04:01:39 -04:00
|
|
|
this.queue_relayout();
|
2012-02-21 14:46:27 -05:00
|
|
|
}
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
if (this._dropWorkspace != -1)
|
|
|
|
return this._thumbnails[this._dropWorkspace].handleDragOverInternal(source, time);
|
|
|
|
else if (this._dropPlaceholderPos != -1)
|
2012-03-22 13:48:50 -04:00
|
|
|
return source.realWindow ? DND.DragMotionResult.MOVE_DROP : DND.DragMotionResult.COPY_DROP;
|
2012-02-10 12:59:05 -05:00
|
|
|
else
|
2011-05-04 22:47:07 -04:00
|
|
|
return DND.DragMotionResult.CONTINUE;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
acceptDrop(source, actor, x, y, time) {
|
2012-02-10 12:59:05 -05:00
|
|
|
if (this._dropWorkspace != -1) {
|
|
|
|
return this._thumbnails[this._dropWorkspace].acceptDropInternal(source, time);
|
|
|
|
} else if (this._dropPlaceholderPos != -1) {
|
|
|
|
if (!source.realWindow && !source.shellWorkspaceLaunch)
|
|
|
|
return false;
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
let isWindow = !!source.realWindow;
|
|
|
|
|
|
|
|
let newWorkspaceIndex;
|
|
|
|
[newWorkspaceIndex, this._dropPlaceholderPos] = [this._dropPlaceholderPos, -1];
|
2012-12-16 17:52:33 -05:00
|
|
|
this._spliceIndex = newWorkspaceIndex;
|
|
|
|
|
2015-01-15 17:03:24 -05:00
|
|
|
Main.wm.insertWorkspace(newWorkspaceIndex);
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2014-04-26 10:17:24 -04:00
|
|
|
if (isWindow) {
|
|
|
|
// Move the window to our monitor first if necessary.
|
|
|
|
let thumbMonitor = this._thumbnails[newWorkspaceIndex].monitorIndex;
|
|
|
|
if (source.metaWindow.get_monitor() != thumbMonitor)
|
|
|
|
source.metaWindow.move_to_monitor(thumbMonitor);
|
2013-10-09 18:10:01 -04:00
|
|
|
source.metaWindow.change_workspace_by_index(newWorkspaceIndex, true);
|
2014-04-26 10:17:24 -04:00
|
|
|
} else if (source.shellWorkspaceLaunch) {
|
2012-02-10 12:59:05 -05:00
|
|
|
source.shellWorkspaceLaunch({ workspace: newWorkspaceIndex,
|
|
|
|
timestamp: time });
|
|
|
|
// This new workspace will be automatically removed if the application fails
|
|
|
|
// to open its first window within some time, as tracked by Shell.WindowTracker.
|
|
|
|
// Here, we only add a very brief timeout to avoid the _immediate_ removal of the
|
|
|
|
// workspace while we wait for the startup sequence to load.
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
Main.wm.keepWorkspaceAlive(workspaceManager.get_workspace_by_index(newWorkspaceIndex),
|
2013-06-16 00:12:22 -04:00
|
|
|
WORKSPACE_KEEP_ALIVE_TIME);
|
2012-02-10 12:59:05 -05:00
|
|
|
}
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-12-16 17:52:33 -05:00
|
|
|
// Start the animation on the workspace (which is actually
|
|
|
|
// an old one which just became empty)
|
|
|
|
let thumbnail = this._thumbnails[newWorkspaceIndex];
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.NEW);
|
|
|
|
thumbnail.slidePosition = 1;
|
|
|
|
|
|
|
|
this._queueUpdateStates();
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createThumbnails() {
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
|
2011-02-09 15:48:11 -05:00
|
|
|
this._switchWorkspaceNotifyId =
|
|
|
|
global.window_manager.connect('switch-workspace',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._activeWorkspaceChanged.bind(this));
|
2012-07-24 11:45:07 -04:00
|
|
|
this._nWorkspacesNotifyId =
|
2018-01-03 02:55:38 -05:00
|
|
|
workspaceManager.connect('notify::n-workspaces',
|
|
|
|
this._workspacesChanged.bind(this));
|
2012-12-13 11:00:30 -05:00
|
|
|
this._syncStackingId =
|
|
|
|
Main.overview.connect('windows-restacked',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._syncStacking.bind(this));
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
this._targetScale = 0;
|
|
|
|
this._scale = 0;
|
2011-02-12 14:40:49 -05:00
|
|
|
this._pendingScaleUpdate = false;
|
|
|
|
this._stateUpdateQueued = false;
|
|
|
|
|
|
|
|
this._stateCounts = {};
|
2011-02-24 12:17:05 -05:00
|
|
|
for (let key in ThumbnailState)
|
2011-02-12 14:40:49 -05:00
|
|
|
this._stateCounts[ThumbnailState[key]] = 0;
|
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
this.addThumbnails(0, workspaceManager.n_workspaces);
|
2012-07-24 11:45:07 -04:00
|
|
|
|
|
|
|
this._updateSwitcherVisibility();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_destroyThumbnails() {
|
2017-09-19 21:05:16 -04:00
|
|
|
if (this._thumbnails.length == 0)
|
|
|
|
return;
|
|
|
|
|
2011-02-09 15:48:11 -05:00
|
|
|
if (this._switchWorkspaceNotifyId > 0) {
|
|
|
|
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
|
|
|
|
this._switchWorkspaceNotifyId = 0;
|
|
|
|
}
|
2012-07-24 11:45:07 -04:00
|
|
|
if (this._nWorkspacesNotifyId > 0) {
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
workspaceManager.disconnect(this._nWorkspacesNotifyId);
|
2012-07-24 11:45:07 -04:00
|
|
|
this._nWorkspacesNotifyId = 0;
|
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2012-12-13 11:00:30 -05:00
|
|
|
if (this._syncStackingId > 0) {
|
|
|
|
Main.overview.disconnect(this._syncStackingId);
|
|
|
|
this._syncStackingId = 0;
|
|
|
|
}
|
|
|
|
|
2011-02-09 15:48:11 -05:00
|
|
|
for (let w = 0; w < this._thumbnails.length; w++)
|
|
|
|
this._thumbnails[w].destroy();
|
|
|
|
this._thumbnails = [];
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_workspacesChanged() {
|
2017-10-30 20:38:18 -04:00
|
|
|
let validThumbnails =
|
|
|
|
this._thumbnails.filter(t => t.state <= ThumbnailState.NORMAL);
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
2014-04-24 19:56:31 -04:00
|
|
|
let oldNumWorkspaces = validThumbnails.length;
|
2018-01-03 02:55:38 -05:00
|
|
|
let newNumWorkspaces = workspaceManager.n_workspaces;
|
2012-07-24 11:45:07 -04:00
|
|
|
|
|
|
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
|
|
|
this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
|
|
|
|
} else {
|
|
|
|
let removedIndex;
|
|
|
|
let removedNum = oldNumWorkspaces - newNumWorkspaces;
|
|
|
|
for (let w = 0; w < oldNumWorkspaces; w++) {
|
2018-01-03 02:55:38 -05:00
|
|
|
let metaWorkspace = workspaceManager.get_workspace_by_index(w);
|
2012-07-24 11:45:07 -04:00
|
|
|
if (this._thumbnails[w].metaWorkspace != metaWorkspace) {
|
|
|
|
removedIndex = w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.removeThumbnails(removedIndex, removedNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._updateSwitcherVisibility();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-07-24 11:45:07 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addThumbnails(start, count) {
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
|
2011-02-09 15:48:11 -05:00
|
|
|
for (let k = start; k < start + count; k++) {
|
2018-01-03 02:55:38 -05:00
|
|
|
let metaWorkspace = workspaceManager.get_workspace_by_index(k);
|
2011-02-09 15:48:11 -05:00
|
|
|
let thumbnail = new WorkspaceThumbnail(metaWorkspace);
|
2011-02-13 16:53:15 -05:00
|
|
|
thumbnail.setPorthole(this._porthole.x, this._porthole.y,
|
|
|
|
this._porthole.width, this._porthole.height);
|
2011-02-12 14:40:49 -05:00
|
|
|
this._thumbnails.push(thumbnail);
|
2018-07-06 04:01:39 -04:00
|
|
|
this.add_actor(thumbnail.actor);
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2012-12-16 17:52:33 -05:00
|
|
|
if (start > 0 && this._spliceIndex == -1) {
|
|
|
|
// not the initial fill, and not splicing via DND
|
2011-02-12 14:40:49 -05:00
|
|
|
thumbnail.state = ThumbnailState.NEW;
|
|
|
|
thumbnail.slidePosition = 1; // start slid out
|
|
|
|
this._haveNewThumbnails = true;
|
|
|
|
} else {
|
|
|
|
thumbnail.state = ThumbnailState.NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._stateCounts[thumbnail.state]++;
|
2011-02-09 15:48:11 -05:00
|
|
|
}
|
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
this._queueUpdateStates();
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
// The thumbnails indicator actually needs to be on top of the thumbnails
|
2011-02-09 15:48:11 -05:00
|
|
|
this._indicator.raise_top();
|
2012-12-16 17:52:33 -05:00
|
|
|
|
|
|
|
// Clear the splice index, we got the message
|
|
|
|
this._spliceIndex = -1;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
removeThumbnails(start, count) {
|
2011-02-12 14:40:49 -05:00
|
|
|
let currentPos = 0;
|
|
|
|
for (let k = 0; k < this._thumbnails.length; k++) {
|
|
|
|
let thumbnail = this._thumbnails[k];
|
|
|
|
|
|
|
|
if (thumbnail.state > ThumbnailState.NORMAL)
|
|
|
|
continue;
|
|
|
|
|
2012-01-17 17:50:31 -05:00
|
|
|
if (currentPos >= start && currentPos < start + count) {
|
|
|
|
thumbnail.workspaceRemoved();
|
2011-02-12 14:40:49 -05:00
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.REMOVING);
|
2012-01-17 17:50:31 -05:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
currentPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._queueUpdateStates();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_syncStacking(overview, stackIndices) {
|
2011-02-09 15:48:11 -05:00
|
|
|
for (let i = 0; i < this._thumbnails.length; i++)
|
|
|
|
this._thumbnails[i].syncStacking(stackIndices);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
set scale(scale) {
|
|
|
|
this._scale = scale;
|
2018-07-06 04:01:39 -04:00
|
|
|
this.queue_relayout();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-11 17:05:35 -05:00
|
|
|
|
|
|
|
get scale() {
|
|
|
|
return this._scale;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-11 17:05:35 -05:00
|
|
|
|
2011-02-12 16:33:42 -05:00
|
|
|
set indicatorY(indicatorY) {
|
|
|
|
this._indicatorY = indicatorY;
|
2018-07-06 04:01:39 -04:00
|
|
|
this.queue_relayout();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 16:33:42 -05:00
|
|
|
|
|
|
|
get indicatorY() {
|
|
|
|
return this._indicatorY;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 16:33:42 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setThumbnailState(thumbnail, state) {
|
2011-02-12 14:40:49 -05:00
|
|
|
this._stateCounts[thumbnail.state]--;
|
|
|
|
thumbnail.state = state;
|
|
|
|
this._stateCounts[thumbnail.state]++;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_iterateStateThumbnails(state, callback) {
|
2011-02-12 14:40:49 -05:00
|
|
|
if (this._stateCounts[state] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._thumbnails.length; i++) {
|
|
|
|
if (this._thumbnails[i].state == state)
|
|
|
|
callback.call(this, this._thumbnails[i]);
|
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_tweenScale() {
|
2011-02-12 14:40:49 -05:00
|
|
|
Tweener.addTween(this,
|
|
|
|
{ scale: this._targetScale,
|
|
|
|
time: RESCALE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: this._queueUpdateStates,
|
|
|
|
onCompleteScope: this });
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateStates() {
|
2011-02-12 14:40:49 -05:00
|
|
|
this._stateUpdateQueued = false;
|
|
|
|
|
2011-02-12 16:14:12 -05:00
|
|
|
// If we are animating the indicator, wait
|
|
|
|
if (this._animatingIndicator)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Then slide out any thumbnails that have been destroyed
|
2017-10-30 20:38:18 -04:00
|
|
|
this._iterateStateThumbnails(ThumbnailState.REMOVING, thumbnail => {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_OUT);
|
|
|
|
|
|
|
|
Tweener.addTween(thumbnail,
|
|
|
|
{ slidePosition: 1,
|
|
|
|
time: SLIDE_ANIMATION_TIME,
|
|
|
|
transition: 'linear',
|
|
|
|
onComplete: () => {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATED_OUT);
|
|
|
|
this._queueUpdateStates();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
// As long as things are sliding out, don't proceed
|
|
|
|
if (this._stateCounts[ThumbnailState.ANIMATING_OUT] > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Once that's complete, we can start scaling to the new size and collapse any removed thumbnails
|
2017-10-30 20:38:18 -04:00
|
|
|
this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT, thumbnail => {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING);
|
|
|
|
Tweener.addTween(thumbnail,
|
|
|
|
{ collapseFraction: 1,
|
|
|
|
time: RESCALE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: () => {
|
|
|
|
this._stateCounts[thumbnail.state]--;
|
|
|
|
thumbnail.state = ThumbnailState.DESTROYED;
|
|
|
|
|
|
|
|
let index = this._thumbnails.indexOf(thumbnail);
|
|
|
|
this._thumbnails.splice(index, 1);
|
|
|
|
thumbnail.destroy();
|
|
|
|
|
|
|
|
this._queueUpdateStates();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
if (this._pendingScaleUpdate) {
|
|
|
|
this._tweenScale();
|
|
|
|
this._pendingScaleUpdate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until that's done
|
|
|
|
if (this._scale != this._targetScale || this._stateCounts[ThumbnailState.COLLAPSING] > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// And then slide in any new thumbnails
|
2017-10-30 20:38:18 -04:00
|
|
|
this._iterateStateThumbnails(ThumbnailState.NEW, thumbnail => {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_IN);
|
|
|
|
Tweener.addTween(thumbnail,
|
|
|
|
{ slidePosition: 0,
|
|
|
|
time: SLIDE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: () => {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.NORMAL);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_queueUpdateStates() {
|
2011-02-12 14:40:49 -05:00
|
|
|
if (this._stateUpdateQueued)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateStates.bind(this));
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
this._stateUpdateQueued = true;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
vfunc_get_preferred_height(forWidth) {
|
2011-02-11 12:09:23 -05:00
|
|
|
// Note that for getPreferredWidth/Height we cheat a bit and skip propagating
|
|
|
|
// the size request to our children because we know how big they are and know
|
|
|
|
// that the actors aren't depending on the virtual functions being called.
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
2018-07-06 04:01:39 -04:00
|
|
|
let themeNode = this.get_theme_node();
|
|
|
|
|
2013-10-11 21:27:59 -04:00
|
|
|
let spacing = themeNode.get_length('spacing');
|
2018-01-03 02:55:38 -05:00
|
|
|
let nWorkspaces = workspaceManager.n_workspaces;
|
2011-02-12 14:40:49 -05:00
|
|
|
let totalSpacing = (nWorkspaces - 1) * spacing;
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
let naturalHeight = totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE;
|
|
|
|
|
|
|
|
return themeNode.adjust_preferred_height(totalSpacing, naturalHeight);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
vfunc_get_preferred_width(forHeight) {
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
2018-07-06 04:01:39 -04:00
|
|
|
let themeNode = this.get_theme_node();
|
|
|
|
|
|
|
|
forHeight = themeNode.adjust_for_height(forHeight);
|
2011-02-12 14:40:49 -05:00
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
let spacing = themeNode.get_length('spacing');
|
2018-01-03 02:55:38 -05:00
|
|
|
let nWorkspaces = workspaceManager.n_workspaces;
|
2011-02-12 14:40:49 -05:00
|
|
|
let totalSpacing = (nWorkspaces - 1) * spacing;
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
let avail = forHeight - totalSpacing;
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
let scale = (avail / nWorkspaces) / this._porthole.height;
|
2011-02-11 12:09:23 -05:00
|
|
|
scale = Math.min(scale, MAX_THUMBNAIL_SCALE);
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
let width = Math.round(this._porthole.width * scale);
|
2018-07-06 04:01:39 -04:00
|
|
|
|
|
|
|
return themeNode.adjust_preferred_width(width, width);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2019-01-11 17:50:09 -05:00
|
|
|
_updatePorthole() {
|
|
|
|
if (!Main.layoutManager.primaryMonitor)
|
|
|
|
this._porthole = { width: global.stage.width, height: global.stage.height,
|
|
|
|
x: global.stage.x, y: global.stage.y };
|
|
|
|
else
|
2014-07-31 11:35:27 -04:00
|
|
|
this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
2017-04-12 02:46:54 -04:00
|
|
|
|
2019-01-11 17:50:09 -05:00
|
|
|
this.queue_relayout();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2014-07-31 11:35:27 -04:00
|
|
|
|
2018-07-06 04:01:39 -04:00
|
|
|
vfunc_allocate(box, flags) {
|
|
|
|
this.set_allocation(box, flags);
|
|
|
|
|
2012-02-13 20:37:28 -05:00
|
|
|
let rtl = (Clutter.get_default_text_direction () == Clutter.TextDirection.RTL);
|
2011-02-18 09:41:43 -05:00
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
if (this._thumbnails.length == 0) // not visible
|
|
|
|
return;
|
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
2018-07-06 04:01:39 -04:00
|
|
|
let themeNode = this.get_theme_node();
|
|
|
|
|
|
|
|
box = themeNode.get_content_box(box);
|
2013-10-11 21:27:59 -04:00
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
let portholeWidth = this._porthole.width;
|
|
|
|
let portholeHeight = this._porthole.height;
|
2013-10-11 21:27:59 -04:00
|
|
|
let spacing = themeNode.get_length('spacing');
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
// Compute the scale we'll need once everything is updated
|
2018-01-03 02:55:38 -05:00
|
|
|
let nWorkspaces = workspaceManager.n_workspaces;
|
2011-02-12 14:40:49 -05:00
|
|
|
let totalSpacing = (nWorkspaces - 1) * spacing;
|
2013-10-11 21:27:59 -04:00
|
|
|
let avail = (box.y2 - box.y1) - totalSpacing;
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
let newScale = (avail / nWorkspaces) / portholeHeight;
|
2011-02-12 14:40:49 -05:00
|
|
|
newScale = Math.min(newScale, MAX_THUMBNAIL_SCALE);
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
if (newScale != this._targetScale) {
|
2011-02-11 17:05:35 -05:00
|
|
|
if (this._targetScale > 0) {
|
2011-02-12 14:40:49 -05:00
|
|
|
// We don't do the tween immediately because we need to observe the ordering
|
|
|
|
// in queueUpdateStates - if workspaces have been removed we need to slide them
|
|
|
|
// out as the first thing.
|
|
|
|
this._targetScale = newScale;
|
|
|
|
this._pendingScaleUpdate = true;
|
2011-02-11 17:05:35 -05:00
|
|
|
} else {
|
2011-02-12 14:40:49 -05:00
|
|
|
this._targetScale = this._scale = newScale;
|
2011-02-11 17:05:35 -05:00
|
|
|
}
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
this._queueUpdateStates();
|
2011-02-11 17:05:35 -05:00
|
|
|
}
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
let thumbnailHeight = portholeHeight * this._scale;
|
|
|
|
let thumbnailWidth = Math.round(portholeWidth * this._scale);
|
2011-02-18 10:31:18 -05:00
|
|
|
let roundedHScale = thumbnailWidth / portholeWidth;
|
2011-02-18 09:41:43 -05:00
|
|
|
|
|
|
|
let slideOffset; // X offset when thumbnail is fully slid offscreen
|
|
|
|
if (rtl)
|
|
|
|
slideOffset = - (thumbnailWidth + themeNode.get_padding(St.Side.LEFT));
|
|
|
|
else
|
|
|
|
slideOffset = thumbnailWidth + themeNode.get_padding(St.Side.RIGHT);
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-11-26 18:28:51 -05:00
|
|
|
let indicatorY1 = this._indicatorY;
|
|
|
|
let indicatorY2;
|
2011-02-12 16:33:42 -05:00
|
|
|
// when not animating, the workspace position overrides this._indicatorY
|
2018-01-03 02:55:38 -05:00
|
|
|
let activeWorkspace = workspaceManager.get_active_workspace();
|
|
|
|
let indicatorWorkspace = !this._animatingIndicator ? activeWorkspace : null;
|
2011-11-26 18:28:51 -05:00
|
|
|
let indicatorThemeNode = this._indicator.get_theme_node();
|
|
|
|
|
|
|
|
let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP);
|
|
|
|
let indicatorBottomFullBorder = indicatorThemeNode.get_padding(St.Side.BOTTOM) + indicatorThemeNode.get_border_width(St.Side.BOTTOM);
|
|
|
|
let indicatorLeftFullBorder = indicatorThemeNode.get_padding(St.Side.LEFT) + indicatorThemeNode.get_border_width(St.Side.LEFT);
|
|
|
|
let indicatorRightFullBorder = indicatorThemeNode.get_padding(St.Side.RIGHT) + indicatorThemeNode.get_border_width(St.Side.RIGHT);
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2013-10-11 21:27:59 -04:00
|
|
|
let y = box.y1;
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
if (this._dropPlaceholderPos == -1) {
|
2017-10-30 20:38:18 -04:00
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
2011-05-04 22:47:07 -04:00
|
|
|
this._dropPlaceholder.hide();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-05-04 22:47:07 -04:00
|
|
|
}
|
|
|
|
|
2013-10-11 21:27:59 -04:00
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
for (let i = 0; i < this._thumbnails.length; i++) {
|
2011-02-12 14:40:49 -05:00
|
|
|
let thumbnail = this._thumbnails[i];
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
if (i > 0)
|
2011-02-18 10:31:18 -05:00
|
|
|
y += spacing - Math.round(thumbnail.collapseFraction * spacing);
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-02-18 09:41:43 -05:00
|
|
|
let x1, x2;
|
|
|
|
if (rtl) {
|
2013-10-11 21:27:59 -04:00
|
|
|
x1 = box.x1 + slideOffset * thumbnail.slidePosition;
|
2011-02-18 09:41:43 -05:00
|
|
|
x2 = x1 + thumbnailWidth;
|
|
|
|
} else {
|
2013-10-11 21:27:59 -04:00
|
|
|
x1 = box.x2 - thumbnailWidth + slideOffset * thumbnail.slidePosition;
|
2011-02-18 09:41:43 -05:00
|
|
|
x2 = x1 + thumbnailWidth;
|
|
|
|
}
|
2011-02-11 17:05:35 -05:00
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
if (i == this._dropPlaceholderPos) {
|
|
|
|
let [minHeight, placeholderHeight] = this._dropPlaceholder.get_preferred_height(-1);
|
|
|
|
childBox.x1 = x1;
|
2019-01-31 09:04:56 -05:00
|
|
|
childBox.x2 = x2;
|
2011-05-04 22:47:07 -04:00
|
|
|
childBox.y1 = Math.round(y);
|
|
|
|
childBox.y2 = Math.round(y + placeholderHeight);
|
|
|
|
this._dropPlaceholder.allocate(childBox, flags);
|
2017-10-30 20:38:18 -04:00
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
2011-05-04 22:47:07 -04:00
|
|
|
this._dropPlaceholder.show();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-05-04 22:47:07 -04:00
|
|
|
y += placeholderHeight + spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We might end up with thumbnailHeight being something like 99.33
|
|
|
|
// pixels. To make this work and not end up with a gap at the bottom,
|
|
|
|
// we need some thumbnails to be 99 pixels and some 100 pixels height;
|
|
|
|
// we compute an actual scale separately for each thumbnail.
|
|
|
|
let y1 = Math.round(y);
|
|
|
|
let y2 = Math.round(y + thumbnailHeight);
|
|
|
|
let roundedVScale = (y2 - y1) / portholeHeight;
|
|
|
|
|
2011-11-26 18:28:51 -05:00
|
|
|
if (thumbnail.metaWorkspace == indicatorWorkspace) {
|
|
|
|
indicatorY1 = y1;
|
|
|
|
indicatorY2 = y2;
|
|
|
|
}
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
// Allocating a scaled actor is funny - x1/y1 correspond to the origin
|
|
|
|
// of the actor, but x2/y2 are increased by the *unscaled* size.
|
|
|
|
childBox.x1 = x1;
|
2011-02-13 16:53:15 -05:00
|
|
|
childBox.x2 = x1 + portholeWidth;
|
2011-02-11 12:09:23 -05:00
|
|
|
childBox.y1 = y1;
|
2011-02-13 16:53:15 -05:00
|
|
|
childBox.y2 = y1 + portholeHeight;
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-02-18 10:31:18 -05:00
|
|
|
thumbnail.actor.set_scale(roundedHScale, roundedVScale);
|
2011-02-12 14:40:49 -05:00
|
|
|
thumbnail.actor.allocate(childBox, flags);
|
|
|
|
|
2011-02-18 10:31:18 -05:00
|
|
|
// We round the collapsing portion so that we don't get thumbnails resizing
|
|
|
|
// during an animation due to differences in rounded, but leave the uncollapsed
|
|
|
|
// portion unrounded so that non-animating we end up with the right total
|
|
|
|
y += thumbnailHeight - Math.round(thumbnailHeight * thumbnail.collapseFraction);
|
2011-02-11 12:09:23 -05:00
|
|
|
}
|
|
|
|
|
2011-02-18 09:41:43 -05:00
|
|
|
if (rtl) {
|
2013-10-11 21:27:59 -04:00
|
|
|
childBox.x1 = box.x1;
|
|
|
|
childBox.x2 = box.x1 + thumbnailWidth;
|
2011-02-18 09:41:43 -05:00
|
|
|
} else {
|
2013-10-11 21:27:59 -04:00
|
|
|
childBox.x1 = box.x2 - thumbnailWidth;
|
|
|
|
childBox.x2 = box.x2;
|
2011-02-18 09:41:43 -05:00
|
|
|
}
|
2011-11-26 18:28:51 -05:00
|
|
|
childBox.x1 -= indicatorLeftFullBorder;
|
|
|
|
childBox.x2 += indicatorRightFullBorder;
|
|
|
|
childBox.y1 = indicatorY1 - indicatorTopFullBorder;
|
|
|
|
childBox.y2 = (indicatorY2 ? indicatorY2 : (indicatorY1 + thumbnailHeight)) + indicatorBottomFullBorder;
|
2011-02-12 16:33:42 -05:00
|
|
|
this._indicator.allocate(childBox, flags);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_activeWorkspaceChanged(wm, from, to, direction) {
|
2011-02-12 14:40:49 -05:00
|
|
|
let thumbnail;
|
2018-01-03 02:55:38 -05:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let activeWorkspace = workspaceManager.get_active_workspace();
|
2011-02-12 14:40:49 -05:00
|
|
|
for (let i = 0; i < this._thumbnails.length; i++) {
|
|
|
|
if (this._thumbnails[i].metaWorkspace == activeWorkspace) {
|
|
|
|
thumbnail = this._thumbnails[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-02-12 16:14:12 -05:00
|
|
|
this._animatingIndicator = true;
|
2011-11-26 18:28:51 -05:00
|
|
|
let indicatorThemeNode = this._indicator.get_theme_node();
|
|
|
|
let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP);
|
|
|
|
this.indicatorY = this._indicator.allocation.y1 + indicatorTopFullBorder;
|
2011-02-12 16:33:42 -05:00
|
|
|
Tweener.addTween(this,
|
|
|
|
{ indicatorY: thumbnail.actor.allocation.y1,
|
2011-02-09 15:48:11 -05:00
|
|
|
time: WorkspacesView.WORKSPACE_SWITCH_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
2019-06-29 11:37:59 -04:00
|
|
|
onComplete: () => {
|
2011-02-12 16:14:12 -05:00
|
|
|
this._animatingIndicator = false;
|
|
|
|
this._queueUpdateStates();
|
2019-06-29 11:37:59 -04:00
|
|
|
}
|
2011-02-09 15:48:11 -05:00
|
|
|
});
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|