2009-02-02 23:02:16 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-02-02 23:02:16 +00:00
|
|
|
const Big = imports.gi.Big;
|
2008-12-02 16:15:00 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-02-02 23:02:16 +00:00
|
|
|
const GdkPixbuf = imports.gi.GdkPixbuf;
|
2009-11-20 00:39:00 +00:00
|
|
|
const Gdk = imports.gi.Gdk;
|
2009-01-23 19:21:20 +00:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2008-12-22 22:06:47 +00:00
|
|
|
const Lang = imports.lang;
|
2009-02-04 14:50:50 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2009-01-23 19:21:20 +00:00
|
|
|
const Pango = imports.gi.Pango;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-11-12 00:26:52 +00:00
|
|
|
const St = imports.gi.St;
|
2009-01-23 19:21:20 +00:00
|
|
|
const Signals = imports.signals;
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-02-10 16:15:59 +00:00
|
|
|
const DND = imports.ui.dnd;
|
2009-09-22 19:24:14 +00:00
|
|
|
const Lightbox = imports.ui.lightbox;
|
2008-12-02 16:15:00 +00:00
|
|
|
const Main = imports.ui.main;
|
2009-08-11 11:46:10 +00:00
|
|
|
const Overview = imports.ui.overview;
|
2008-12-02 16:15:00 +00:00
|
|
|
const Panel = imports.ui.panel;
|
2009-02-10 16:12:58 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-01-19 23:06:59 +00:00
|
|
|
const FOCUS_ANIMATION_TIME = 0.15;
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-01-21 21:12:49 +00:00
|
|
|
const FRAME_COLOR = new Clutter.Color();
|
|
|
|
FRAME_COLOR.from_pixel(0xffffffff);
|
2008-12-18 18:50:09 +00:00
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
const SCROLL_SCALE_AMOUNT = 100 / 5;
|
|
|
|
|
|
|
|
const ZOOM_OVERLAY_FADE_TIME = 0.15;
|
|
|
|
|
2008-12-02 16:15:00 +00:00
|
|
|
// Define a layout scheme for small window counts. For larger
|
|
|
|
// counts we fall back to an algorithm. We need more schemes here
|
|
|
|
// unless we have a really good algorithm.
|
|
|
|
|
|
|
|
// Each triplet is [xCenter, yCenter, scale] where the scale
|
2008-12-04 15:20:37 +00:00
|
|
|
// is relative to the width of the workspace.
|
2008-12-02 16:15:00 +00:00
|
|
|
const POSITIONS = {
|
2009-08-08 20:10:40 +00:00
|
|
|
1: [[0.5, 0.5, 0.95]],
|
|
|
|
2: [[0.25, 0.5, 0.48], [0.75, 0.5, 0.48]],
|
|
|
|
3: [[0.25, 0.25, 0.48], [0.75, 0.25, 0.48], [0.5, 0.75, 0.48]],
|
|
|
|
4: [[0.25, 0.25, 0.47], [0.75, 0.25, 0.47], [0.75, 0.75, 0.47], [0.25, 0.75, 0.47]],
|
|
|
|
5: [[0.165, 0.25, 0.32], [0.495, 0.25, 0.32], [0.825, 0.25, 0.32], [0.25, 0.75, 0.32], [0.75, 0.75, 0.32]]
|
2008-12-02 16:15:00 +00:00
|
|
|
};
|
2009-09-18 19:08:56 +00:00
|
|
|
// Used in _orderWindowsPermutations, 5! = 120 which is probably the highest we can go
|
|
|
|
const POSITIONING_PERMUTATIONS_MAX = 5;
|
2009-09-04 19:25:17 +00:00
|
|
|
|
|
|
|
function _interpolate(start, end, step) {
|
|
|
|
return start + (end - start) * step;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _clamp(value, min, max) {
|
|
|
|
return Math.max(min, Math.min(max, value));
|
|
|
|
}
|
|
|
|
|
2008-12-15 20:55:24 +00:00
|
|
|
// Spacing between workspaces. At the moment, the same spacing is used
|
|
|
|
// in both zoomed-in and zoomed-out views; this is slightly
|
|
|
|
// metaphor-breaking, but the alternatives are also weird.
|
2008-12-04 15:16:16 +00:00
|
|
|
const GRID_SPACING = 15;
|
2009-01-21 21:12:49 +00:00
|
|
|
const FRAME_SIZE = GRID_SPACING / 3;
|
2008-12-04 15:16:16 +00:00
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
function ScaledPoint(x, y, scaleX, scaleY) {
|
|
|
|
[this.x, this.y, this.scaleX, this.scaleY] = arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScaledPoint.prototype = {
|
|
|
|
getPosition : function() {
|
|
|
|
return [this.x, this.y];
|
|
|
|
},
|
|
|
|
|
|
|
|
getScale : function() {
|
|
|
|
return [this.scaleX, this.scaleY];
|
|
|
|
},
|
|
|
|
|
|
|
|
setPosition : function(x, y) {
|
|
|
|
[this.x, this.y] = arguments;
|
|
|
|
},
|
|
|
|
|
|
|
|
setScale : function(scaleX, scaleY) {
|
|
|
|
[this.scaleX, this.scaleY] = arguments;
|
|
|
|
},
|
|
|
|
|
|
|
|
interpPosition : function(other, step) {
|
|
|
|
return [_interpolate(this.x, other.x, step),
|
|
|
|
_interpolate(this.y, other.y, step)];
|
|
|
|
},
|
|
|
|
|
|
|
|
interpScale : function(other, step) {
|
|
|
|
return [_interpolate(this.scaleX, other.scaleX, step),
|
|
|
|
_interpolate(this.scaleY, other.scaleY, step)];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
function WindowClone(realWindow) {
|
|
|
|
this._init(realWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowClone.prototype = {
|
|
|
|
_init : function(realWindow) {
|
2009-02-23 19:42:00 +00:00
|
|
|
this.actor = new Clutter.Clone({ source: realWindow.get_texture(),
|
|
|
|
reactive: true,
|
|
|
|
x: realWindow.x,
|
|
|
|
y: realWindow.y });
|
2009-02-10 16:12:58 +00:00
|
|
|
this.actor._delegate = this;
|
2009-01-29 21:21:50 +00:00
|
|
|
this.realWindow = realWindow;
|
2009-02-04 14:50:50 +00:00
|
|
|
this.metaWindow = realWindow.meta_window;
|
2009-09-10 01:14:31 +00:00
|
|
|
this.metaWindow._delegate = this;
|
2009-01-29 21:21:50 +00:00
|
|
|
this.origX = realWindow.x;
|
|
|
|
this.origY = realWindow.y;
|
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
this._stackAbove = null;
|
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
this.actor.connect('button-release-event',
|
|
|
|
Lang.bind(this, this._onButtonRelease));
|
2009-02-10 16:15:59 +00:00
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
this.actor.connect('scroll-event',
|
|
|
|
Lang.bind(this, this._onScroll));
|
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
this.actor.connect('enter-event',
|
|
|
|
Lang.bind(this, this._onEnter));
|
|
|
|
this.actor.connect('leave-event',
|
|
|
|
Lang.bind(this, this._onLeave));
|
|
|
|
this._havePointer = false;
|
2009-02-10 16:15:59 +00:00
|
|
|
|
|
|
|
this._draggable = DND.makeDraggable(this.actor);
|
|
|
|
this._draggable.connect('drag-begin', Lang.bind(this, this._onDragBegin));
|
|
|
|
this._draggable.connect('drag-end', Lang.bind(this, this._onDragEnd));
|
2009-01-29 21:21:50 +00:00
|
|
|
this._inDrag = false;
|
2009-09-28 23:48:03 +00:00
|
|
|
|
|
|
|
this._zooming = false;
|
2009-01-29 21:21:50 +00:00
|
|
|
},
|
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
setStackAbove: function (actor) {
|
|
|
|
this._stackAbove = actor;
|
|
|
|
if (this._inDrag || this._zooming)
|
|
|
|
// We'll fix up the stack after the drag/zooming
|
|
|
|
return;
|
|
|
|
this.actor.raise(this._stackAbove);
|
|
|
|
},
|
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
destroy: function () {
|
|
|
|
this.actor.destroy();
|
|
|
|
},
|
2009-02-10 16:15:59 +00:00
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
_onEnter: function (actor, event) {
|
|
|
|
// If the user drags faster than we can follow, he'll end up
|
|
|
|
// leaving the window temporarily and then re-entering it
|
|
|
|
if (this._inDrag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._havePointer = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onLeave: function (actor, event) {
|
|
|
|
// If the user drags faster than we can follow, he'll end up
|
|
|
|
// leaving the window temporarily and then re-entering it
|
|
|
|
if (this._inDrag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._havePointer = false;
|
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
if (this._zoomStep)
|
|
|
|
this._zoomEnd();
|
|
|
|
},
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
_onScroll : function (actor, event) {
|
|
|
|
let direction = event.get_scroll_direction();
|
|
|
|
if (direction == Clutter.ScrollDirection.UP) {
|
|
|
|
if (this._zoomStep == undefined)
|
|
|
|
this._zoomStart();
|
|
|
|
if (this._zoomStep < 100) {
|
|
|
|
this._zoomStep += SCROLL_SCALE_AMOUNT;
|
|
|
|
this._zoomUpdate();
|
|
|
|
}
|
|
|
|
} else if (direction == Clutter.ScrollDirection.DOWN) {
|
|
|
|
if (this._zoomStep > 0) {
|
|
|
|
this._zoomStep -= SCROLL_SCALE_AMOUNT;
|
|
|
|
this._zoomStep = Math.max(0, this._zoomStep);
|
|
|
|
this._zoomUpdate();
|
|
|
|
}
|
|
|
|
if (this._zoomStep <= 0.0)
|
|
|
|
this._zoomEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_zoomUpdate : function () {
|
|
|
|
[this.actor.x, this.actor.y] = this._zoomGlobalOrig.interpPosition(this._zoomTarget, this._zoomStep / 100);
|
|
|
|
[this.actor.scale_x, this.actor.scale_y] = this._zoomGlobalOrig.interpScale(this._zoomTarget, this._zoomStep / 100);
|
|
|
|
|
|
|
|
let [width, height] = this.actor.get_transformed_size();
|
|
|
|
|
|
|
|
this.actor.x = _clamp(this.actor.x, 0, global.screen_width - width);
|
|
|
|
this.actor.y = _clamp(this.actor.y, Panel.PANEL_HEIGHT, global.screen_height - height);
|
|
|
|
},
|
|
|
|
|
|
|
|
_zoomStart : function () {
|
2009-09-28 23:48:03 +00:00
|
|
|
this._zooming = true;
|
2009-11-12 00:26:52 +00:00
|
|
|
this.emit('zoom-start');
|
2009-09-28 23:48:03 +00:00
|
|
|
|
2009-09-22 19:24:14 +00:00
|
|
|
this._zoomLightbox = new Lightbox.Lightbox(global.stage);
|
2009-09-04 19:25:17 +00:00
|
|
|
|
|
|
|
this._zoomLocalOrig = new ScaledPoint(this.actor.x, this.actor.y, this.actor.scale_x, this.actor.scale_y);
|
|
|
|
this._zoomGlobalOrig = new ScaledPoint();
|
|
|
|
let parent = this._origParent = this.actor.get_parent();
|
2009-09-25 22:48:34 +00:00
|
|
|
let [width, height] = this.actor.get_transformed_size();
|
2009-09-04 19:25:17 +00:00
|
|
|
this._zoomGlobalOrig.setPosition.apply(this._zoomGlobalOrig, this.actor.get_transformed_position());
|
|
|
|
this._zoomGlobalOrig.setScale(width / this.actor.width, height / this.actor.height);
|
|
|
|
|
|
|
|
this.actor.reparent(global.stage);
|
2009-09-22 19:24:14 +00:00
|
|
|
this._zoomLightbox.highlight(this.actor);
|
2009-09-04 19:25:17 +00:00
|
|
|
|
|
|
|
[this.actor.x, this.actor.y] = this._zoomGlobalOrig.getPosition();
|
|
|
|
[this.actor.scale_x, this.actor.scale_y] = this._zoomGlobalOrig.getScale();
|
|
|
|
|
|
|
|
this.actor.raise_top();
|
|
|
|
|
|
|
|
this._zoomTarget = new ScaledPoint(0, 0, 1.0, 1.0);
|
|
|
|
this._zoomTarget.setPosition(this.actor.x - (this.actor.width - width) / 2, this.actor.y - (this.actor.height - height) / 2);
|
|
|
|
this._zoomStep = 0;
|
|
|
|
|
|
|
|
this._hideEventId = Main.overview.connect('hiding', Lang.bind(this, function () { this._zoomEnd(); }));
|
|
|
|
this._zoomUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
_zoomEnd : function () {
|
2009-09-28 23:48:03 +00:00
|
|
|
this._zooming = false;
|
2009-11-12 00:26:52 +00:00
|
|
|
this.emit('zoom-end');
|
2009-09-28 23:48:03 +00:00
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
this.actor.reparent(this._origParent);
|
2009-09-28 23:48:03 +00:00
|
|
|
this.actor.raise(this._stackAbove);
|
2009-09-04 19:25:17 +00:00
|
|
|
|
|
|
|
[this.actor.x, this.actor.y] = this._zoomLocalOrig.getPosition();
|
|
|
|
[this.actor.scale_x, this.actor.scale_y] = this._zoomLocalOrig.getScale();
|
|
|
|
|
2009-09-22 19:24:14 +00:00
|
|
|
this._zoomLightbox.destroy();
|
2009-09-04 19:25:17 +00:00
|
|
|
Main.overview.disconnect(this._hideEventId);
|
|
|
|
|
|
|
|
this._zoomLocalPosition = undefined;
|
|
|
|
this._zoomLocalScale = undefined;
|
|
|
|
this._zoomGlobalPosition = undefined;
|
|
|
|
this._zoomGlobalScale = undefined;
|
|
|
|
this._zoomTargetPosition = undefined;
|
2009-09-22 19:24:14 +00:00
|
|
|
this._zoomStep = undefined;
|
|
|
|
this._zoomLightbox = undefined;
|
2009-01-29 21:21:50 +00:00
|
|
|
},
|
|
|
|
|
2009-02-10 16:15:59 +00:00
|
|
|
_onButtonRelease : function (actor, event) {
|
|
|
|
this.emit('selected', event.get_time());
|
2009-01-29 21:21:50 +00:00
|
|
|
},
|
|
|
|
|
2009-02-10 16:15:59 +00:00
|
|
|
_onDragBegin : function (draggable, time) {
|
|
|
|
this._inDrag = true;
|
2009-07-23 21:36:41 +00:00
|
|
|
this.emit('drag-begin');
|
2009-01-29 21:21:50 +00:00
|
|
|
},
|
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
_onDragEnd : function (draggable, time, snapback) {
|
2009-01-29 21:21:50 +00:00
|
|
|
this._inDrag = false;
|
|
|
|
|
2009-02-10 16:15:59 +00:00
|
|
|
// Most likely, the clone is going to move away from the
|
|
|
|
// pointer now. But that won't cause a leave-event, so
|
|
|
|
// do this by hand. Of course, if the window only snaps
|
|
|
|
// back a short distance, this might be wrong, but it's
|
|
|
|
// better to have the label mysteriously missing than
|
|
|
|
// mysteriously present
|
|
|
|
this._havePointer = false;
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
// 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)
|
|
|
|
this.actor.raise(this._stackAbove);
|
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
this.emit('drag-end');
|
2009-01-29 21:21:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(WindowClone.prototype);
|
|
|
|
|
|
|
|
|
|
|
|
function DesktopClone(window) {
|
|
|
|
this._init(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
DesktopClone.prototype = {
|
|
|
|
_init : function(window) {
|
|
|
|
if (window) {
|
2009-02-23 19:42:00 +00:00
|
|
|
this.actor = new Clutter.Clone({ source: window.get_texture(),
|
|
|
|
reactive: true });
|
2009-01-29 21:21:50 +00:00
|
|
|
} else {
|
|
|
|
this.actor = new Clutter.Rectangle({ color: global.stage.color,
|
|
|
|
reactive: true,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_height });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor.connect('button-release-event',
|
|
|
|
Lang.bind(this, this._onButtonRelease));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onButtonRelease : function (actor, event) {
|
|
|
|
this.emit('selected', event.get_time());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(DesktopClone.prototype);
|
|
|
|
|
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
/**
|
|
|
|
* @windowClone: Corresponding window clone
|
|
|
|
* @parentActor: The actor which will be the parent of all overlay items
|
|
|
|
* such as app icon and window caption
|
|
|
|
*/
|
|
|
|
function WindowOverlay(windowClone, parentActor) {
|
|
|
|
this._init(windowClone, parentActor);
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowOverlay.prototype = {
|
|
|
|
_init : function(windowClone, parentActor) {
|
|
|
|
let metaWindow = windowClone.metaWindow;
|
|
|
|
|
2009-11-20 00:39:00 +00:00
|
|
|
this._windowClone = windowClone;
|
2009-11-12 00:26:52 +00:00
|
|
|
this._parentActor = parentActor;
|
|
|
|
|
|
|
|
let title = new St.Label({ style_class: "window-caption",
|
|
|
|
text : metaWindow.title });
|
|
|
|
title.connect('style-changed',
|
|
|
|
Lang.bind(this, this._onStyleChanged));
|
|
|
|
title.clutter_text.ellipsize = Pango.EllipsizeMode.END;
|
|
|
|
title._spacing = 0;
|
|
|
|
|
|
|
|
let button = new St.Bin({ style_class: "window-close",
|
|
|
|
reactive: true });
|
|
|
|
button.connect('style-changed',
|
|
|
|
Lang.bind(this, this._onStyleChanged));
|
|
|
|
button._overlap = 0;
|
|
|
|
|
2009-11-21 05:46:02 +00:00
|
|
|
windowClone.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
2009-11-12 00:26:52 +00:00
|
|
|
windowClone.actor.connect('notify::allocation',
|
|
|
|
Lang.bind(this, this._positionItems));
|
|
|
|
windowClone.actor.connect('enter-event',
|
|
|
|
Lang.bind(this, this._onEnter));
|
|
|
|
windowClone.actor.connect('leave-event',
|
|
|
|
Lang.bind(this, this._onLeave));
|
|
|
|
|
2009-11-20 00:39:00 +00:00
|
|
|
this._idleToggleCloseId = 0;
|
2009-11-12 00:26:52 +00:00
|
|
|
button.connect('button-release-event',
|
2009-11-21 05:46:02 +00:00
|
|
|
Lang.bind(this, this._closeWindow));
|
2009-11-12 00:26:52 +00:00
|
|
|
|
2009-11-21 05:46:02 +00:00
|
|
|
this._windowAddedId = 0;
|
2009-11-12 00:26:52 +00:00
|
|
|
windowClone.connect('zoom-start', Lang.bind(this, this.hide));
|
|
|
|
windowClone.connect('zoom-end', Lang.bind(this, this.show));
|
|
|
|
|
|
|
|
button.hide();
|
|
|
|
|
|
|
|
this.title = title;
|
|
|
|
this.closeButton = button;
|
|
|
|
|
|
|
|
parentActor.add_actor(this.title);
|
|
|
|
parentActor.add_actor(this.closeButton);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.closeButton.hide();
|
|
|
|
this.title.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
2009-11-23 21:42:02 +00:00
|
|
|
let [child, x, y, mask] = Gdk.Screen.get_default().get_root_window().get_pointer();
|
|
|
|
let actor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE,
|
|
|
|
x, y);
|
|
|
|
if (actor == this._windowClone.actor) {
|
|
|
|
this.closeButton.show();
|
|
|
|
}
|
2009-11-12 00:26:52 +00:00
|
|
|
this.title.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
fadeIn: function() {
|
|
|
|
this.title.opacity = 0;
|
|
|
|
this.title.show();
|
|
|
|
this.title.raise_top();
|
|
|
|
Tweener.addTween(this.title,
|
|
|
|
{ opacity: 255,
|
|
|
|
time: Overview.ANIMATION_TIME,
|
|
|
|
transition: "easeOutQuad" });
|
|
|
|
},
|
|
|
|
|
|
|
|
chromeWidth: function () {
|
|
|
|
return this.closeButton.width - this.closeButton._overlap;
|
|
|
|
},
|
|
|
|
|
|
|
|
chromeHeight: function () {
|
|
|
|
return this.closeButton.height - this.closeButton._overlap +
|
|
|
|
this.title.height + this.title._spacing;
|
|
|
|
},
|
|
|
|
|
|
|
|
_positionItems: function(win) {
|
|
|
|
let button = this.closeButton;
|
|
|
|
let title = this.title;
|
|
|
|
|
|
|
|
let [x, y] = win.get_transformed_position();
|
|
|
|
let [w, h] = win.get_transformed_size();
|
|
|
|
|
|
|
|
let buttonX = x + w - button._overlap;
|
|
|
|
let buttonY = y - button.height + button._overlap;
|
|
|
|
button.set_position(Math.floor(buttonX), Math.floor(buttonY));
|
|
|
|
|
|
|
|
if (!title.fullWidth)
|
|
|
|
title.fullWidth = title.width;
|
|
|
|
title.width = Math.min(title.fullWidth, w);
|
|
|
|
|
|
|
|
let titleX = x + (w - title.width) / 2;
|
|
|
|
let titleY = y + h + title._spacing;
|
|
|
|
title.set_position(Math.floor(titleX), Math.floor(titleY));
|
|
|
|
},
|
|
|
|
|
2009-11-21 05:46:02 +00:00
|
|
|
_closeWindow: function(actor, event) {
|
|
|
|
let metaWindow = this._windowClone.metaWindow;
|
|
|
|
this._workspace = metaWindow.get_workspace();
|
|
|
|
|
|
|
|
this._windowAddedId = this._workspace.connect('window-added',
|
|
|
|
Lang.bind(this,
|
|
|
|
this._onWindowAdded));
|
|
|
|
|
|
|
|
metaWindow.delete(event.get_time());
|
|
|
|
},
|
|
|
|
|
|
|
|
_onWindowAdded: function(workspace, win) {
|
|
|
|
let metaWindow = this._windowClone.metaWindow;
|
|
|
|
|
|
|
|
if (win.get_transient_for() == metaWindow) {
|
|
|
|
workspace.disconnect(this._windowAddedId);
|
|
|
|
this._windowAddedId = 0;
|
|
|
|
|
|
|
|
// use an idle handler to avoid mapping problems -
|
|
|
|
// see comment in Workspace._windowAdded
|
|
|
|
Mainloop.idle_add(Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._windowClone.emit('selected');
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
|
|
|
if (this._windowAddedId > 0) {
|
|
|
|
this._workspace.disconnect(this._windowAddedId);
|
|
|
|
this._windowAddedId = 0;
|
|
|
|
}
|
|
|
|
if (this._idleToggleCloseId > 0) {
|
|
|
|
Mainloop.source_remove(this._idleToggleCloseId);
|
|
|
|
this._idleToggleCloseId = 0;
|
|
|
|
}
|
|
|
|
this.title.destroy();
|
|
|
|
this.closeButton.destroy();
|
|
|
|
},
|
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
_onEnter: function() {
|
|
|
|
this.closeButton.raise_top();
|
|
|
|
this.closeButton.show();
|
2009-11-20 00:39:00 +00:00
|
|
|
this.emit('show-close-button');
|
2009-11-12 00:26:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onLeave: function() {
|
2009-11-20 00:39:00 +00:00
|
|
|
if (this._idleToggleCloseId == 0)
|
|
|
|
this._idleToggleCloseId = Mainloop.timeout_add(750, Lang.bind(this, this._idleToggleCloseButton));
|
|
|
|
},
|
|
|
|
|
|
|
|
_idleToggleCloseButton: function() {
|
|
|
|
this._idleToggleCloseId = 0;
|
|
|
|
let [child, x, y, mask] = Gdk.Screen.get_default().get_root_window().get_pointer();
|
|
|
|
let actor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE,
|
|
|
|
x, y);
|
|
|
|
if (actor != this._windowClone.actor && actor != this.closeButton) {
|
|
|
|
this.closeButton.hide();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
hideCloseButton: function() {
|
|
|
|
if (this._idleToggleCloseId > 0) {
|
|
|
|
Mainloop.source_remove(this._idleToggleCloseId);
|
|
|
|
this._idleToggleCloseId = 0;
|
|
|
|
}
|
2009-11-12 00:26:52 +00:00
|
|
|
this.closeButton.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStyleChanged: function() {
|
|
|
|
let titleNode = this.title.get_theme_node();
|
|
|
|
|
|
|
|
let [success, len] = titleNode.get_length('-shell-caption-spacing',
|
|
|
|
false);
|
|
|
|
if (success)
|
|
|
|
this.title._spacing = len;
|
|
|
|
|
|
|
|
let closeNode = this.closeButton.get_theme_node();
|
|
|
|
|
|
|
|
let [success, len] = closeNode.get_length('-shell-close-overlap',
|
|
|
|
false);
|
|
|
|
if (success)
|
|
|
|
this.closeButton._overlap = len;
|
|
|
|
|
|
|
|
this._parentActor.queue_relayout();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(WindowOverlay.prototype);
|
|
|
|
|
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
/**
|
|
|
|
* @workspaceNum: Workspace index
|
|
|
|
* @parentActor: The actor which will be the parent of this workspace;
|
|
|
|
* we need this in order to add chrome such as the icons
|
|
|
|
* on top of the windows without having them be scaled.
|
|
|
|
*/
|
|
|
|
function Workspace(workspaceNum, parentActor) {
|
|
|
|
this._init(workspaceNum, parentActor);
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Workspace.prototype = {
|
2009-07-23 21:36:41 +00:00
|
|
|
_init : function(workspaceNum, parentActor) {
|
2009-01-23 19:21:20 +00:00
|
|
|
this.workspaceNum = workspaceNum;
|
2009-02-04 14:50:50 +00:00
|
|
|
this._metaWorkspace = global.screen.get_workspace_by_index(workspaceNum);
|
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
this.parentActor = parentActor;
|
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
this.actor = new Clutter.Group();
|
2009-02-10 16:15:59 +00:00
|
|
|
this.actor._delegate = this;
|
2009-08-13 02:07:10 +00:00
|
|
|
// Auto-sizing is unreliable in the presence of ClutterClone, so rather than
|
|
|
|
// implicitly counting on the workspace actor to be sized to the size of the
|
|
|
|
// included desktop actor clone, set the size explicitly to the screen size.
|
|
|
|
// See http://bugzilla.openedhand.com/show_bug.cgi?id=1755
|
|
|
|
this.actor.width = global.screen_width;
|
|
|
|
this.actor.height = global.screen_height;
|
2009-01-21 21:12:49 +00:00
|
|
|
this.scale = 1.0;
|
2008-12-22 21:51:34 +00:00
|
|
|
|
|
|
|
let windows = global.get_windows().filter(this._isMyWindow, this);
|
|
|
|
|
|
|
|
// Find the desktop window
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
if (windows[i].get_window_type() == Meta.WindowType.DESKTOP) {
|
2009-01-29 21:21:50 +00:00
|
|
|
this._desktop = new DesktopClone(windows[i]);
|
2008-12-22 21:51:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there wasn't one, fake it
|
|
|
|
if (!this._desktop)
|
2009-01-29 21:21:50 +00:00
|
|
|
this._desktop = new DesktopClone();
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
this._desktop.connect('selected',
|
2009-02-04 14:50:50 +00:00
|
|
|
Lang.bind(this,
|
|
|
|
function(clone, time) {
|
|
|
|
this._metaWorkspace.activate(time);
|
2009-08-11 11:46:10 +00:00
|
|
|
Main.overview.hide();
|
2009-02-04 14:50:50 +00:00
|
|
|
}));
|
2009-01-29 21:21:50 +00:00
|
|
|
this.actor.add_actor(this._desktop.actor);
|
2008-12-22 21:51:34 +00:00
|
|
|
|
|
|
|
// Create clones for remaining windows that should be
|
2009-08-11 11:46:10 +00:00
|
|
|
// visible in the Overview
|
2008-12-22 21:51:34 +00:00
|
|
|
this._windows = [this._desktop];
|
2009-11-12 00:26:52 +00:00
|
|
|
this._windowOverlays = [ null ];
|
2008-12-22 21:51:34 +00:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2009-08-11 11:46:10 +00:00
|
|
|
if (this._isOverviewWindow(windows[i])) {
|
2009-01-23 19:21:20 +00:00
|
|
|
this._addWindowClone(windows[i]);
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2009-09-01 18:15:29 +00:00
|
|
|
// A filter for what windows we display
|
|
|
|
this._showOnlyWindows = null;
|
|
|
|
|
2009-02-04 14:50:50 +00:00
|
|
|
// 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));
|
|
|
|
|
2008-12-22 22:06:47 +00:00
|
|
|
this._removeButton = null;
|
|
|
|
this._visible = false;
|
2009-01-21 21:12:49 +00:00
|
|
|
|
|
|
|
this._frame = null;
|
2009-02-03 22:58:33 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
this.leavingOverview = false;
|
2008-12-22 22:06:47 +00:00
|
|
|
},
|
|
|
|
|
2009-02-04 14:50:50 +00:00
|
|
|
updateRemovable : function() {
|
|
|
|
let removable = (this._windows.length == 1 /* just desktop */ &&
|
2009-07-14 12:37:21 +00:00
|
|
|
this.workspaceNum != 0 &&
|
2009-02-04 14:50:50 +00:00
|
|
|
this.workspaceNum == global.screen.n_workspaces - 1);
|
2008-12-22 22:06:47 +00:00
|
|
|
|
|
|
|
if (removable) {
|
|
|
|
if (this._removeButton)
|
|
|
|
return;
|
|
|
|
|
2009-09-01 15:56:41 +00:00
|
|
|
this._removeButton = new Clutter.Texture({ width: Overview.addRemoveButtonSize,
|
|
|
|
height: Overview.addRemoveButtonSize,
|
2008-12-22 22:06:47 +00:00
|
|
|
reactive: true
|
|
|
|
});
|
|
|
|
this._removeButton.set_from_file(global.imagedir + "remove-workspace.svg");
|
2009-02-02 20:54:33 +00:00
|
|
|
this._removeButton.connect('button-release-event', Lang.bind(this, this._removeSelf));
|
2008-12-22 22:06:47 +00:00
|
|
|
|
|
|
|
this.actor.add_actor(this._removeButton);
|
2009-01-21 20:35:20 +00:00
|
|
|
this._adjustRemoveButton();
|
|
|
|
this._adjustRemoveButtonId = this.actor.connect('notify::scale-x', Lang.bind(this, this._adjustRemoveButton));
|
2008-12-22 22:06:47 +00:00
|
|
|
|
|
|
|
if (this._visible) {
|
|
|
|
this._removeButton.set_opacity(0);
|
|
|
|
Tweener.addTween(this._removeButton,
|
|
|
|
{ opacity: 255,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 22:06:47 +00:00
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!this._removeButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._visible) {
|
|
|
|
Tweener.addTween(this._removeButton,
|
|
|
|
{ opacity: 0,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 22:06:47 +00:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: this._removeRemoveButton,
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
2009-01-21 20:35:20 +00:00
|
|
|
} else
|
|
|
|
this._removeRemoveButton();
|
2008-12-22 22:06:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
_lookupIndex: function (metaWindow) {
|
2009-07-31 21:20:26 +00:00
|
|
|
let index, clone;
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
if (this._windows[i].metaWindow == metaWindow) {
|
2009-07-23 21:36:41 +00:00
|
|
|
return i;
|
2009-07-31 21:20:26 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-23 21:36:41 +00:00
|
|
|
return -1;
|
2009-07-31 21:20:26 +00:00
|
|
|
},
|
|
|
|
|
2009-09-11 16:47:53 +00:00
|
|
|
/**
|
|
|
|
* lookupCloneForMetaWindow:
|
|
|
|
* @metaWindow: A #MetaWindow
|
|
|
|
*
|
|
|
|
* Given a #MetaWindow instance, find the WindowClone object
|
|
|
|
* which represents it in the workspaces display.
|
|
|
|
*/
|
2009-07-31 21:20:26 +00:00
|
|
|
lookupCloneForMetaWindow: function (metaWindow) {
|
2009-07-23 21:36:41 +00:00
|
|
|
let index = this._lookupIndex (metaWindow);
|
|
|
|
return index < 0 ? null : this._windows[index];
|
2009-07-31 21:20:26 +00:00
|
|
|
},
|
|
|
|
|
2009-09-01 18:15:29 +00:00
|
|
|
containsMetaWindow: function (metaWindow) {
|
|
|
|
return this._lookupIndex(metaWindow) >= 0;
|
|
|
|
},
|
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
setShowOnlyWindows: function(showOnlyWindows, reposition) {
|
2009-09-01 18:15:29 +00:00
|
|
|
this._showOnlyWindows = showOnlyWindows;
|
2009-09-11 16:39:59 +00:00
|
|
|
this._resetCloneVisibility();
|
|
|
|
if (reposition)
|
|
|
|
this.positionWindows(false);
|
2009-09-01 18:15:29 +00:00
|
|
|
},
|
|
|
|
|
2009-09-08 22:34:04 +00:00
|
|
|
/**
|
|
|
|
* setLightboxMode:
|
|
|
|
* @showLightbox: If true, dim background and allow highlighting a specific window
|
|
|
|
*
|
|
|
|
* This function also resets the highlighted window state.
|
|
|
|
*/
|
2009-09-01 18:15:29 +00:00
|
|
|
setLightboxMode: function (showLightbox) {
|
2009-09-08 22:34:04 +00:00
|
|
|
if (showLightbox) {
|
2009-09-22 19:24:14 +00:00
|
|
|
this._lightbox = new Lightbox.Lightbox(this.actor);
|
2009-09-08 22:34:04 +00:00
|
|
|
} else {
|
2009-09-22 19:24:14 +00:00
|
|
|
this._lightbox.destroy();
|
|
|
|
this._lightbox = null;
|
2009-09-08 22:34:04 +00:00
|
|
|
}
|
2009-11-15 01:24:43 +00:00
|
|
|
if (this._frame) {
|
|
|
|
this._frame.set_opacity(showLightbox ? 150 : 255);
|
|
|
|
}
|
2009-09-01 18:15:29 +00:00
|
|
|
},
|
|
|
|
|
2009-09-11 16:47:53 +00:00
|
|
|
/**
|
|
|
|
* setHighlightWindow:
|
|
|
|
* @metaWindow: A #MetaWindow
|
|
|
|
*
|
|
|
|
* Draw the user's attention to the given window @metaWindow.
|
|
|
|
*/
|
2009-09-01 18:15:29 +00:00
|
|
|
setHighlightWindow: function (metaWindow) {
|
2009-09-22 19:24:14 +00:00
|
|
|
let actor;
|
2009-09-01 18:15:29 +00:00
|
|
|
if (metaWindow != null) {
|
|
|
|
let clone = this.lookupCloneForMetaWindow(metaWindow);
|
2009-09-22 19:24:14 +00:00
|
|
|
actor = clone.actor;
|
2009-09-01 18:15:29 +00:00
|
|
|
}
|
2009-09-22 19:24:14 +00:00
|
|
|
this._lightbox.highlight(actor);
|
2009-09-01 18:15:29 +00:00
|
|
|
},
|
|
|
|
|
2009-01-21 20:35:20 +00:00
|
|
|
_adjustRemoveButton : function() {
|
|
|
|
this._removeButton.set_scale(1.0 / this.actor.scale_x,
|
|
|
|
1.0 / this.actor.scale_y);
|
|
|
|
this._removeButton.set_position(
|
|
|
|
(this.actor.width - this._removeButton.width / this.actor.scale_x) / 2,
|
|
|
|
(this.actor.height - this._removeButton.height / this.actor.scale_y) / 2);
|
|
|
|
},
|
|
|
|
|
2008-12-22 22:06:47 +00:00
|
|
|
_removeRemoveButton : function() {
|
|
|
|
this._removeButton.destroy();
|
|
|
|
this._removeButton = null;
|
2009-01-21 20:35:20 +00:00
|
|
|
this.actor.disconnect(this._adjustRemoveButtonId);
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
2009-01-21 21:12:49 +00:00
|
|
|
// Mark the workspace selected/not-selected
|
|
|
|
setSelected : function(selected) {
|
2009-08-09 23:48:54 +00:00
|
|
|
// Don't draw a frame if we only have one workspace
|
|
|
|
if (selected && global.screen.n_workspaces > 1) {
|
2009-01-21 21:12:49 +00:00
|
|
|
if (this._frame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// FIXME: do something cooler-looking using clutter-cairo
|
|
|
|
this._frame = new Clutter.Rectangle({ color: FRAME_COLOR });
|
|
|
|
this.actor.add_actor(this._frame);
|
2009-01-29 21:21:50 +00:00
|
|
|
this._frame.set_position(this._desktop.actor.x - FRAME_SIZE / this.actor.scale_x,
|
|
|
|
this._desktop.actor.y - FRAME_SIZE / this.actor.scale_y);
|
|
|
|
this._frame.set_size(this._desktop.actor.width + 2 * FRAME_SIZE / this.actor.scale_x,
|
|
|
|
this._desktop.actor.height + 2 * FRAME_SIZE / this.actor.scale_y);
|
2009-01-21 21:12:49 +00:00
|
|
|
this._frame.lower_bottom();
|
|
|
|
|
2009-08-08 04:31:47 +00:00
|
|
|
this._framePosHandler = this.actor.connect('notify::scale-x', Lang.bind(this, this._updateFramePosition));
|
2009-01-21 21:12:49 +00:00
|
|
|
} else {
|
|
|
|
if (!this._frame)
|
|
|
|
return;
|
|
|
|
this.actor.disconnect(this._framePosHandler);
|
|
|
|
this._frame.destroy();
|
|
|
|
this._frame = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateFramePosition : function() {
|
2009-01-29 21:21:50 +00:00
|
|
|
this._frame.set_position(this._desktop.actor.x - FRAME_SIZE / this.actor.scale_x,
|
|
|
|
this._desktop.actor.y - FRAME_SIZE / this.actor.scale_y);
|
|
|
|
this._frame.set_size(this._desktop.actor.width + 2 * FRAME_SIZE / this.actor.scale_x,
|
|
|
|
this._desktop.actor.height + 2 * FRAME_SIZE / this.actor.scale_y);
|
2009-01-21 21:12:49 +00:00
|
|
|
},
|
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
_isCloneVisible: function(clone) {
|
|
|
|
return this._showOnlyWindows == null || (clone.metaWindow in this._showOnlyWindows);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _getVisibleClones:
|
|
|
|
*
|
|
|
|
* Returns a list WindowClone objects where the clone isn't filtered
|
|
|
|
* out by any application filter. The clone for the desktop is excluded.
|
|
|
|
* The returned array will always be newly allocated; it is not in any
|
|
|
|
* defined order, and thus it's convenient to call .sort() with your
|
|
|
|
* choice of sorting function.
|
|
|
|
*/
|
|
|
|
_getVisibleClones: function() {
|
|
|
|
let visible = [];
|
|
|
|
|
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
|
|
|
|
|
|
|
if (!this._isCloneVisible(clone))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
visible.push(clone);
|
|
|
|
}
|
|
|
|
return visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getVisibleWindows: function() {
|
|
|
|
return this._getVisibleClones().map(function (clone) { return clone.metaWindow; });
|
|
|
|
},
|
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
_resetCloneVisibility: function () {
|
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
2009-11-12 00:26:52 +00:00
|
|
|
let overlay = this._windowOverlays[i];
|
2009-09-11 16:39:59 +00:00
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
if (!this._isCloneVisible(clone)) {
|
2009-11-12 00:26:52 +00:00
|
|
|
clone.actor.hide();
|
|
|
|
overlay.hide();
|
2009-09-11 16:39:59 +00:00
|
|
|
} else {
|
2009-11-12 00:26:52 +00:00
|
|
|
clone.actor.show();
|
2009-09-11 16:39:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-18 19:08:56 +00:00
|
|
|
// Only use this for n <= 20 say
|
|
|
|
_factorial: function(n) {
|
|
|
|
let result = 1;
|
|
|
|
for (let i = 2; i <= n; i++)
|
|
|
|
result *= i;
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _permutation:
|
|
|
|
* @permutationIndex: An integer from [0, list.length!)
|
|
|
|
* @list: (inout): Array of objects to permute; will be modified in place
|
|
|
|
*
|
|
|
|
* Given an integer between 0 and length of array, re-order the array in-place
|
|
|
|
* into a permutation denoted by the index.
|
|
|
|
*/
|
|
|
|
_permutation: function(permutationIndex, list) {
|
|
|
|
for (let j = 2; j <= list.length; j++) {
|
|
|
|
let firstIndex = (permutationIndex % j);
|
|
|
|
let secondIndex = j - 1;
|
|
|
|
// Swap
|
|
|
|
let tmp = list[firstIndex];
|
|
|
|
list[firstIndex] = list[secondIndex];
|
|
|
|
list[secondIndex] = tmp;
|
|
|
|
permutationIndex = Math.floor(permutationIndex / j);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _forEachPermutations:
|
|
|
|
* @list: Array
|
|
|
|
* @func: Function which takes a single array argument
|
|
|
|
*
|
|
|
|
* Call @func with each permutation of @list as an argument.
|
|
|
|
*/
|
|
|
|
_forEachPermutations: function(list, func) {
|
|
|
|
let nCombinations = this._factorial(list.length);
|
|
|
|
for (let i = 0; i < nCombinations; i++) {
|
|
|
|
let listCopy = list.concat();
|
|
|
|
this._permutation(i, listCopy);
|
|
|
|
func(listCopy);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _computeWindowMotion:
|
|
|
|
* @metaWindow: A #MetaWindow
|
|
|
|
* @slot: An element of #POSITIONS
|
|
|
|
* @slotGeometry: Layout of @slot
|
|
|
|
*
|
|
|
|
* Returns a number corresponding to how much perceived motion
|
|
|
|
* would be involved in moving the window to the given slot.
|
|
|
|
* Currently this is the square of the distance between the
|
|
|
|
* centers.
|
|
|
|
*/
|
|
|
|
_computeWindowMotion: function (metaWindow, slot, slotGeometry) {
|
|
|
|
let rect = new Meta.Rectangle();
|
|
|
|
metaWindow.get_outer_rect(rect);
|
|
|
|
|
|
|
|
let [slotX, slotY, slotWidth, slotHeight] = slotGeometry;
|
|
|
|
let distanceSquared;
|
|
|
|
let xDelta, yDelta;
|
|
|
|
|
|
|
|
xDelta = (rect.x + rect.width / 2) - (slotX + slotWidth / 2);
|
|
|
|
yDelta = (rect.y + rect.height / 2) - (slotY + slotHeight / 2);
|
|
|
|
distanceSquared = xDelta * xDelta + yDelta * yDelta;
|
|
|
|
|
|
|
|
return distanceSquared;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _orderWindowsPermutations:
|
|
|
|
*
|
|
|
|
* Iterate over all permutations of the windows, and determine the
|
|
|
|
* permutation which has the least total motion.
|
|
|
|
*/
|
|
|
|
_orderWindowsPermutations: function (windows, slots, slotGeometries) {
|
|
|
|
let minimumMotionPermutation = null;
|
|
|
|
let minimumMotion = -1;
|
|
|
|
let permIndex = 0;
|
|
|
|
this._forEachPermutations(windows, Lang.bind(this, function (permutation) {
|
|
|
|
let motion = 0;
|
|
|
|
for (let i = 0; i < permutation.length; i++) {
|
|
|
|
let metaWindow = permutation[i];
|
|
|
|
let slot = slots[i];
|
|
|
|
let slotAbsGeometry = slotGeometries[i];
|
|
|
|
|
|
|
|
let delta = this._computeWindowMotion(metaWindow, slot, slotAbsGeometry);
|
|
|
|
|
|
|
|
motion += delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minimumMotionPermutation == null || motion < minimumMotion) {
|
|
|
|
minimumMotionPermutation = permutation;
|
|
|
|
minimumMotion = motion;
|
|
|
|
}
|
|
|
|
permIndex++;
|
|
|
|
}));
|
|
|
|
return minimumMotionPermutation;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _orderWindowsGreedy:
|
|
|
|
*
|
|
|
|
* Iterate over available slots in order, placing into each one the window
|
|
|
|
* we find with the smallest motion to that slot.
|
|
|
|
*/
|
|
|
|
_orderWindowsGreedy: function(windows, slots, slotGeometries) {
|
|
|
|
let result = [];
|
|
|
|
let slotIndex = 0;
|
|
|
|
// Copy since we mutate below
|
|
|
|
let windowCopy = windows.concat();
|
|
|
|
for (let i = 0; i < slots.length; i++) {
|
|
|
|
let slot = slots[i];
|
|
|
|
let slotGeometry = slotGeometries[i];
|
|
|
|
let minimumMotionIndex = -1;
|
|
|
|
let minimumMotion = -1;
|
|
|
|
for (let j = 0; j < windowCopy.length; j++) {
|
|
|
|
let metaWindow = windowCopy[j];
|
|
|
|
let delta = this._computeWindowMotion(metaWindow, slot, slotGeometry);
|
|
|
|
if (minimumMotionIndex == -1 || delta < minimumMotion) {
|
|
|
|
minimumMotionIndex = j;
|
|
|
|
minimumMotion = delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push(windowCopy[minimumMotionIndex]);
|
|
|
|
windowCopy.splice(minimumMotionIndex, 1);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _orderWindowsByMotionAndStartup:
|
|
|
|
* @windows: Array of #MetaWindow
|
|
|
|
* @slots: Array of slots
|
|
|
|
*
|
|
|
|
* Returns a copy of @windows, ordered in such a way that they require least motion
|
|
|
|
* to move to the final screen coordinates of @slots. Ties are broken in a stable
|
|
|
|
* fashion by the order in which the windows were created.
|
|
|
|
*/
|
|
|
|
_orderWindowsByMotionAndStartup: function(windows, slots) {
|
|
|
|
windows.sort(function(w1, w2) {
|
|
|
|
return w2.get_stable_sequence() - w1.get_stable_sequence();
|
|
|
|
});
|
|
|
|
let slotGeometries = slots.map(Lang.bind(this, this._getSlotAbsoluteGeometry));
|
|
|
|
if (windows.length <= POSITIONING_PERMUTATIONS_MAX)
|
|
|
|
return this._orderWindowsPermutations(windows, slots, slotGeometries);
|
|
|
|
else
|
|
|
|
return this._orderWindowsGreedy(windows, slots, slotGeometries);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _getSlotRelativeGeometry:
|
|
|
|
* @slot: A layout slot
|
|
|
|
*
|
|
|
|
* Returns: the workspace-relative [x, y, width, height]
|
|
|
|
* of a given window layout slot.
|
|
|
|
*/
|
|
|
|
_getSlotRelativeGeometry: function(slot) {
|
|
|
|
let [xCenter, yCenter, fraction] = slot;
|
|
|
|
|
|
|
|
let width = global.screen_width * fraction;
|
|
|
|
let height = global.screen_height * fraction;
|
|
|
|
|
|
|
|
let x = xCenter * global.screen_width - width / 2;
|
|
|
|
let y = yCenter * global.screen_height - height / 2;
|
|
|
|
|
|
|
|
return [x, y, width, height];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _getSlotAbsoluteGeometry:
|
|
|
|
* @slot: A layout slot
|
|
|
|
*
|
|
|
|
* Returns: the screen coordiantes [x, y, width, height]
|
|
|
|
* of a given window layout slot.
|
|
|
|
*/
|
|
|
|
_getSlotAbsoluteGeometry: function(slot) {
|
|
|
|
let [x, y, width, height] = this._getSlotRelativeGeometry(slot);
|
|
|
|
return [ this.gridX + x, this.gridY + y,
|
|
|
|
this.scale * width, this.scale * height];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _computeWindowRelativeLayout:
|
|
|
|
* @metaWindow: A #MetaWindow
|
|
|
|
* @slot: A layout slot
|
|
|
|
*
|
|
|
|
* Given a window and slot to fit it in, compute its
|
|
|
|
* workspace-relative [x, y, scale] where scale applies
|
|
|
|
* to both X and Y directions.
|
|
|
|
*/
|
|
|
|
_computeWindowRelativeLayout: function(metaWindow, slot) {
|
|
|
|
let [xCenter, yCenter, fraction] = slot;
|
|
|
|
|
|
|
|
xCenter = xCenter * global.screen_width;
|
|
|
|
yCenter = yCenter * global.screen_height;
|
|
|
|
|
|
|
|
let rect = new Meta.Rectangle();
|
|
|
|
metaWindow.get_outer_rect(rect);
|
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
let chromeHeight = this._windowOverlays[1].chromeHeight() / this.scale;
|
|
|
|
let chromeWidth = this._windowOverlays[1].chromeWidth() / this.scale;
|
|
|
|
|
|
|
|
let desiredWidth = (global.screen_width - chromeWidth) * fraction;
|
|
|
|
let desiredHeight = (global.screen_height - chromeHeight) * fraction;
|
|
|
|
let scale = Math.min(desiredWidth / (rect.width + chromeWidth),
|
|
|
|
desiredHeight / (rect.height + chromeHeight),
|
2009-09-18 19:08:56 +00:00
|
|
|
1.0 / this.scale);
|
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
let x = xCenter - 0.5 * scale * (rect.width + chromeWidth);
|
|
|
|
let y = yCenter - 0.5 * scale * (rect.height + chromeHeight);
|
2009-09-18 19:08:56 +00:00
|
|
|
|
|
|
|
return [x, y, scale];
|
|
|
|
},
|
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
/**
|
|
|
|
* positionWindows:
|
|
|
|
* @workspaceZooming: If true, then the workspace is moving at the same time and we need to take that into account.
|
|
|
|
*/
|
2009-08-08 04:45:06 +00:00
|
|
|
positionWindows : function(workspaceZooming) {
|
2009-09-01 18:15:29 +00:00
|
|
|
let totalVisible = 0;
|
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
let visibleWindows = this._getVisibleWindows();
|
2009-09-01 18:15:29 +00:00
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
// Start the animations
|
2009-09-18 19:08:56 +00:00
|
|
|
let slots = this._computeAllWindowSlots(visibleWindows.length);
|
|
|
|
visibleWindows = this._orderWindowsByMotionAndStartup(visibleWindows, slots);
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2009-09-18 19:08:56 +00:00
|
|
|
for (let i = 0; i < visibleWindows.length; i++) {
|
|
|
|
let slot = slots[i];
|
|
|
|
let metaWindow = visibleWindows[i];
|
|
|
|
let mainIndex = this._lookupIndex(metaWindow);
|
|
|
|
let clone = metaWindow._delegate;
|
2009-11-12 00:26:52 +00:00
|
|
|
let overlay = this._windowOverlays[mainIndex];
|
2009-09-01 18:15:29 +00:00
|
|
|
|
2009-09-18 19:08:56 +00:00
|
|
|
let [x, y, scale] = this._computeWindowRelativeLayout(metaWindow, slot);
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
overlay.hide();
|
2009-09-18 19:08:56 +00:00
|
|
|
Tweener.addTween(clone.actor,
|
|
|
|
{ x: x,
|
|
|
|
y: y,
|
2009-02-10 16:12:58 +00:00
|
|
|
scale_x: scale,
|
|
|
|
scale_y: scale,
|
|
|
|
workspace_relative: workspaceZooming ? this : null,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-07-23 21:36:41 +00:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: Lang.bind(this, function() {
|
2009-11-12 00:26:52 +00:00
|
|
|
overlay.fadeIn();
|
2009-07-23 21:36:41 +00:00
|
|
|
})
|
2009-02-10 16:12:58 +00:00
|
|
|
});
|
2009-01-23 19:21:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
syncStacking: function(stackIndices) {
|
|
|
|
let desktopClone = this._windows[0];
|
|
|
|
|
|
|
|
let visibleClones = this._getVisibleClones();
|
|
|
|
visibleClones.sort(function (a, b) { return stackIndices[a.metaWindow.get_stable_sequence()] - stackIndices[b.metaWindow.get_stable_sequence()]; });
|
|
|
|
|
|
|
|
for (let i = 0; i < visibleClones.length; i++) {
|
|
|
|
let clone = visibleClones[i];
|
|
|
|
let metaWindow = clone.metaWindow;
|
|
|
|
if (i == 0) {
|
|
|
|
clone.setStackAbove(desktopClone.actor);
|
|
|
|
} else {
|
|
|
|
let previousClone = visibleClones[i - 1];
|
|
|
|
clone.setStackAbove(previousClone.actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
_fadeInAllOverlays: function() {
|
2009-07-23 21:36:41 +00:00
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
2009-11-12 00:26:52 +00:00
|
|
|
let overlay = this._windowOverlays[i];
|
2009-09-01 18:15:29 +00:00
|
|
|
if (this._showOnlyWindows != null && !(clone.metaWindow in this._showOnlyWindows))
|
|
|
|
continue;
|
2009-11-12 00:26:52 +00:00
|
|
|
overlay.fadeIn();
|
2009-07-23 21:36:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
_hideAllOverlays: function() {
|
|
|
|
for (let i = 1; i< this._windows.length; i++) {
|
|
|
|
let overlay = this._windowOverlays[i];
|
|
|
|
overlay.hide();
|
2009-07-23 21:36:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-02-04 14:50:50 +00:00
|
|
|
_windowRemoved : function(metaWorkspace, metaWin) {
|
|
|
|
let win = metaWin.get_compositor_private();
|
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
// find the position of the window in our list
|
2009-07-23 21:36:41 +00:00
|
|
|
let index = this._lookupIndex (metaWin);
|
2009-01-23 19:21:20 +00:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
2009-02-10 16:15:59 +00:00
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
let clone = this._windows[index];
|
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
this._windows.splice(index, 1);
|
2009-11-12 00:26:52 +00:00
|
|
|
this._windowOverlays.splice(index, 1);
|
2009-02-04 14:50:50 +00:00
|
|
|
|
|
|
|
// If metaWin.get_compositor_private() returned non-NULL, that
|
|
|
|
// means the window still exists (and is just being moved to
|
2009-08-11 11:46:10 +00:00
|
|
|
// another workspace or something), so set its overviewHint
|
2009-02-04 14:50:50 +00:00
|
|
|
// accordingly. (If it returned NULL, then the window is being
|
|
|
|
// destroyed; we'd like to animate this, but it's too late at
|
|
|
|
// this point.)
|
|
|
|
if (win) {
|
|
|
|
let [stageX, stageY] = clone.actor.get_transformed_position();
|
|
|
|
let [stageWidth, stageHeight] = clone.actor.get_transformed_size();
|
2009-08-11 11:46:10 +00:00
|
|
|
win._overviewHint = {
|
2009-02-04 14:50:50 +00:00
|
|
|
x: stageX,
|
|
|
|
y: stageY,
|
|
|
|
scale: stageWidth / clone.actor.width
|
|
|
|
};
|
|
|
|
}
|
2009-01-23 19:21:20 +00:00
|
|
|
clone.destroy();
|
|
|
|
|
2009-08-08 04:45:06 +00:00
|
|
|
this.positionWindows(false);
|
2009-02-04 14:50:50 +00:00
|
|
|
this.updateRemovable();
|
2009-01-23 19:21:20 +00:00
|
|
|
},
|
|
|
|
|
2009-02-04 14:50:50 +00:00
|
|
|
_windowAdded : function(metaWorkspace, metaWin) {
|
2009-08-11 11:46:10 +00:00
|
|
|
if (this.leavingOverview)
|
2009-03-17 22:22:25 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-04 14:50:50 +00:00
|
|
|
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 () {
|
2009-02-04 18:24:20 +00:00
|
|
|
if (this.actor && metaWin.get_compositor_private())
|
2009-02-04 14:50:50 +00:00
|
|
|
this._windowAdded(metaWorkspace, metaWin);
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
2009-02-04 22:40:24 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
if (!this._isOverviewWindow(win))
|
2009-02-04 22:40:24 +00:00
|
|
|
return;
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
let clone = this._addWindowClone(win);
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
if (win._overviewHint) {
|
|
|
|
let x = (win._overviewHint.x - this.actor.x) / this.scale;
|
|
|
|
let y = (win._overviewHint.y - this.actor.y) / this.scale;
|
|
|
|
let scale = win._overviewHint.scale / this.scale;
|
|
|
|
delete win._overviewHint;
|
2009-02-04 14:50:50 +00:00
|
|
|
|
|
|
|
clone.actor.set_position (x, y);
|
|
|
|
clone.actor.set_scale (scale, scale);
|
|
|
|
}
|
|
|
|
|
2009-08-08 04:45:06 +00:00
|
|
|
this.positionWindows(false);
|
2009-02-04 14:50:50 +00:00
|
|
|
this.updateRemovable();
|
2009-01-23 19:21:20 +00:00
|
|
|
},
|
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
// Animate the full-screen to Overview transition.
|
|
|
|
zoomToOverview : function() {
|
2009-08-10 22:31:39 +00:00
|
|
|
this.actor.set_position(this.gridX, this.gridY);
|
|
|
|
this.actor.set_scale(this.scale, this.scale);
|
2009-02-03 22:58:33 +00:00
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
// Position and scale the windows.
|
|
|
|
this.positionWindows(true);
|
2009-02-03 22:58:33 +00:00
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
// Fade in the remove button if available, so that it doesn't appear
|
|
|
|
// too abrubtly and doesn't start at a too big size.
|
|
|
|
if (this._removeButton) {
|
|
|
|
Tweener.removeTweens(this._removeButton);
|
|
|
|
this._removeButton.opacity = 0;
|
|
|
|
Tweener.addTween(this._removeButton,
|
|
|
|
{ opacity: 255,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-08-10 22:31:39 +00:00
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
this._visible = true;
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
// Animates the return from Overview mode
|
|
|
|
zoomFromOverview : function() {
|
|
|
|
this.leavingOverview = true;
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
this._hideAllOverlays();
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
Main.overview.connect('hidden', Lang.bind(this,
|
|
|
|
this._doneLeavingOverview));
|
2009-08-10 22:31:39 +00:00
|
|
|
|
|
|
|
// Fade out the remove button if available, so that it doesn't
|
|
|
|
// disappear too abrubtly and doesn't become too big.
|
|
|
|
if (this._removeButton) {
|
|
|
|
Tweener.removeTweens(this._removeButton);
|
|
|
|
Tweener.addTween(this._removeButton,
|
|
|
|
{ opacity: 0,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-08-10 22:31:39 +00:00
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
|
|
|
}
|
2009-01-21 20:35:20 +00:00
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
// Position and scale the windows.
|
2009-01-21 20:35:20 +00:00
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
2009-01-29 21:21:50 +00:00
|
|
|
let clone = this._windows[i];
|
2009-02-10 16:12:58 +00:00
|
|
|
Tweener.addTween(clone.actor,
|
|
|
|
{ x: clone.origX,
|
|
|
|
y: clone.origY,
|
|
|
|
scale_x: 1.0,
|
|
|
|
scale_y: 1.0,
|
|
|
|
workspace_relative: this,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-02-10 16:12:58 +00:00
|
|
|
opacity: 255,
|
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2009-03-17 22:22:25 +00:00
|
|
|
this._visible = false;
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Animates grid shrinking/expanding when a row or column
|
|
|
|
// of workspaces is added or removed
|
|
|
|
resizeToGrid : function (oldScale) {
|
2009-11-12 00:26:52 +00:00
|
|
|
this._hideAllOverlays();
|
2009-01-21 20:35:20 +00:00
|
|
|
Tweener.addTween(this.actor,
|
|
|
|
{ x: this.gridX,
|
|
|
|
y: this.gridY,
|
|
|
|
scale_x: this.scale,
|
|
|
|
scale_y: this.scale,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-07-23 21:36:41 +00:00
|
|
|
transition: "easeOutQuad",
|
2009-11-12 00:26:52 +00:00
|
|
|
onComplete: Lang.bind(this, this._fadeInAllOverlays)
|
2009-01-21 20:35:20 +00:00
|
|
|
});
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
// Animates the addition of a new (empty) workspace
|
|
|
|
slideIn : function(oldScale) {
|
|
|
|
if (this.gridCol > this.gridRow) {
|
2009-01-21 20:35:20 +00:00
|
|
|
this.actor.set_position(global.screen_width, this.gridY);
|
|
|
|
this.actor.set_scale(oldScale, oldScale);
|
2008-12-22 21:51:34 +00:00
|
|
|
} else {
|
2009-01-21 20:35:20 +00:00
|
|
|
this.actor.set_position(this.gridX, global.screen_height);
|
|
|
|
this.actor.set_scale(this.scale, this.scale);
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
2009-01-21 20:35:20 +00:00
|
|
|
Tweener.addTween(this.actor,
|
2008-12-22 21:51:34 +00:00
|
|
|
{ x: this.gridX,
|
|
|
|
y: this.gridY,
|
|
|
|
scale_x: this.scale,
|
|
|
|
scale_y: this.scale,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 21:51:34 +00:00
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
2008-12-22 22:06:47 +00:00
|
|
|
|
|
|
|
this._visible = true;
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Animates the removal of a workspace
|
|
|
|
slideOut : function(onComplete) {
|
2009-01-21 20:35:20 +00:00
|
|
|
let destX = this.actor.x, destY = this.actor.y;
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2009-11-12 00:26:52 +00:00
|
|
|
this._hideAllOverlays();
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
if (this.gridCol > this.gridRow)
|
|
|
|
destX = global.screen_width;
|
|
|
|
else
|
|
|
|
destY = global.screen_height;
|
2009-01-21 20:35:20 +00:00
|
|
|
Tweener.addTween(this.actor,
|
2008-12-22 21:51:34 +00:00
|
|
|
{ x: destX,
|
|
|
|
y: destY,
|
|
|
|
scale_x: this.scale,
|
|
|
|
scale_y: this.scale,
|
2009-08-11 11:46:10 +00:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 21:51:34 +00:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: onComplete
|
|
|
|
});
|
2008-12-22 22:06:47 +00:00
|
|
|
|
|
|
|
this._visible = false;
|
2009-02-02 20:54:33 +00:00
|
|
|
|
|
|
|
// Don't let the user try to select this workspace as it's
|
|
|
|
// making its exit.
|
|
|
|
this._desktop.reactive = false;
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy : function() {
|
2009-02-10 16:15:59 +00:00
|
|
|
Tweener.removeTweens(this.actor);
|
2008-12-22 21:51:34 +00:00
|
|
|
this.actor.destroy();
|
|
|
|
this.actor = null;
|
2009-02-04 14:50:50 +00:00
|
|
|
|
|
|
|
this._metaWorkspace.disconnect(this._windowAddedId);
|
|
|
|
this._metaWorkspace.disconnect(this._windowRemovedId);
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
// Sets this.leavingOverview flag to false.
|
|
|
|
_doneLeavingOverview : function() {
|
|
|
|
this.leavingOverview = false;
|
2009-03-17 22:22:25 +00:00
|
|
|
},
|
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
// Tests if @win belongs to this workspaces
|
|
|
|
_isMyWindow : function (win) {
|
2009-01-23 19:21:20 +00:00
|
|
|
return win.get_workspace() == this.workspaceNum ||
|
2008-12-22 21:51:34 +00:00
|
|
|
(win.get_meta_window() && win.get_meta_window().is_on_all_workspaces());
|
|
|
|
},
|
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
// Tests if @win should be shown in the Overview
|
|
|
|
_isOverviewWindow : function (win) {
|
2009-10-15 23:28:29 +00:00
|
|
|
let tracker = Shell.WindowTracker.get_default()
|
|
|
|
return tracker.is_window_interesting(win.get_meta_window());
|
2008-12-22 21:51:34 +00:00
|
|
|
},
|
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
// Create a clone of a (non-desktop) window and add it to the window list
|
|
|
|
_addWindowClone : function(win) {
|
2009-01-29 21:21:50 +00:00
|
|
|
let clone = new WindowClone(win);
|
2009-11-12 00:26:52 +00:00
|
|
|
let overlay = new WindowOverlay(clone, this.parentActor);
|
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
clone.connect('selected',
|
|
|
|
Lang.bind(this, this._onCloneSelected));
|
2009-07-23 21:36:41 +00:00
|
|
|
clone.connect('drag-begin',
|
|
|
|
Lang.bind(this, function() {
|
2009-11-12 00:26:52 +00:00
|
|
|
overlay.hide();
|
2009-07-23 21:36:41 +00:00
|
|
|
}));
|
|
|
|
clone.connect('drag-end',
|
|
|
|
Lang.bind(this, function() {
|
2009-11-12 00:26:52 +00:00
|
|
|
overlay.show();
|
2009-07-23 21:36:41 +00:00
|
|
|
}));
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
this.actor.add_actor(clone.actor);
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2009-11-20 00:39:00 +00:00
|
|
|
overlay.connect('show-close-button', Lang.bind(this, this._onShowOverlayClose));
|
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
this._windows.push(clone);
|
2009-11-12 00:26:52 +00:00
|
|
|
this._windowOverlays.push(overlay);
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
return clone;
|
|
|
|
},
|
|
|
|
|
2009-11-20 00:39:00 +00:00
|
|
|
_onShowOverlayClose: function (windowOverlay) {
|
|
|
|
for (let i = 1; i < this._windowOverlays.length; i++) {
|
|
|
|
let overlay = this._windowOverlays[i];
|
|
|
|
if (overlay == windowOverlay)
|
|
|
|
continue;
|
|
|
|
overlay.hideCloseButton();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-18 19:08:56 +00:00
|
|
|
_computeWindowSlot : function(windowIndex, numberOfWindows) {
|
2008-12-22 21:51:34 +00:00
|
|
|
if (numberOfWindows in POSITIONS)
|
|
|
|
return POSITIONS[numberOfWindows][windowIndex];
|
|
|
|
|
|
|
|
// If we don't have a predefined scheme for this window count,
|
2009-03-31 21:40:18 +00:00
|
|
|
// arrange the windows in a grid pattern.
|
|
|
|
let gridWidth = Math.ceil(Math.sqrt(numberOfWindows));
|
|
|
|
let gridHeight = Math.ceil(numberOfWindows / gridWidth);
|
|
|
|
|
2009-08-08 20:10:40 +00:00
|
|
|
let fraction = 0.95 * (1. / gridWidth);
|
2009-03-31 21:40:18 +00:00
|
|
|
|
|
|
|
let xCenter = (.5 / gridWidth) + ((windowIndex) % gridWidth) / gridWidth;
|
|
|
|
let yCenter = (.5 / gridHeight) + Math.floor((windowIndex / gridWidth)) / gridHeight;
|
2008-12-22 21:51:34 +00:00
|
|
|
|
|
|
|
return [xCenter, yCenter, fraction];
|
|
|
|
},
|
2009-01-21 20:35:20 +00:00
|
|
|
|
2009-09-18 19:08:56 +00:00
|
|
|
_computeAllWindowSlots: function(totalWindows) {
|
|
|
|
let slots = [];
|
|
|
|
for (let i = 0; i < totalWindows; i++) {
|
|
|
|
slots.push(this._computeWindowSlot(i, totalWindows));
|
|
|
|
}
|
|
|
|
return slots;
|
|
|
|
},
|
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
_onCloneSelected : function (clone, time) {
|
2009-08-11 11:46:10 +00:00
|
|
|
Main.overview.activateWindow(clone.metaWindow, time);
|
2008-12-22 22:06:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeSelf : function(actor, event) {
|
|
|
|
let screen = global.screen;
|
2009-01-23 19:21:20 +00:00
|
|
|
let workspace = screen.get_workspace_by_index(this.workspaceNum);
|
2008-12-22 22:06:47 +00:00
|
|
|
|
|
|
|
screen.remove_workspace(workspace, event.get_time());
|
2009-02-02 20:54:33 +00:00
|
|
|
return true;
|
2009-02-10 16:15:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Draggable target interface
|
|
|
|
acceptDrop : function(source, actor, x, y, time) {
|
|
|
|
if (source instanceof WindowClone) {
|
|
|
|
let win = source.realWindow;
|
|
|
|
if (this._isMyWindow(win))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Set a hint on the Mutter.Window so its initial position
|
|
|
|
// in the new workspace will be correct
|
2009-08-11 11:46:10 +00:00
|
|
|
win._overviewHint = {
|
2009-02-10 16:15:59 +00:00
|
|
|
x: actor.x,
|
|
|
|
y: actor.y,
|
|
|
|
scale: actor.scale_x
|
|
|
|
};
|
|
|
|
|
|
|
|
let metaWindow = win.get_meta_window();
|
|
|
|
metaWindow.change_workspace_by_index(this.workspaceNum,
|
|
|
|
false, // don't create workspace
|
|
|
|
time);
|
|
|
|
return true;
|
2009-08-18 00:29:54 +00:00
|
|
|
} else if (source.shellWorkspaceLaunch) {
|
2009-02-10 16:15:59 +00:00
|
|
|
this._metaWorkspace.activate(time);
|
2009-08-18 00:29:54 +00:00
|
|
|
source.shellWorkspaceLaunch();
|
2009-02-10 16:15:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
Signals.addSignalMethods(Workspace.prototype);
|
|
|
|
|
2009-09-01 15:56:41 +00:00
|
|
|
function Workspaces(width, height, x, y) {
|
|
|
|
this._init(width, height, x, y);
|
2008-12-02 16:15:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
Workspaces.prototype = {
|
2009-09-01 15:56:41 +00:00
|
|
|
_init : function(width, height, x, y) {
|
2009-11-12 00:26:52 +00:00
|
|
|
this.actor = new St.Bin({ style_class: "workspaces" });
|
|
|
|
this._actor = new Clutter.Group();
|
|
|
|
|
|
|
|
this.actor.add_actor(this._actor);
|
2008-12-04 15:16:16 +00:00
|
|
|
|
2009-02-10 22:38:06 +00:00
|
|
|
this._width = width;
|
|
|
|
this._height = height;
|
|
|
|
this._x = x;
|
|
|
|
this._y = y;
|
2008-12-22 21:50:23 +00:00
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
this._windowSelectionAppId = null;
|
|
|
|
|
2008-12-04 15:16:16 +00:00
|
|
|
this._workspaces = [];
|
2009-09-01 18:15:29 +00:00
|
|
|
|
|
|
|
this._highlightWindow = null;
|
|
|
|
|
2008-12-15 20:55:24 +00:00
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
let activeWorkspace;
|
2008-12-04 15:16:16 +00:00
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
// Create and position workspace objects
|
2008-12-04 15:16:16 +00:00
|
|
|
for (let w = 0; w < global.screen.n_workspaces; w++) {
|
2009-01-23 19:21:20 +00:00
|
|
|
this._addWorkspaceActor(w);
|
2009-01-21 21:12:49 +00:00
|
|
|
if (w == activeWorkspaceIndex) {
|
2008-12-15 20:55:24 +00:00
|
|
|
activeWorkspace = this._workspaces[w];
|
2009-01-21 21:12:49 +00:00
|
|
|
activeWorkspace.setSelected(true);
|
|
|
|
}
|
2008-12-02 16:15:00 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
activeWorkspace.actor.raise_top();
|
2009-09-11 21:23:23 +00:00
|
|
|
this._positionWorkspaces();
|
2008-12-04 15:16:16 +00:00
|
|
|
|
2008-12-22 22:06:47 +00:00
|
|
|
let lastWorkspace = this._workspaces[this._workspaces.length - 1];
|
2009-02-04 14:50:50 +00:00
|
|
|
lastWorkspace.updateRemovable(true);
|
2008-12-04 15:16:16 +00:00
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
// Position/scale the desktop windows and their children after the
|
|
|
|
// workspaces have been created. This cannot be done first because
|
|
|
|
// window movement depends on the Workspaces object being accessible
|
2009-08-11 11:46:10 +00:00
|
|
|
// as an Overview member.
|
2009-09-28 23:48:03 +00:00
|
|
|
this._overviewShowingId =
|
|
|
|
Main.overview.connect('showing',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._onRestacked();
|
|
|
|
for (let w = 0; w < this._workspaces.length; w++)
|
|
|
|
this._workspaces[w].zoomToOverview();
|
2009-08-10 22:31:39 +00:00
|
|
|
}));
|
2008-12-15 21:03:07 +00:00
|
|
|
|
|
|
|
// Track changes to the number of workspaces
|
|
|
|
this._nWorkspacesNotifyId =
|
|
|
|
global.screen.connect('notify::n-workspaces',
|
2009-01-21 21:12:49 +00:00
|
|
|
Lang.bind(this, this._workspacesChanged));
|
|
|
|
this._switchWorkspaceNotifyId =
|
|
|
|
global.window_manager.connect('switch-workspace',
|
|
|
|
Lang.bind(this, this._activeWorkspaceChanged));
|
2009-09-28 23:48:03 +00:00
|
|
|
this._restackedNotifyId =
|
|
|
|
global.screen.connect('restacked',
|
|
|
|
Lang.bind(this, this._onRestacked));
|
2008-12-04 15:16:16 +00:00
|
|
|
},
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-09-01 18:15:29 +00:00
|
|
|
_lookupWorkspaceForMetaWindow: function (metaWindow) {
|
|
|
|
for (let i = 0; i < this._workspaces.length; i++) {
|
|
|
|
if (this._workspaces[i].containsMetaWindow(metaWindow))
|
|
|
|
return this._workspaces[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-09-11 22:58:30 +00:00
|
|
|
_lookupCloneForMetaWindow: function (metaWindow) {
|
2009-07-31 21:20:26 +00:00
|
|
|
for (let i = 0; i < this._workspaces.length; i++) {
|
|
|
|
let clone = this._workspaces[i].lookupCloneForMetaWindow(metaWindow);
|
|
|
|
if (clone)
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-09-01 18:15:29 +00:00
|
|
|
setHighlightWindow: function (metaWindow) {
|
|
|
|
// Looping over all workspaces is easier than keeping track of the last
|
|
|
|
// highlighted window while trying to handle the window or workspace possibly
|
|
|
|
// going away.
|
|
|
|
for (let i = 0; i < this._workspaces.length; i++) {
|
|
|
|
this._workspaces[i].setHighlightWindow(null);
|
|
|
|
}
|
|
|
|
if (metaWindow != null) {
|
|
|
|
let workspace = this._lookupWorkspaceForMetaWindow(metaWindow);
|
|
|
|
workspace.setHighlightWindow(metaWindow);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
_clearApplicationWindowSelection: function(reposition) {
|
|
|
|
if (this._windowSelectionAppId == null)
|
|
|
|
return;
|
|
|
|
this._windowSelectionAppId = null;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._workspaces.length; i++) {
|
|
|
|
this._workspaces[i].setLightboxMode(false);
|
|
|
|
this._workspaces[i].setShowOnlyWindows(null, reposition);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-11 16:47:53 +00:00
|
|
|
/**
|
|
|
|
* setApplicationWindowSelection:
|
|
|
|
* @appid: Application identifier string
|
|
|
|
*
|
|
|
|
* Enter a mode which shows only the windows owned by the
|
|
|
|
* given application, and allow highlighting of a specific
|
|
|
|
* window with setHighlightWindow().
|
|
|
|
*/
|
2009-09-09 21:28:52 +00:00
|
|
|
setApplicationWindowSelection: function (appId) {
|
2009-09-11 16:39:59 +00:00
|
|
|
if (appId == null) {
|
|
|
|
this._clearApplicationWindowSelection(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appId == this._windowSelectionAppId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._windowSelectionAppId = appId;
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
let appSys = Shell.AppSystem.get_default();
|
2009-09-01 18:15:29 +00:00
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
let showOnlyWindows = {};
|
2009-10-15 23:28:29 +00:00
|
|
|
let app = appSys.get_app(appId);
|
|
|
|
let windows = app.get_windows();
|
2009-09-11 16:39:59 +00:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
showOnlyWindows[windows[i]] = 1;
|
2009-09-01 18:15:29 +00:00
|
|
|
}
|
2009-09-11 16:39:59 +00:00
|
|
|
|
2009-09-01 18:15:29 +00:00
|
|
|
for (let i = 0; i < this._workspaces.length; i++) {
|
2009-09-11 16:39:59 +00:00
|
|
|
this._workspaces[i].setLightboxMode(true);
|
|
|
|
this._workspaces[i].setShowOnlyWindows(showOnlyWindows, true);
|
2009-09-01 18:15:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-11 16:39:59 +00:00
|
|
|
/**
|
|
|
|
* activateWindowFromOverview:
|
|
|
|
* @metaWindow: A #MetaWindow
|
|
|
|
* @time: Integer even timestamp
|
|
|
|
*
|
|
|
|
* This function exits the overview, switching to the given @metaWindow.
|
|
|
|
* If an application filter is in effect, it will be cleared.
|
|
|
|
*/
|
|
|
|
activateWindowFromOverview: function (metaWindow, time) {
|
|
|
|
if (this._windowSelectionAppId != null) {
|
|
|
|
this._clearApplicationWindowSelection(false);
|
|
|
|
}
|
2009-09-21 20:29:37 +00:00
|
|
|
|
|
|
|
Main.activateWindow(metaWindow, time);
|
2009-09-11 16:39:59 +00:00
|
|
|
Main.overview.hide();
|
|
|
|
},
|
|
|
|
|
2008-12-04 15:16:16 +00:00
|
|
|
hide : function() {
|
2008-12-15 20:55:24 +00:00
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
let activeWorkspace = this._workspaces[activeWorkspaceIndex];
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-09-11 21:23:23 +00:00
|
|
|
this._positionWorkspaces();
|
2008-12-22 21:51:34 +00:00
|
|
|
activeWorkspace.actor.raise_top();
|
2008-12-15 20:55:24 +00:00
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
for (let w = 0; w < this._workspaces.length; w++)
|
2009-08-11 11:46:10 +00:00
|
|
|
this._workspaces[w].zoomFromOverview();
|
2008-12-04 15:16:16 +00:00
|
|
|
},
|
2008-12-15 20:48:59 +00:00
|
|
|
|
|
|
|
destroy : function() {
|
2008-12-22 21:51:34 +00:00
|
|
|
for (let w = 0; w < this._workspaces.length; w++)
|
2008-12-04 15:16:16 +00:00
|
|
|
this._workspaces[w].destroy();
|
|
|
|
this._workspaces = [];
|
2008-12-15 20:55:24 +00:00
|
|
|
|
2008-12-22 22:06:47 +00:00
|
|
|
this.actor.destroy();
|
|
|
|
this.actor = null;
|
2008-12-15 21:03:07 +00:00
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
Main.overview.disconnect(this._overviewShowingId);
|
2008-12-15 21:03:07 +00:00
|
|
|
global.screen.disconnect(this._nWorkspacesNotifyId);
|
2009-01-21 21:12:49 +00:00
|
|
|
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
|
2009-09-28 23:48:03 +00:00
|
|
|
global.screen.disconnect(this._restackedNotifyId);
|
2008-12-15 20:55:24 +00:00
|
|
|
},
|
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
getScale : function() {
|
|
|
|
return this._workspaces[0].scale;
|
2009-04-22 00:23:06 +00:00
|
|
|
},
|
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
// Get the grid position of the active workspace.
|
|
|
|
getActiveWorkspacePosition : function() {
|
2009-04-22 00:23:06 +00:00
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
let activeWorkspace = this._workspaces[activeWorkspaceIndex];
|
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
return [activeWorkspace.gridX, activeWorkspace.gridY];
|
2009-02-03 22:58:33 +00:00
|
|
|
},
|
|
|
|
|
2008-12-15 20:58:10 +00:00
|
|
|
// Assign grid positions to workspaces. We can't just do a simple
|
|
|
|
// row-major or column-major numbering, because we don't want the
|
|
|
|
// existing workspaces to get rearranged when we add a row or
|
|
|
|
// column. So we alternate between adding to rows and adding to
|
|
|
|
// columns. (So, eg, when going from a 2x2 grid of 4 workspaces to
|
|
|
|
// a 3x2 grid of 5 workspaces, the 4 existing workspaces stay
|
|
|
|
// where they are, and the 5th one is added to the end of the
|
|
|
|
// first row.)
|
|
|
|
//
|
|
|
|
// FIXME: need to make the metacity internal layout agree with this!
|
2009-09-11 21:23:23 +00:00
|
|
|
_positionWorkspaces : function() {
|
2008-12-15 20:55:24 +00:00
|
|
|
let gridWidth = Math.ceil(Math.sqrt(this._workspaces.length));
|
|
|
|
let gridHeight = Math.ceil(this._workspaces.length / gridWidth);
|
|
|
|
|
|
|
|
let wsWidth = (this._width - (gridWidth - 1) * GRID_SPACING) / gridWidth;
|
|
|
|
let wsHeight = (this._height - (gridHeight - 1) * GRID_SPACING) / gridHeight;
|
|
|
|
let scale = wsWidth / global.screen_width;
|
|
|
|
|
2008-12-15 20:58:10 +00:00
|
|
|
let span = 1, n = 0, row = 0, col = 0, horiz = true;
|
|
|
|
|
|
|
|
for (let w = 0; w < this._workspaces.length; w++) {
|
2008-12-15 20:55:24 +00:00
|
|
|
let workspace = this._workspaces[w];
|
|
|
|
|
|
|
|
workspace.gridRow = row;
|
|
|
|
workspace.gridCol = col;
|
|
|
|
|
|
|
|
workspace.gridX = this._x + workspace.gridCol * (wsWidth + GRID_SPACING);
|
|
|
|
workspace.gridY = this._y + workspace.gridRow * (wsHeight + GRID_SPACING);
|
2008-12-22 21:51:34 +00:00
|
|
|
workspace.scale = scale;
|
2008-12-15 20:55:24 +00:00
|
|
|
|
2008-12-15 20:58:10 +00:00
|
|
|
if (horiz) {
|
|
|
|
col++;
|
|
|
|
if (col == span) {
|
|
|
|
row = 0;
|
|
|
|
horiz = false;
|
|
|
|
}
|
|
|
|
} else {
|
2008-12-15 20:55:24 +00:00
|
|
|
row++;
|
2008-12-15 20:58:10 +00:00
|
|
|
if (row == span) {
|
|
|
|
col = 0;
|
|
|
|
horiz = true;
|
|
|
|
span++;
|
|
|
|
}
|
2008-12-15 20:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-02 16:15:00 +00:00
|
|
|
},
|
|
|
|
|
2008-12-15 21:03:07 +00:00
|
|
|
_workspacesChanged : function() {
|
|
|
|
let oldNumWorkspaces = this._workspaces.length;
|
|
|
|
let newNumWorkspaces = global.screen.n_workspaces;
|
|
|
|
|
|
|
|
if (oldNumWorkspaces == newNumWorkspaces)
|
|
|
|
return;
|
|
|
|
|
2008-12-22 21:51:34 +00:00
|
|
|
let oldScale = this._workspaces[0].scale;
|
2008-12-15 21:03:07 +00:00
|
|
|
let oldGridWidth = Math.ceil(Math.sqrt(oldNumWorkspaces));
|
|
|
|
let oldGridHeight = Math.ceil(oldNumWorkspaces / oldGridWidth);
|
|
|
|
let lostWorkspaces = [];
|
|
|
|
|
2008-12-22 22:06:47 +00:00
|
|
|
// The old last workspace is no longer removable.
|
2009-02-04 14:50:50 +00:00
|
|
|
this._workspaces[oldNumWorkspaces - 1].updateRemovable();
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2008-12-15 21:03:07 +00:00
|
|
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
|
|
|
// Create new workspace groups
|
|
|
|
for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++) {
|
2009-01-23 19:21:20 +00:00
|
|
|
this._addWorkspaceActor(w);
|
2008-12-15 21:03:07 +00:00
|
|
|
}
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2008-12-15 21:03:07 +00:00
|
|
|
} else {
|
|
|
|
// Truncate the list of workspaces
|
|
|
|
// FIXME: assumes that the workspaces are being removed from
|
|
|
|
// the end of the list, not the start/middle
|
|
|
|
lostWorkspaces = this._workspaces.splice(newNumWorkspaces);
|
|
|
|
}
|
|
|
|
|
2008-12-22 22:06:47 +00:00
|
|
|
// The new last workspace may be removable
|
|
|
|
let newLastWorkspace = this._workspaces[this._workspaces.length - 1];
|
2009-02-04 14:50:50 +00:00
|
|
|
newLastWorkspace.updateRemovable();
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2008-12-15 21:03:07 +00:00
|
|
|
// Figure out the new layout
|
2009-09-11 21:23:23 +00:00
|
|
|
this._positionWorkspaces();
|
2008-12-22 21:51:34 +00:00
|
|
|
let newScale = this._workspaces[0].scale;
|
2008-12-15 21:03:07 +00:00
|
|
|
let newGridWidth = Math.ceil(Math.sqrt(newNumWorkspaces));
|
|
|
|
let newGridHeight = Math.ceil(newNumWorkspaces / newGridWidth);
|
|
|
|
|
|
|
|
if (newGridWidth != oldGridWidth || newGridHeight != oldGridHeight) {
|
|
|
|
// We need to resize/move the existing workspaces/windows
|
|
|
|
let existingWorkspaces = Math.min(oldNumWorkspaces, newNumWorkspaces);
|
2008-12-22 21:51:34 +00:00
|
|
|
for (let w = 0; w < existingWorkspaces; w++)
|
|
|
|
this._workspaces[w].resizeToGrid(oldScale);
|
2008-12-15 21:03:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 04:45:06 +00:00
|
|
|
if (newScale != oldScale) {
|
|
|
|
// The workspace scale affects window size/positioning because we clamp
|
|
|
|
// window size to a 1:1 ratio and never scale them up
|
|
|
|
let existingWorkspaces = Math.min(oldNumWorkspaces, newNumWorkspaces);
|
|
|
|
for (let w = 0; w < existingWorkspaces; w++)
|
|
|
|
this._workspaces[w].positionWindows(false);
|
|
|
|
}
|
|
|
|
|
2008-12-15 21:03:07 +00:00
|
|
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
|
|
|
// Slide new workspaces in from offscreen
|
2008-12-22 21:51:34 +00:00
|
|
|
for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++)
|
|
|
|
this._workspaces[w].slideIn(oldScale);
|
2008-12-15 21:03:07 +00:00
|
|
|
} else {
|
|
|
|
// Slide old workspaces out
|
|
|
|
for (let w = 0; w < lostWorkspaces.length; w++) {
|
|
|
|
let workspace = lostWorkspaces[w];
|
2008-12-22 21:51:34 +00:00
|
|
|
workspace.slideOut(function () { workspace.destroy(); });
|
2008-12-15 21:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: deal with windows on the lost workspaces
|
|
|
|
}
|
2009-08-09 23:48:54 +00:00
|
|
|
|
|
|
|
// Reset the selection state; if we went from > 1 workspace to 1,
|
|
|
|
// this has the side effect of removing the frame border
|
|
|
|
let activeIndex = global.screen.get_active_workspace_index();
|
|
|
|
this._workspaces[activeIndex].setSelected(true);
|
2008-12-22 22:06:47 +00:00
|
|
|
},
|
|
|
|
|
2009-01-21 21:12:49 +00:00
|
|
|
_activeWorkspaceChanged : function(wm, from, to, direction) {
|
|
|
|
this._workspaces[from].setSelected(false);
|
|
|
|
this._workspaces[to].setSelected(true);
|
|
|
|
},
|
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
_addWorkspaceActor : function(workspaceNum) {
|
2009-11-12 00:26:52 +00:00
|
|
|
let workspace = new Workspace(workspaceNum, this._actor);
|
2009-01-23 19:21:20 +00:00
|
|
|
this._workspaces[workspaceNum] = workspace;
|
2009-11-12 00:26:52 +00:00
|
|
|
this._actor.add_actor(workspace.actor);
|
2009-01-23 19:21:20 +00:00
|
|
|
},
|
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
_onRestacked: function() {
|
|
|
|
let stack = global.get_windows();
|
|
|
|
let stackIndices = {};
|
|
|
|
|
|
|
|
for (let i = 0; i < stack.length; i++) {
|
|
|
|
// Use the stable sequence for an integer to use as a hash key
|
|
|
|
stackIndices[stack[i].get_meta_window().get_stable_sequence()] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < this._workspaces.length; i++)
|
|
|
|
this._workspaces[i].syncStacking(stackIndices);
|
|
|
|
},
|
|
|
|
|
2009-09-01 15:56:41 +00:00
|
|
|
// Handles a drop onto the (+) button; assumes the new workspace
|
|
|
|
// has already been added
|
|
|
|
acceptNewWorkspaceDrop : function(source, dropActor, x, y, time) {
|
2009-08-13 00:02:59 +00:00
|
|
|
return this._workspaces[this._workspaces.length - 1].acceptDrop(source, dropActor, x, y, time);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-21 20:35:20 +00:00
|
|
|
// Create a SpecialPropertyModifier to let us move windows in a
|
|
|
|
// straight line on the screen even though their containing workspace
|
|
|
|
// is also moving.
|
2009-05-02 22:33:13 +00:00
|
|
|
Tweener.registerSpecialPropertyModifier("workspace_relative", _workspaceRelativeModifier, _workspaceRelativeGet);
|
2009-01-21 20:35:20 +00:00
|
|
|
|
2009-05-02 22:33:13 +00:00
|
|
|
function _workspaceRelativeModifier(workspace) {
|
2009-08-11 11:46:10 +00:00
|
|
|
let [startX, startY] = Main.overview.getPosition();
|
|
|
|
let overviewPosX, overviewPosY, overviewScale;
|
2009-01-21 20:35:20 +00:00
|
|
|
|
2009-02-10 16:12:58 +00:00
|
|
|
if (!workspace)
|
|
|
|
return [];
|
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
if (workspace.leavingOverview) {
|
|
|
|
let [zoomedInX, zoomedInY] = Main.overview.getZoomedInPosition();
|
|
|
|
overviewPosX = { begin: startX, end: zoomedInX };
|
|
|
|
overviewPosY = { begin: startY, end: zoomedInY };
|
|
|
|
overviewScale = { begin: Main.overview.getScale(),
|
|
|
|
end: Main.overview.getZoomedInScale() };
|
2009-02-03 22:58:33 +00:00
|
|
|
} else {
|
2009-08-11 11:46:10 +00:00
|
|
|
overviewPosX = { begin: startX, end: 0 };
|
|
|
|
overviewPosY = { begin: startY, end: 0 };
|
|
|
|
overviewScale = { begin: Main.overview.getScale(), end: 1 };
|
2009-01-21 20:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return [ { name: "x",
|
2009-08-10 22:31:39 +00:00
|
|
|
parameters: { workspacePos: workspace.gridX,
|
2009-08-11 11:46:10 +00:00
|
|
|
overviewPos: overviewPosX,
|
|
|
|
overviewScale: overviewScale } },
|
2009-01-21 20:35:20 +00:00
|
|
|
{ name: "y",
|
2009-08-10 22:31:39 +00:00
|
|
|
parameters: { workspacePos: workspace.gridY,
|
2009-08-11 11:46:10 +00:00
|
|
|
overviewPos: overviewPosY,
|
|
|
|
overviewScale: overviewScale } }
|
2009-01-21 20:35:20 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2009-05-02 22:33:13 +00:00
|
|
|
function _workspaceRelativeGet(begin, end, time, params) {
|
2009-08-11 11:46:10 +00:00
|
|
|
let curOverviewPos = (1 - time) * params.overviewPos.begin +
|
|
|
|
time * params.overviewPos.end;
|
|
|
|
let curOverviewScale = (1 - time) * params.overviewScale.begin +
|
|
|
|
time * params.overviewScale.end;
|
2009-08-10 22:31:39 +00:00
|
|
|
|
|
|
|
// Calculate the screen position of the window.
|
|
|
|
let screen = (1 - time) *
|
2009-08-11 11:46:10 +00:00
|
|
|
((begin + params.workspacePos) * params.overviewScale.begin +
|
|
|
|
params.overviewPos.begin) +
|
2009-08-10 22:31:39 +00:00
|
|
|
time *
|
2009-08-11 11:46:10 +00:00
|
|
|
((end + params.workspacePos) * params.overviewScale.end +
|
|
|
|
params.overviewPos.end);
|
2009-08-10 22:31:39 +00:00
|
|
|
|
|
|
|
// Return the workspace coordinates.
|
2009-08-11 11:46:10 +00:00
|
|
|
return (screen - curOverviewPos) / curOverviewScale - params.workspacePos;
|
2009-02-03 22:58:33 +00:00
|
|
|
}
|