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
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
2011-02-12 14:40:49 -05:00
|
|
|
const Meta = imports.gi.Meta;
|
2011-01-30 21:18:12 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
// The maximum size of a thumbnail is 1/8 the width and height of the screen
|
|
|
|
let MAX_THUMBNAIL_SCALE = 1/8.;
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
const RESCALE_ANIMATION_TIME = 0.2;
|
2011-02-12 14:40:49 -05:00
|
|
|
const 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.
|
|
|
|
const WORKSPACE_CUT_SIZE = 10;
|
|
|
|
|
2012-02-17 09:57:27 -05:00
|
|
|
const WORKSPACE_KEEP_ALIVE_TIME = 100;
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const WindowClone = new Lang.Class({
|
|
|
|
Name: 'WindowClone',
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
_init : function(realWindow) {
|
|
|
|
this.actor = new Clutter.Clone({ source: realWindow.get_texture(),
|
2011-02-02 22:54:33 -05:00
|
|
|
reactive: true });
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor._delegate = this;
|
|
|
|
this.realWindow = realWindow;
|
|
|
|
this.metaWindow = realWindow.meta_window;
|
|
|
|
|
2011-02-02 22:54:33 -05:00
|
|
|
this._positionChangedId = this.realWindow.connect('position-changed',
|
|
|
|
Lang.bind(this, this._onPositionChanged));
|
|
|
|
this._realWindowDestroyedId = this.realWindow.connect('destroy',
|
|
|
|
Lang.bind(this, this._disconnectRealWindowSignals));
|
|
|
|
this._onPositionChanged();
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor.connect('button-release-event',
|
|
|
|
Lang.bind(this, this._onButtonRelease));
|
|
|
|
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
|
|
|
|
this._draggable = DND.makeDraggable(this.actor,
|
|
|
|
{ restoreOnSuccess: true,
|
|
|
|
dragActorMaxSize: Workspace.WINDOW_DND_SIZE,
|
|
|
|
dragActorOpacity: Workspace.DRAGGING_WINDOW_OPACITY });
|
|
|
|
this._draggable.connect('drag-begin', Lang.bind(this, this._onDragBegin));
|
2011-12-02 10:54:27 -05:00
|
|
|
this._draggable.connect('drag-cancelled', Lang.bind(this, this._onDragCancelled));
|
2011-01-30 21:18:12 -05:00
|
|
|
this._draggable.connect('drag-end', Lang.bind(this, this._onDragEnd));
|
|
|
|
this.inDrag = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
setStackAbove: function (actor) {
|
|
|
|
this._stackAbove = actor;
|
|
|
|
if (this._stackAbove == null)
|
|
|
|
this.actor.lower_bottom();
|
|
|
|
else
|
|
|
|
this.actor.raise(this._stackAbove);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function () {
|
|
|
|
this.actor.destroy();
|
|
|
|
},
|
|
|
|
|
2011-02-02 22:54:33 -05:00
|
|
|
_onPositionChanged: function() {
|
|
|
|
let rect = this.metaWindow.get_outer_rect();
|
|
|
|
this.actor.set_position(this.realWindow.x, this.realWindow.y);
|
|
|
|
},
|
|
|
|
|
|
|
|
_disconnectRealWindowSignals: function() {
|
|
|
|
if (this._positionChangedId != 0) {
|
|
|
|
this.realWindow.disconnect(this._positionChangedId);
|
|
|
|
this._positionChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._realWindowDestroyedId != 0) {
|
|
|
|
this.realWindow.disconnect(this._realWindowDestroyedId);
|
|
|
|
this._realWindowDestroyedId = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
_onDestroy: function() {
|
2011-02-02 22:54:33 -05:00
|
|
|
this._disconnectRealWindowSignals();
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this.actor._delegate = null;
|
|
|
|
|
|
|
|
if (this.inDrag) {
|
|
|
|
this.emit('drag-end');
|
|
|
|
this.inDrag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.disconnectAll();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onButtonRelease : function (actor, event) {
|
|
|
|
this.emit('selected', event.get_time());
|
2011-02-09 19:19:35 -05:00
|
|
|
|
|
|
|
return true;
|
2011-01-30 21:18:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDragBegin : function (draggable, time) {
|
|
|
|
this.inDrag = true;
|
|
|
|
this.emit('drag-begin');
|
|
|
|
},
|
|
|
|
|
2011-12-02 10:54:27 -05:00
|
|
|
_onDragCancelled : function (draggable, time) {
|
|
|
|
this.emit('drag-cancelled');
|
|
|
|
},
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
_onDragEnd : function (draggable, time, snapback) {
|
|
|
|
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');
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-01-30 21:18:12 -05:00
|
|
|
Signals.addSignalMethods(WindowClone.prototype);
|
|
|
|
|
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
const ThumbnailState = {
|
|
|
|
NEW : 0,
|
|
|
|
ANIMATING_IN : 1,
|
|
|
|
NORMAL: 2,
|
|
|
|
REMOVING : 3,
|
|
|
|
ANIMATING_OUT : 4,
|
|
|
|
ANIMATED_OUT : 5,
|
|
|
|
COLLAPSING : 6,
|
|
|
|
DESTROYED : 7
|
|
|
|
};
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
/**
|
|
|
|
* @metaWorkspace: a #Meta.Workspace
|
|
|
|
*/
|
2011-11-20 12:56:27 -05:00
|
|
|
const WorkspaceThumbnail = new Lang.Class({
|
|
|
|
Name: 'WorkspaceThumbnail',
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
_init : function(metaWorkspace) {
|
|
|
|
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;
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
this._contents = new Clutter.Group();
|
|
|
|
this.actor.add_actor(this._contents);
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
|
2011-08-28 21:37:41 -04:00
|
|
|
this._background = Meta.BackgroundActor.new_for_screen(global.screen);
|
2011-02-13 16:53:15 -05:00
|
|
|
this._contents.add_actor(this._background);
|
|
|
|
|
2011-06-13 09:54:05 -04:00
|
|
|
let monitor = Main.layoutManager.primaryMonitor;
|
2011-02-28 14:09:23 -05:00
|
|
|
this.setPorthole(monitor.x, monitor.y, monitor.width, monitor.height);
|
2011-01-30 21:18:12 -05:00
|
|
|
|
2012-01-11 17:59:17 -05:00
|
|
|
let windows = global.get_window_actors().filter(this._isWorkspaceWindow, this);
|
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',
|
|
|
|
Lang.bind(this,
|
|
|
|
this._updateMinimized));
|
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',
|
|
|
|
Lang.bind(this, this._windowAdded));
|
|
|
|
this._windowRemovedId = this.metaWorkspace.connect('window-removed',
|
|
|
|
Lang.bind(this, this._windowRemoved));
|
2011-02-28 14:19:30 -05:00
|
|
|
this._windowEnteredMonitorId = global.screen.connect('window-entered-monitor',
|
|
|
|
Lang.bind(this, this._windowEnteredMonitor));
|
|
|
|
this._windowLeftMonitorId = global.screen.connect('window-left-monitor',
|
|
|
|
Lang.bind(this, this._windowLeftMonitor));
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
this.state = ThumbnailState.NORMAL;
|
|
|
|
this._slidePosition = 0; // Fully slid in
|
|
|
|
this._collapseFraction = 0; // Not collapsed
|
2011-01-30 21:18:12 -05:00
|
|
|
},
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
setPorthole: function(x, y, width, height) {
|
2011-02-28 14:19:30 -05:00
|
|
|
this._portholeX = x;
|
|
|
|
this._portholeY = y;
|
2011-02-13 16:53:15 -05:00
|
|
|
this.actor.set_size(width, height);
|
|
|
|
this._contents.set_position(-x, -y);
|
|
|
|
},
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
_lookupIndex: function (metaWindow) {
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
if (this._windows[i].metaWindow == metaWindow) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
syncStacking: function(stackIndices) {
|
|
|
|
this._windows.sort(function (a, b) { return stackIndices[a.metaWindow.get_stable_sequence()] - stackIndices[b.metaWindow.get_stable_sequence()]; });
|
|
|
|
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
|
|
|
let metaWindow = clone.metaWindow;
|
|
|
|
if (i == 0) {
|
|
|
|
clone.setStackAbove(this._background);
|
|
|
|
} else {
|
|
|
|
let previousClone = this._windows[i - 1];
|
|
|
|
clone.setStackAbove(previousClone.actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
set slidePosition(slidePosition) {
|
|
|
|
this._slidePosition = slidePosition;
|
|
|
|
this.actor.queue_relayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
get slidePosition() {
|
|
|
|
return this._slidePosition;
|
|
|
|
},
|
|
|
|
|
|
|
|
set collapseFraction(collapseFraction) {
|
|
|
|
this._collapseFraction = collapseFraction;
|
|
|
|
this.actor.queue_relayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
get collapseFraction() {
|
|
|
|
return this._collapseFraction;
|
|
|
|
},
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
_doRemoveWindow : function(metaWin) {
|
2011-01-30 21:18:12 -05:00
|
|
|
let win = metaWin.get_compositor_private();
|
|
|
|
|
|
|
|
// find the position of the window in our list
|
|
|
|
let index = this._lookupIndex (metaWin);
|
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
// Check if window still should be here
|
2011-05-31 12:49:36 -04:00
|
|
|
if (win && this._isMyWindow(win) && this._isOverviewWindow(win))
|
2011-02-28 14:19:30 -05:00
|
|
|
return;
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
let clone = this._windows[index];
|
|
|
|
this._windows.splice(index, 1);
|
2011-05-31 12:49:36 -04:00
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
clone.destroy();
|
|
|
|
},
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
_doAddWindow : function(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...
|
|
|
|
Mainloop.idle_add(Lang.bind(this,
|
|
|
|
function () {
|
2012-01-11 17:24:42 -05:00
|
|
|
if (!this._removed &&
|
2011-04-20 16:04:03 -04:00
|
|
|
metaWin.get_compositor_private() &&
|
|
|
|
metaWin.get_workspace() == this.metaWorkspace)
|
2011-02-28 14:19:30 -05:00
|
|
|
this._doAddWindow(metaWin);
|
2011-01-30 21:18:12 -05:00
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 17:50:31 -05:00
|
|
|
if (this._allWindows.indexOf(metaWin) == -1) {
|
|
|
|
let minimizedChangedId = metaWin.connect('notify::minimized',
|
|
|
|
Lang.bind(this,
|
|
|
|
this._updateMinimized));
|
|
|
|
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
|
2012-01-17 17:50:31 -05:00
|
|
|
if (this._lookupIndex (metaWin) != -1)
|
2011-02-28 14:19:30 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!this._isMyWindow(win) || !this._isOverviewWindow(win))
|
2011-01-30 21:18:12 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
let clone = this._addWindowClone(win);
|
|
|
|
},
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
_windowAdded : function(metaWorkspace, metaWin) {
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
},
|
|
|
|
|
|
|
|
_windowRemoved : function(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);
|
|
|
|
},
|
|
|
|
|
|
|
|
_windowEnteredMonitor : function(metaScreen, monitorIndex, metaWin) {
|
|
|
|
if (monitorIndex == this.monitorIndex) {
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_windowLeftMonitor : function(metaScreen, monitorIndex, metaWin) {
|
|
|
|
if (monitorIndex == this.monitorIndex) {
|
|
|
|
this._doRemoveWindow(metaWin);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-05-31 12:49:36 -04:00
|
|
|
_updateMinimized: function(metaWin) {
|
|
|
|
if (metaWin.minimized)
|
|
|
|
this._doRemoveWindow(metaWin);
|
|
|
|
else
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
},
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
destroy : function() {
|
|
|
|
this.actor.destroy();
|
|
|
|
},
|
|
|
|
|
2012-01-11 17:24:42 -05:00
|
|
|
workspaceRemoved : function() {
|
|
|
|
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);
|
2011-02-28 14:19:30 -05:00
|
|
|
global.screen.disconnect(this._windowEnteredMonitorId);
|
|
|
|
global.screen.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]);
|
2012-01-11 17:24:42 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function(actor) {
|
|
|
|
this.workspaceRemoved();
|
2011-05-31 12:49:36 -04:00
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this._windows = [];
|
|
|
|
this.actor = null;
|
|
|
|
},
|
|
|
|
|
2012-01-11 17:59:17 -05:00
|
|
|
// Tests if @win belongs to this workspace
|
|
|
|
_isWorkspaceWindow : function (win) {
|
|
|
|
return Main.isWindowActorDisplayedOnWorkspace(win, this.metaWorkspace.index());
|
|
|
|
},
|
|
|
|
|
2011-02-28 14:19:30 -05:00
|
|
|
// Tests if @win belongs to this workspace and monitor
|
2011-01-30 21:18:12 -05:00
|
|
|
_isMyWindow : function (win) {
|
2012-01-11 17:59:17 -05:00
|
|
|
return this._isWorkspaceWindow(win) &&
|
2011-02-28 14:19:30 -05:00
|
|
|
(!win.get_meta_window() || win.get_meta_window().get_monitor() == this.monitorIndex);
|
2011-01-30 21:18:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Tests if @win should be shown in the Overview
|
|
|
|
_isOverviewWindow : function (win) {
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
2011-05-31 12:49:36 -04:00
|
|
|
return tracker.is_window_interesting(win.get_meta_window()) &&
|
|
|
|
win.get_meta_window().showing_on_its_workspace();
|
2011-01-30 21:18:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Create a clone of a (non-desktop) window and add it to the window list
|
|
|
|
_addWindowClone : function(win) {
|
|
|
|
let clone = new WindowClone(win);
|
|
|
|
|
|
|
|
clone.connect('selected',
|
2012-02-10 12:59:05 -05:00
|
|
|
Lang.bind(this, function(clone, time) {
|
|
|
|
this.activate(time);
|
|
|
|
}));
|
2011-01-30 21:18:12 -05:00
|
|
|
clone.connect('drag-begin',
|
|
|
|
Lang.bind(this, function(clone) {
|
|
|
|
Main.overview.beginWindowDrag();
|
|
|
|
}));
|
2011-12-02 10:54:27 -05:00
|
|
|
clone.connect('drag-cancelled',
|
|
|
|
Lang.bind(this, function(clone) {
|
|
|
|
Main.overview.cancelledWindowDrag();
|
|
|
|
}));
|
2011-01-30 21:18:12 -05:00
|
|
|
clone.connect('drag-end',
|
|
|
|
Lang.bind(this, function(clone) {
|
|
|
|
Main.overview.endWindowDrag();
|
|
|
|
}));
|
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)
|
|
|
|
clone.setStackAbove(this._background);
|
|
|
|
else
|
|
|
|
clone.setStackAbove(this._windows[this._windows.length - 1].actor);
|
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
this._windows.push(clone);
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
},
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
activate : function (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
|
|
|
|
if (this.metaWorkspace == global.screen.get_active_workspace())
|
|
|
|
Main.overview.hide();
|
|
|
|
else
|
|
|
|
this.metaWorkspace.activate(time);
|
2011-01-30 21:18:12 -05:00
|
|
|
},
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
// Draggable target interface used only by ThumbnailsBox
|
|
|
|
handleDragOverInternal : function(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;
|
|
|
|
},
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
acceptDropInternal : function(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
|
|
|
|
2011-01-30 21:18:12 -05:00
|
|
|
metaWindow.change_workspace_by_index(this.metaWorkspace.index(),
|
|
|
|
false, // don't create workspace
|
|
|
|
time);
|
|
|
|
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;
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2011-01-30 21:18:12 -05:00
|
|
|
|
|
|
|
Signals.addSignalMethods(WorkspaceThumbnail.prototype);
|
2011-02-09 15:48:11 -05:00
|
|
|
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const ThumbnailsBox = new Lang.Class({
|
|
|
|
Name: 'ThumbnailsBox',
|
2011-02-09 15:48:11 -05:00
|
|
|
|
|
|
|
_init: function() {
|
2012-02-10 12:59:05 -05:00
|
|
|
this.actor = new Shell.GenericContainer({ reactive: true,
|
|
|
|
style_class: 'workspace-thumbnails',
|
2011-02-11 12:09:23 -05:00
|
|
|
request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
|
|
|
|
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this.actor.connect('allocate', Lang.bind(this, this._allocate));
|
2011-05-04 22:47:07 -04:00
|
|
|
this.actor._delegate = this;
|
2011-02-09 15:48:11 -05:00
|
|
|
|
2011-02-12 15:23:27 -05:00
|
|
|
// When we animate the scale, we don't animate the requested size of the thumbnails, rather
|
|
|
|
// we ask for our final size and then animate within that size. This slightly simplifies the
|
|
|
|
// interaction with the main workspace windows (instead of constantly reallocating them
|
|
|
|
// to a new size, they get a new size once, then use the standard window animation code
|
|
|
|
// allocate the windows to their new positions), however it causes problems for drawing
|
|
|
|
// the background and border wrapped around the thumbnail as we animate - we can't just pack
|
|
|
|
// the container into a box and set style properties on the box since that box would wrap
|
|
|
|
// around the final size not the animating size. So instead we fake the background with
|
|
|
|
// an actor underneath the content and adjust the allocation of our children to leave space
|
|
|
|
// for the border and padding of the background actor.
|
|
|
|
this._background = new St.Bin({ style_class: 'workspace-thumbnails-background' });
|
2011-02-18 09:41:43 -05:00
|
|
|
|
2011-02-12 15:23:27 -05:00
|
|
|
this.actor.add_actor(this._background);
|
|
|
|
|
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;
|
2011-02-11 12:09:23 -05:00
|
|
|
this.actor.add_actor(indicator);
|
2011-02-12 14:40:49 -05:00
|
|
|
|
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' });
|
|
|
|
this.actor.add_actor(this._dropPlaceholder);
|
|
|
|
|
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
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
this.actor.connect('button-press-event', function() { return true; });
|
|
|
|
this.actor.connect('button-release-event', Lang.bind(this, this._onButtonRelease));
|
|
|
|
|
2011-11-27 10:23:17 -05:00
|
|
|
Main.overview.connect('item-drag-begin',
|
|
|
|
Lang.bind(this, this._onDragBegin));
|
|
|
|
Main.overview.connect('item-drag-end',
|
|
|
|
Lang.bind(this, this._onDragEnd));
|
|
|
|
Main.overview.connect('item-drag-cancelled',
|
|
|
|
Lang.bind(this, this._onDragCancelled));
|
|
|
|
Main.overview.connect('window-drag-begin',
|
|
|
|
Lang.bind(this, this._onDragBegin));
|
|
|
|
Main.overview.connect('window-drag-end',
|
|
|
|
Lang.bind(this, this._onDragEnd));
|
|
|
|
Main.overview.connect('window-drag-cancelled',
|
|
|
|
Lang.bind(this, this._onDragCancelled));
|
|
|
|
},
|
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
_onButtonRelease: function(actor, event) {
|
|
|
|
let [stageX, stageY] = event.get_coords();
|
|
|
|
let [r, x, y] = this.actor.transform_stage_point(stageX, stageY);
|
|
|
|
|
|
|
|
for (let i = 0; i < this._thumbnails.length; i++) {
|
|
|
|
let thumbnail = this._thumbnails[i]
|
|
|
|
let [w, h] = thumbnail.actor.get_transformed_size();
|
|
|
|
if (y >= thumbnail.actor.y && y <= thumbnail.actor.y + h) {
|
|
|
|
thumbnail.activate(event.time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2011-11-27 10:23:17 -05:00
|
|
|
_onDragBegin: function() {
|
|
|
|
this._dragCancelled = false;
|
|
|
|
this._dragMonitor = {
|
|
|
|
dragMotion: Lang.bind(this, this._onDragMotion)
|
|
|
|
};
|
|
|
|
DND.addDragMonitor(this._dragMonitor);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDragEnd: function() {
|
|
|
|
if (this._dragCancelled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._endDrag();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDragCancelled: function() {
|
|
|
|
this._dragCancelled = true;
|
|
|
|
this._endDrag();
|
|
|
|
},
|
|
|
|
|
|
|
|
_endDrag: function() {
|
|
|
|
this._clearDragPlaceholder();
|
|
|
|
DND.removeDragMonitor(this._dragMonitor);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDragMotion: function(dragEvent) {
|
|
|
|
if (!this.actor.contains(dragEvent.targetActor))
|
|
|
|
this._onLeave();
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onLeave: function() {
|
|
|
|
this._clearDragPlaceholder();
|
|
|
|
},
|
|
|
|
|
|
|
|
_clearDragPlaceholder: function() {
|
2012-02-21 14:46:27 -05:00
|
|
|
if (this._dropPlaceholderPos == -1)
|
|
|
|
return;
|
|
|
|
|
2011-11-27 10:23:17 -05:00
|
|
|
this._dropPlaceholderPos = -1;
|
|
|
|
this.actor.queue_relayout();
|
2011-02-09 15:48:11 -05:00
|
|
|
},
|
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
// Draggable target interface
|
|
|
|
handleDragOver : function(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-03-07 19:29:17 -05:00
|
|
|
if (!Meta.prefs_get_dynamic_workspaces())
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
let spacing = this.actor.get_theme_node().get_length('spacing');
|
|
|
|
|
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;
|
|
|
|
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-02-10 12:59:05 -05:00
|
|
|
if (y > targetTop && y <= targetBottom && source != Main.xdndHandler) {
|
|
|
|
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;
|
|
|
|
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;
|
2012-02-21 14:46:27 -05:00
|
|
|
this.actor.queue_relayout();
|
|
|
|
}
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
acceptDrop: function(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;
|
|
|
|
|
|
|
|
// To create a new workspace, we first slide all the windows on workspaces
|
|
|
|
// below us to the next workspace, leaving a blank workspace for us to recycle.
|
|
|
|
let newWorkspaceIndex;
|
|
|
|
[newWorkspaceIndex, this._dropPlaceholderPos] = [this._dropPlaceholderPos, -1];
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
// Nab all the windows below us.
|
|
|
|
let windows = global.get_window_actors().filter(function(win) {
|
|
|
|
if (isWindow)
|
|
|
|
return win.get_workspace() >= newWorkspaceIndex && win != source;
|
|
|
|
else
|
|
|
|
return win.get_workspace() >= newWorkspaceIndex;
|
|
|
|
});
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
// ... move them down one.
|
|
|
|
windows.forEach(function(win) {
|
|
|
|
win.meta_window.change_workspace_by_index(win.get_workspace() + 1,
|
|
|
|
true, time);
|
|
|
|
});
|
2011-05-04 22:47:07 -04:00
|
|
|
|
|
|
|
if (isWindow)
|
2012-02-10 12:59:05 -05:00
|
|
|
// ... and bam, a workspace, good as new.
|
|
|
|
source.metaWindow.change_workspace_by_index(newWorkspaceIndex,
|
|
|
|
true, time);
|
|
|
|
else if (source.shellWorkspaceLaunch) {
|
|
|
|
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.
|
|
|
|
Main.keepWorkspaceAlive(global.screen.get_workspace_by_index(newWorkspaceIndex),
|
|
|
|
WORKSPACE_KEEP_ALIVE_TIME);
|
|
|
|
}
|
2011-05-04 22:47:07 -04:00
|
|
|
|
2012-02-10 12:59:05 -05:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-04 22:47:07 -04:00
|
|
|
},
|
|
|
|
|
2011-02-09 15:48:11 -05:00
|
|
|
show: function() {
|
|
|
|
this._switchWorkspaceNotifyId =
|
|
|
|
global.window_manager.connect('switch-workspace',
|
|
|
|
Lang.bind(this, this._activeWorkspaceChanged));
|
|
|
|
|
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;
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
// The "porthole" is the portion of the screen that we show in the workspaces
|
|
|
|
let panelHeight = Main.panel.actor.height;
|
2011-06-13 09:54:05 -04:00
|
|
|
let monitor = Main.layoutManager.primaryMonitor;
|
2011-02-13 16:53:15 -05:00
|
|
|
this._porthole = {
|
2011-02-28 14:09:23 -05:00
|
|
|
x: monitor.x,
|
|
|
|
y: monitor.y + panelHeight,
|
|
|
|
width: monitor.width,
|
|
|
|
height: monitor.height - panelHeight
|
2011-02-13 16:53:15 -05:00
|
|
|
};
|
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
this.addThumbnails(0, global.screen.n_workspaces);
|
2011-02-09 15:48:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
if (this._switchWorkspaceNotifyId > 0) {
|
|
|
|
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
|
|
|
|
this._switchWorkspaceNotifyId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let w = 0; w < this._thumbnails.length; w++)
|
|
|
|
this._thumbnails[w].destroy();
|
|
|
|
this._thumbnails = [];
|
|
|
|
},
|
|
|
|
|
|
|
|
addThumbnails: function(start, count) {
|
|
|
|
for (let k = start; k < start + count; k++) {
|
|
|
|
let metaWorkspace = global.screen.get_workspace_by_index(k);
|
|
|
|
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);
|
2011-02-11 12:09:23 -05:00
|
|
|
this.actor.add_actor(thumbnail.actor);
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
if (start > 0) { // not the initial fill
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeThumbmails: function(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();
|
2011-02-09 15:48:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
syncStacking: function(stackIndices) {
|
|
|
|
for (let i = 0; i < this._thumbnails.length; i++)
|
|
|
|
this._thumbnails[i].syncStacking(stackIndices);
|
|
|
|
},
|
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
set scale(scale) {
|
|
|
|
this._scale = scale;
|
|
|
|
this.actor.queue_relayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
get scale() {
|
|
|
|
return this._scale;
|
|
|
|
},
|
|
|
|
|
2011-02-12 16:33:42 -05:00
|
|
|
set indicatorY(indicatorY) {
|
|
|
|
this._indicatorY = indicatorY;
|
|
|
|
this.actor.queue_relayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
get indicatorY() {
|
|
|
|
return this._indicatorY;
|
|
|
|
},
|
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
_setThumbnailState: function(thumbnail, state) {
|
|
|
|
this._stateCounts[thumbnail.state]--;
|
|
|
|
thumbnail.state = state;
|
|
|
|
this._stateCounts[thumbnail.state]++;
|
|
|
|
},
|
|
|
|
|
|
|
|
_iterateStateThumbnails: function(state, callback) {
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_tweenScale: function() {
|
|
|
|
Tweener.addTween(this,
|
|
|
|
{ scale: this._targetScale,
|
|
|
|
time: RESCALE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: this._queueUpdateStates,
|
|
|
|
onCompleteScope: this });
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateStates: function() {
|
|
|
|
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
|
2011-02-12 14:40:49 -05:00
|
|
|
this._iterateStateThumbnails(ThumbnailState.REMOVING,
|
|
|
|
function(thumbnail) {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_OUT);
|
|
|
|
|
|
|
|
Tweener.addTween(thumbnail,
|
|
|
|
{ slidePosition: 1,
|
|
|
|
time: SLIDE_ANIMATION_TIME,
|
|
|
|
transition: 'linear',
|
|
|
|
onComplete: function() {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATED_OUT);
|
|
|
|
this._queueUpdateStates();
|
|
|
|
},
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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
|
|
|
|
this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT,
|
|
|
|
function(thumbnail) {
|
|
|
|
this.actor.set_skip_paint(thumbnail.actor, true);
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING);
|
|
|
|
Tweener.addTween(thumbnail,
|
|
|
|
{ collapseFraction: 1,
|
|
|
|
time: RESCALE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: function() {
|
|
|
|
this._stateCounts[thumbnail.state]--;
|
|
|
|
thumbnail.state = ThumbnailState.DESTROYED;
|
|
|
|
|
|
|
|
let index = this._thumbnails.indexOf(thumbnail);
|
|
|
|
this._thumbnails.splice(index, 1);
|
|
|
|
thumbnail.destroy();
|
|
|
|
|
|
|
|
this._queueUpdateStates();
|
|
|
|
},
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
this._iterateStateThumbnails(ThumbnailState.NEW,
|
|
|
|
function(thumbnail) {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_IN);
|
|
|
|
Tweener.addTween(thumbnail,
|
|
|
|
{ slidePosition: 0,
|
|
|
|
time: SLIDE_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: function() {
|
|
|
|
this._setThumbnailState(thumbnail, ThumbnailState.NORMAL);
|
|
|
|
},
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_queueUpdateStates: function() {
|
|
|
|
if (this._stateUpdateQueued)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW,
|
|
|
|
Lang.bind(this, this._updateStates));
|
|
|
|
|
|
|
|
this._stateUpdateQueued = true;
|
|
|
|
},
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
_getPreferredHeight: function(actor, forWidth, alloc) {
|
2011-02-12 15:23:27 -05:00
|
|
|
// See comment about this._background in _init()
|
|
|
|
let themeNode = this._background.get_theme_node();
|
|
|
|
|
|
|
|
forWidth = themeNode.adjust_for_width(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.
|
|
|
|
|
|
|
|
if (this._thumbnails.length == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let spacing = this.actor.get_theme_node().get_length('spacing');
|
2011-02-12 14:40:49 -05:00
|
|
|
let nWorkspaces = global.screen.n_workspaces;
|
|
|
|
let totalSpacing = (nWorkspaces - 1) * spacing;
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-02-12 15:23:27 -05:00
|
|
|
[alloc.min_size, alloc.natural_size] =
|
|
|
|
themeNode.adjust_preferred_height(totalSpacing,
|
2011-02-13 16:53:15 -05:00
|
|
|
totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE);
|
2011-02-11 12:09:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function(actor, forHeight, alloc) {
|
2011-02-12 15:23:27 -05:00
|
|
|
// See comment about this._background in _init()
|
|
|
|
let themeNode = this._background.get_theme_node();
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
if (this._thumbnails.length == 0)
|
|
|
|
return;
|
|
|
|
|
2011-02-12 14:40:49 -05:00
|
|
|
// We don't animate our preferred width, which is always reported according
|
|
|
|
// to the actual number of current workspaces, we just animate within that
|
|
|
|
|
2011-02-11 12:09:23 -05:00
|
|
|
let spacing = this.actor.get_theme_node().get_length('spacing');
|
2011-02-12 14:40:49 -05:00
|
|
|
let nWorkspaces = global.screen.n_workspaces;
|
|
|
|
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);
|
2011-02-12 15:23:27 -05:00
|
|
|
[alloc.min_size, alloc.natural_size] =
|
|
|
|
themeNode.adjust_preferred_width(width, width);
|
2011-02-11 12:09:23 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function(actor, 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-12 15:23:27 -05:00
|
|
|
// See comment about this._background in _init()
|
|
|
|
let themeNode = this._background.get_theme_node();
|
|
|
|
let contentBox = themeNode.get_content_box(box);
|
|
|
|
|
2011-02-11 17:05:35 -05:00
|
|
|
if (this._thumbnails.length == 0) // not visible
|
|
|
|
return;
|
|
|
|
|
2011-02-13 16:53:15 -05:00
|
|
|
let portholeWidth = this._porthole.width;
|
|
|
|
let portholeHeight = this._porthole.height;
|
2011-02-11 12:09:23 -05:00
|
|
|
let spacing = this.actor.get_theme_node().get_length('spacing');
|
2011-02-12 14:40:49 -05:00
|
|
|
|
|
|
|
// Compute the scale we'll need once everything is updated
|
|
|
|
let nWorkspaces = global.screen.n_workspaces;
|
|
|
|
let totalSpacing = (nWorkspaces - 1) * spacing;
|
2011-02-12 15:23:27 -05:00
|
|
|
let avail = (contentBox.y2 - contentBox.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
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
2011-02-12 15:23:27 -05:00
|
|
|
// The background is horizontally restricted to correspond to the current thumbnail size
|
|
|
|
// but otherwise covers the entire allocation
|
2011-02-18 09:41:43 -05:00
|
|
|
if (rtl) {
|
|
|
|
childBox.x1 = box.x1;
|
|
|
|
childBox.x2 = box.x2 - ((contentBox.x2 - contentBox.x1) - thumbnailWidth);
|
|
|
|
} else {
|
|
|
|
childBox.x1 = box.x1 + ((contentBox.x2 - contentBox.x1) - thumbnailWidth);
|
|
|
|
childBox.x2 = box.x2;
|
|
|
|
}
|
2011-02-12 15:23:27 -05:00
|
|
|
childBox.y1 = box.y1;
|
|
|
|
childBox.y2 = box.y2;
|
|
|
|
this._background.allocate(childBox, flags);
|
|
|
|
|
2011-02-12 16:33:42 -05:00
|
|
|
let indicatorY = this._indicatorY;
|
|
|
|
// when not animating, the workspace position overrides this._indicatorY
|
|
|
|
let indicatorWorkspace = !this._animatingIndicator ? global.screen.get_active_workspace() : null;
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-02-12 15:23:27 -05:00
|
|
|
let y = contentBox.y1;
|
2011-02-11 12:09:23 -05:00
|
|
|
|
2011-05-04 22:47:07 -04:00
|
|
|
if (this._dropPlaceholderPos == -1) {
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
|
|
|
|
this._dropPlaceholder.hide();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
x1 = contentBox.x1 + slideOffset * thumbnail.slidePosition;
|
|
|
|
x2 = x1 + thumbnailWidth;
|
|
|
|
} else {
|
|
|
|
x1 = contentBox.x2 - thumbnailWidth + slideOffset * thumbnail.slidePosition;
|
|
|
|
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;
|
|
|
|
childBox.x2 = x1 + thumbnailWidth;
|
|
|
|
childBox.y1 = Math.round(y);
|
|
|
|
childBox.y2 = Math.round(y + placeholderHeight);
|
|
|
|
this._dropPlaceholder.allocate(childBox, flags);
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
|
|
|
|
this._dropPlaceholder.show();
|
|
|
|
}));
|
|
|
|
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-02-12 16:33:42 -05:00
|
|
|
if (thumbnail.metaWorkspace == indicatorWorkspace)
|
|
|
|
indicatorY = y1;
|
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) {
|
|
|
|
childBox.x1 = contentBox.x1;
|
|
|
|
childBox.x2 = contentBox.x1 + thumbnailWidth;
|
|
|
|
} else {
|
|
|
|
childBox.x1 = contentBox.x2 - thumbnailWidth;
|
|
|
|
childBox.x2 = contentBox.x2;
|
|
|
|
}
|
2011-02-12 16:33:42 -05:00
|
|
|
childBox.y1 = indicatorY;
|
|
|
|
childBox.y2 = childBox.y1 + thumbnailHeight;
|
|
|
|
this._indicator.allocate(childBox, flags);
|
2011-02-09 15:48:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_activeWorkspaceChanged: function(wm, from, to, direction) {
|
2011-02-12 14:40:49 -05:00
|
|
|
let thumbnail;
|
|
|
|
let activeWorkspace = global.screen.get_active_workspace();
|
|
|
|
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-02-12 16:33:42 -05:00
|
|
|
this.indicatorY = this._indicator.allocation.y1;
|
|
|
|
Tweener.addTween(this,
|
|
|
|
{ indicatorY: thumbnail.actor.allocation.y1,
|
2011-02-09 15:48:11 -05:00
|
|
|
time: WorkspacesView.WORKSPACE_SWITCH_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
2011-02-12 16:14:12 -05:00
|
|
|
onComplete: function() {
|
|
|
|
this._animatingIndicator = false;
|
|
|
|
this._queueUpdateStates();
|
|
|
|
},
|
|
|
|
onCompleteScope: this
|
2011-02-09 15:48:11 -05:00
|
|
|
});
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|