2009-02-02 18:02:16 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2009-02-02 18:02:16 -05:00
|
|
|
const Big = imports.gi.Big;
|
2008-12-02 11:15:00 -05:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-02-02 18:02:16 -05:00
|
|
|
const GdkPixbuf = imports.gi.GdkPixbuf;
|
2009-01-23 14:21:20 -05:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2008-12-22 17:06:47 -05:00
|
|
|
const Lang = imports.lang;
|
2009-02-04 09:50:50 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
2009-02-02 18:02:16 -05:00
|
|
|
const Meta = imports.gi.Meta;
|
2009-01-23 14:21:20 -05:00
|
|
|
const Pango = imports.gi.Pango;
|
2009-02-02 18:02:16 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-01-23 14:21:20 -05:00
|
|
|
const Signals = imports.signals;
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
const DND = imports.ui.dnd;
|
2008-12-02 11:15:00 -05:00
|
|
|
const Main = imports.ui.main;
|
2009-08-11 07:46:10 -04:00
|
|
|
const Overview = imports.ui.overview;
|
2008-12-02 11:15:00 -05:00
|
|
|
const Panel = imports.ui.panel;
|
2009-02-10 11:12:58 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2009-01-19 18:06:59 -05:00
|
|
|
const FOCUS_ANIMATION_TIME = 0.15;
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2008-12-18 13:50:09 -05:00
|
|
|
const WINDOWCLONE_BG_COLOR = new Clutter.Color();
|
|
|
|
WINDOWCLONE_BG_COLOR.from_pixel(0x000000f0);
|
|
|
|
const WINDOWCLONE_TITLE_COLOR = new Clutter.Color();
|
|
|
|
WINDOWCLONE_TITLE_COLOR.from_pixel(0xffffffff);
|
2009-01-21 16:12:49 -05:00
|
|
|
const FRAME_COLOR = new Clutter.Color();
|
|
|
|
FRAME_COLOR.from_pixel(0xffffffff);
|
2008-12-18 13:50:09 -05:00
|
|
|
|
2008-12-02 11:15:00 -05: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 10:20:37 -05:00
|
|
|
// is relative to the width of the workspace.
|
2008-12-02 11:15:00 -05:00
|
|
|
const POSITIONS = {
|
2009-08-08 16:10:40 -04: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 11:15:00 -05:00
|
|
|
};
|
|
|
|
|
2008-12-15 15:55:24 -05: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 10:16:16 -05:00
|
|
|
const GRID_SPACING = 15;
|
2009-01-21 16:12:49 -05:00
|
|
|
const FRAME_SIZE = GRID_SPACING / 3;
|
2008-12-04 10:16:16 -05:00
|
|
|
|
2009-02-10 17:38:06 -05:00
|
|
|
let buttonSize = false;
|
|
|
|
|
2009-01-29 16:21:50 -05:00
|
|
|
function WindowClone(realWindow) {
|
|
|
|
this._init(realWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowClone.prototype = {
|
|
|
|
_init : function(realWindow) {
|
2009-02-23 14:42:00 -05:00
|
|
|
this.actor = new Clutter.Clone({ source: realWindow.get_texture(),
|
|
|
|
reactive: true,
|
|
|
|
x: realWindow.x,
|
|
|
|
y: realWindow.y });
|
2009-02-10 11:12:58 -05:00
|
|
|
this.actor._delegate = this;
|
2009-01-29 16:21:50 -05:00
|
|
|
this.realWindow = realWindow;
|
2009-02-04 09:50:50 -05:00
|
|
|
this.metaWindow = realWindow.meta_window;
|
2009-01-29 16:21:50 -05:00
|
|
|
this.origX = realWindow.x;
|
|
|
|
this.origY = realWindow.y;
|
|
|
|
|
|
|
|
this.actor.connect('button-release-event',
|
|
|
|
Lang.bind(this, this._onButtonRelease));
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2009-01-29 16:21:50 -05: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 11:15:59 -05: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 16:21:50 -05:00
|
|
|
this._inDrag = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function () {
|
|
|
|
this.actor.destroy();
|
|
|
|
if (this._title)
|
|
|
|
this._title.destroy();
|
|
|
|
},
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2009-01-29 16:21:50 -05: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;
|
|
|
|
|
|
|
|
actor.raise_top();
|
|
|
|
this._updateTitle();
|
|
|
|
},
|
|
|
|
|
|
|
|
_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-02-10 11:12:58 -05:00
|
|
|
if (Tweener.isTweening(this.actor))
|
2009-01-29 16:21:50 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
actor.raise(this.stackAbove);
|
|
|
|
this._updateTitle();
|
|
|
|
},
|
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
_onButtonRelease : function (actor, event) {
|
|
|
|
this.emit('selected', event.get_time());
|
2009-01-29 16:21:50 -05:00
|
|
|
},
|
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
_onDragBegin : function (draggable, time) {
|
|
|
|
this._inDrag = true;
|
|
|
|
this._updateTitle();
|
2009-07-23 17:36:41 -04:00
|
|
|
this.emit('drag-begin');
|
2009-01-29 16:21:50 -05:00
|
|
|
},
|
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
_onDragEnd : function (draggable, time, snapback) {
|
2009-01-29 16:21:50 -05:00
|
|
|
this._inDrag = false;
|
|
|
|
|
2009-02-10 11:15:59 -05: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 17:36:41 -04:00
|
|
|
|
|
|
|
this.emit('drag-end');
|
2009-01-29 16:21:50 -05:00
|
|
|
},
|
|
|
|
|
2009-02-10 11:12:58 -05:00
|
|
|
// Called by Tweener
|
|
|
|
onAnimationStart : function () {
|
|
|
|
this._updateTitle();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called by Tweener
|
|
|
|
onAnimationComplete : function () {
|
|
|
|
this._updateTitle();
|
|
|
|
this.actor.raise(this.stackAbove);
|
2009-01-29 16:21:50 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_createTitle : function () {
|
|
|
|
let window = this.realWindow;
|
|
|
|
|
|
|
|
let box = new Big.Box({ background_color : WINDOWCLONE_BG_COLOR,
|
|
|
|
y_align: Big.BoxAlignment.CENTER,
|
|
|
|
corner_radius: 5,
|
|
|
|
padding: 4,
|
|
|
|
spacing: 4,
|
|
|
|
orientation: Big.BoxOrientation.HORIZONTAL });
|
2009-07-23 17:36:41 -04:00
|
|
|
|
2009-02-23 14:42:00 -05:00
|
|
|
let title = new Clutter.Text({ color: WINDOWCLONE_TITLE_COLOR,
|
|
|
|
font_name: "Sans 12",
|
|
|
|
text: this.metaWindow.title,
|
|
|
|
ellipsize: Pango.EllipsizeMode.END
|
|
|
|
});
|
2009-01-29 16:21:50 -05:00
|
|
|
box.append(title, Big.BoxPackFlags.EXPAND);
|
|
|
|
// Get and cache the expected width (just the icon), with spacing, plus title
|
|
|
|
box.fullWidth = box.width;
|
|
|
|
box.hide(); // Hidden by default, show on mouseover
|
|
|
|
this._title = box;
|
|
|
|
|
|
|
|
// Make the title a sibling of the window
|
|
|
|
this.actor.get_parent().add_actor(box);
|
|
|
|
},
|
|
|
|
|
|
|
|
_adjustTitle : function () {
|
|
|
|
let title = this._title;
|
|
|
|
if (!title)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [cloneScreenWidth, cloneScreenHeight] = this.actor.get_transformed_size();
|
|
|
|
let [titleScreenWidth, titleScreenHeight] = title.get_transformed_size();
|
|
|
|
|
|
|
|
// Titles are supposed to be "full-size", so adjust its
|
|
|
|
// scale to counteract the scaling of its ancestor actors.
|
|
|
|
title.set_scale(title.width / titleScreenWidth * title.scale_x,
|
|
|
|
title.height / titleScreenHeight * title.scale_y);
|
|
|
|
|
|
|
|
title.width = Math.min(title.fullWidth, cloneScreenWidth);
|
|
|
|
let xoff = ((cloneScreenWidth - title.width) / 2) * title.scale_x;
|
|
|
|
title.set_position(this.actor.x + xoff, this.actor.y);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showTitle : function () {
|
|
|
|
if (!this._title)
|
|
|
|
this._createTitle();
|
|
|
|
|
|
|
|
this._adjustTitle();
|
|
|
|
this._title.show();
|
|
|
|
this._title.raise(this.actor);
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideTitle : function () {
|
|
|
|
if (!this._title)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._title.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateTitle : function () {
|
|
|
|
let shouldShow = (this._havePointer &&
|
2009-02-10 11:15:59 -05:00
|
|
|
!this._inDrag &&
|
2009-02-10 11:12:58 -05:00
|
|
|
!Tweener.isTweening(this.actor));
|
2009-01-29 16:21:50 -05:00
|
|
|
|
|
|
|
if (shouldShow)
|
|
|
|
this._showTitle();
|
|
|
|
else
|
|
|
|
this._hideTitle();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(WindowClone.prototype);
|
|
|
|
|
|
|
|
|
|
|
|
function DesktopClone(window) {
|
|
|
|
this._init(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
DesktopClone.prototype = {
|
|
|
|
_init : function(window) {
|
|
|
|
if (window) {
|
2009-02-23 14:42:00 -05:00
|
|
|
this.actor = new Clutter.Clone({ source: window.get_texture(),
|
|
|
|
reactive: true });
|
2009-01-29 16:21:50 -05:00
|
|
|
} else {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
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-07-23 17:36:41 -04: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 16:51:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Workspace.prototype = {
|
2009-07-23 17:36:41 -04:00
|
|
|
_init : function(workspaceNum, parentActor) {
|
2008-12-22 16:51:34 -05:00
|
|
|
let me = this;
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
this.workspaceNum = workspaceNum;
|
2009-02-04 09:50:50 -05:00
|
|
|
this._metaWorkspace = global.screen.get_workspace_by_index(workspaceNum);
|
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
this.parentActor = parentActor;
|
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
this.actor = new Clutter.Group();
|
2009-02-10 11:15:59 -05:00
|
|
|
this.actor._delegate = this;
|
2009-08-12 22:07:10 -04: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 16:12:49 -05:00
|
|
|
this.scale = 1.0;
|
2008-12-22 16:51:34 -05: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 16:21:50 -05:00
|
|
|
this._desktop = new DesktopClone(windows[i]);
|
2008-12-22 16:51:34 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there wasn't one, fake it
|
|
|
|
if (!this._desktop)
|
2009-01-29 16:21:50 -05:00
|
|
|
this._desktop = new DesktopClone();
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2009-01-29 16:21:50 -05:00
|
|
|
this._desktop.connect('selected',
|
2009-02-04 09:50:50 -05:00
|
|
|
Lang.bind(this,
|
|
|
|
function(clone, time) {
|
|
|
|
this._metaWorkspace.activate(time);
|
2009-08-11 07:46:10 -04:00
|
|
|
Main.overview.hide();
|
2009-02-04 09:50:50 -05:00
|
|
|
}));
|
2009-01-29 16:21:50 -05:00
|
|
|
this.actor.add_actor(this._desktop.actor);
|
2008-12-22 16:51:34 -05:00
|
|
|
|
|
|
|
// Create clones for remaining windows that should be
|
2009-08-11 07:46:10 -04:00
|
|
|
// visible in the Overview
|
2008-12-22 16:51:34 -05:00
|
|
|
this._windows = [this._desktop];
|
2009-07-23 17:36:41 -04:00
|
|
|
this._windowIcons = [ null ];
|
2008-12-22 16:51:34 -05:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2009-08-11 07:46:10 -04:00
|
|
|
if (this._isOverviewWindow(windows[i])) {
|
2009-01-23 14:21:20 -05:00
|
|
|
this._addWindowClone(windows[i]);
|
2008-12-22 16:51:34 -05:00
|
|
|
}
|
|
|
|
}
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2009-02-04 09:50:50 -05: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 17:06:47 -05:00
|
|
|
this._removeButton = null;
|
|
|
|
this._visible = false;
|
2009-01-21 16:12:49 -05:00
|
|
|
|
|
|
|
this._frame = null;
|
2009-02-03 17:58:33 -05:00
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
this.leavingOverview = false;
|
2008-12-22 17:06:47 -05:00
|
|
|
},
|
|
|
|
|
2009-02-04 09:50:50 -05:00
|
|
|
updateRemovable : function() {
|
2008-12-22 17:06:47 -05:00
|
|
|
let global = Shell.Global.get();
|
2009-02-04 09:50:50 -05:00
|
|
|
let removable = (this._windows.length == 1 /* just desktop */ &&
|
2009-07-14 08:37:21 -04:00
|
|
|
this.workspaceNum != 0 &&
|
2009-02-04 09:50:50 -05:00
|
|
|
this.workspaceNum == global.screen.n_workspaces - 1);
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
if (removable) {
|
|
|
|
if (this._removeButton)
|
|
|
|
return;
|
|
|
|
|
2009-02-10 17:38:06 -05:00
|
|
|
this._removeButton = new Clutter.Texture({ width: buttonSize,
|
|
|
|
height: buttonSize,
|
2008-12-22 17:06:47 -05:00
|
|
|
reactive: true
|
|
|
|
});
|
|
|
|
this._removeButton.set_from_file(global.imagedir + "remove-workspace.svg");
|
2009-02-02 15:54:33 -05:00
|
|
|
this._removeButton.connect('button-release-event', Lang.bind(this, this._removeSelf));
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
this.actor.add_actor(this._removeButton);
|
2009-01-21 15:35:20 -05:00
|
|
|
this._adjustRemoveButton();
|
|
|
|
this._adjustRemoveButtonId = this.actor.connect('notify::scale-x', Lang.bind(this, this._adjustRemoveButton));
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
if (this._visible) {
|
|
|
|
this._removeButton.set_opacity(0);
|
|
|
|
Tweener.addTween(this._removeButton,
|
|
|
|
{ opacity: 255,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 17:06:47 -05:00
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!this._removeButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._visible) {
|
|
|
|
Tweener.addTween(this._removeButton,
|
|
|
|
{ opacity: 0,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 17:06:47 -05:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: this._removeRemoveButton,
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
2009-01-21 15:35:20 -05:00
|
|
|
} else
|
|
|
|
this._removeRemoveButton();
|
2008-12-22 17:06:47 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
_lookupIndex: function (metaWindow) {
|
2009-07-31 17:20:26 -04:00
|
|
|
let index, clone;
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
if (this._windows[i].metaWindow == metaWindow) {
|
2009-07-23 17:36:41 -04:00
|
|
|
return i;
|
2009-07-31 17:20:26 -04:00
|
|
|
}
|
|
|
|
}
|
2009-07-23 17:36:41 -04:00
|
|
|
return -1;
|
2009-07-31 17:20:26 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
lookupCloneForMetaWindow: function (metaWindow) {
|
2009-07-23 17:36:41 -04:00
|
|
|
let index = this._lookupIndex (metaWindow);
|
|
|
|
return index < 0 ? null : this._windows[index];
|
2009-07-31 17:20:26 -04:00
|
|
|
},
|
|
|
|
|
2009-01-21 15:35:20 -05: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 17:06:47 -05:00
|
|
|
_removeRemoveButton : function() {
|
|
|
|
this._removeButton.destroy();
|
|
|
|
this._removeButton = null;
|
2009-01-21 15:35:20 -05:00
|
|
|
this.actor.disconnect(this._adjustRemoveButtonId);
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
2009-01-21 16:12:49 -05:00
|
|
|
// Mark the workspace selected/not-selected
|
|
|
|
setSelected : function(selected) {
|
2009-08-09 19:48:54 -04:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
// Don't draw a frame if we only have one workspace
|
|
|
|
if (selected && global.screen.n_workspaces > 1) {
|
2009-01-21 16:12:49 -05: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 16:21:50 -05: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 16:12:49 -05:00
|
|
|
this._frame.lower_bottom();
|
|
|
|
|
2009-08-08 00:31:47 -04:00
|
|
|
this._framePosHandler = this.actor.connect('notify::scale-x', Lang.bind(this, this._updateFramePosition));
|
2009-01-21 16:12:49 -05:00
|
|
|
} else {
|
|
|
|
if (!this._frame)
|
|
|
|
return;
|
|
|
|
this.actor.disconnect(this._framePosHandler);
|
|
|
|
this._frame.destroy();
|
|
|
|
this._frame = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateFramePosition : function() {
|
2009-01-29 16:21:50 -05: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 16:12:49 -05:00
|
|
|
},
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
// Reposition all windows in their zoomed-to-Overview position. if workspaceZooming
|
2009-01-23 14:21:20 -05:00
|
|
|
// is true, then the workspace is moving at the same time and we need to take
|
|
|
|
// that into account
|
2009-08-08 00:45:06 -04:00
|
|
|
positionWindows : function(workspaceZooming) {
|
2008-12-22 16:51:34 -05:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
2009-07-23 17:36:41 -04:00
|
|
|
let icon = this._windowIcons[i];
|
2009-01-29 16:21:50 -05:00
|
|
|
clone.stackAbove = this._windows[i - 1].actor;
|
2009-01-23 14:21:20 -05:00
|
|
|
|
|
|
|
let [xCenter, yCenter, fraction] = this._computeWindowPosition(i);
|
|
|
|
xCenter = xCenter * global.screen_width;
|
|
|
|
yCenter = yCenter * global.screen_height;
|
|
|
|
|
2009-08-08 00:36:59 -04:00
|
|
|
// clone.actor.width/height aren't reliably set at this point for
|
|
|
|
// a new window - they're only set when the window contents are
|
|
|
|
// initially updated prior to painting.
|
|
|
|
let cloneRect = new Meta.Rectangle();
|
|
|
|
clone.realWindow.meta_window.get_outer_rect(cloneRect);
|
|
|
|
|
2009-08-08 16:10:40 -04:00
|
|
|
let desiredWidth = global.screen_width * fraction;
|
|
|
|
let desiredHeight = global.screen_height * fraction;
|
2009-08-08 00:36:59 -04:00
|
|
|
let scale = Math.min(desiredWidth / cloneRect.width, desiredHeight / cloneRect.height, 1.0 / this.scale);
|
2009-01-23 14:21:20 -05:00
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
icon.hide();
|
2009-02-10 11:12:58 -05:00
|
|
|
Tweener.addTween(clone.actor,
|
2009-08-08 00:36:59 -04:00
|
|
|
{ x: xCenter - 0.5 * scale * cloneRect.width,
|
|
|
|
y: yCenter - 0.5 * scale * cloneRect.height,
|
2009-02-10 11:12:58 -05:00
|
|
|
scale_x: scale,
|
|
|
|
scale_y: scale,
|
|
|
|
workspace_relative: workspaceZooming ? this : null,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-07-23 17:36:41 -04:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
this._fadeInWindowIcon(clone, icon);
|
|
|
|
})
|
2009-02-10 11:12:58 -05:00
|
|
|
});
|
2009-01-23 14:21:20 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
_fadeInWindowIcon: function (clone, icon) {
|
|
|
|
icon.opacity = 0;
|
|
|
|
icon.show();
|
2009-08-08 00:41:46 -04:00
|
|
|
// This is a little messy and complicated because when we
|
|
|
|
// start the fade-in we may not have done the final positioning
|
|
|
|
// of the workspaces. (Tweener doesn't necessarily finish
|
|
|
|
// all animations before calling onComplete callbacks.)
|
|
|
|
// So we need to manually compute where the window will
|
|
|
|
// be after the workspace animation finishes.
|
|
|
|
let [parentX, parentY] = icon.get_parent().get_position();
|
|
|
|
let [cloneX, cloneY] = clone.actor.get_position();
|
|
|
|
let [cloneWidth, cloneHeight] = clone.actor.get_size();
|
|
|
|
cloneX = this.gridX + this.scale * cloneX;
|
|
|
|
cloneY = this.gridY + this.scale * cloneY;
|
|
|
|
cloneWidth = this.scale * clone.actor.scale_x * cloneWidth;
|
|
|
|
cloneHeight = this.scale * clone.actor.scale_y * cloneHeight;
|
2009-07-23 17:36:41 -04:00
|
|
|
// Note we only round the first part, because we're still going to be
|
|
|
|
// positioned relative to the parent. By subtracting a possibly
|
|
|
|
// non-integral parent X/Y we cancel it out.
|
|
|
|
let x = Math.round(cloneX + cloneWidth - icon.width) - parentX;
|
|
|
|
let y = Math.round(cloneY + cloneHeight - icon.height) - parentY;
|
|
|
|
icon.set_position(x, y);
|
|
|
|
icon.raise(this.actor);
|
|
|
|
Tweener.addTween(icon,
|
|
|
|
{ opacity: 255,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-07-23 17:36:41 -04:00
|
|
|
transition: "easeOutQuad" });
|
|
|
|
},
|
|
|
|
|
|
|
|
_fadeInAllIcons: function () {
|
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
|
|
|
let clone = this._windows[i];
|
|
|
|
let icon = this._windowIcons[i];
|
|
|
|
this._fadeInWindowIcon(clone, icon);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideAllIcons: function () {
|
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
|
|
|
let icon = this._windowIcons[i];
|
|
|
|
icon.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-02-04 09:50:50 -05:00
|
|
|
_windowRemoved : function(metaWorkspace, metaWin) {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
let win = metaWin.get_compositor_private();
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
// find the position of the window in our list
|
2009-07-23 17:36:41 -04:00
|
|
|
let index = this._lookupIndex (metaWin);
|
2009-01-23 14:21:20 -05:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
2009-02-10 11:15:59 -05:00
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
let clone = this._windows[index];
|
|
|
|
let icon = this._windowIcons[index];
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
this._windows.splice(index, 1);
|
2009-07-23 17:36:41 -04:00
|
|
|
this._windowIcons.splice(index, 1);
|
2009-02-04 09:50:50 -05:00
|
|
|
|
|
|
|
// If metaWin.get_compositor_private() returned non-NULL, that
|
|
|
|
// means the window still exists (and is just being moved to
|
2009-08-11 07:46:10 -04:00
|
|
|
// another workspace or something), so set its overviewHint
|
2009-02-04 09:50:50 -05: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 07:46:10 -04:00
|
|
|
win._overviewHint = {
|
2009-02-04 09:50:50 -05:00
|
|
|
x: stageX,
|
|
|
|
y: stageY,
|
|
|
|
scale: stageWidth / clone.actor.width
|
|
|
|
};
|
|
|
|
}
|
2009-01-23 14:21:20 -05:00
|
|
|
clone.destroy();
|
2009-07-23 17:36:41 -04:00
|
|
|
icon.destroy();
|
2009-01-23 14:21:20 -05:00
|
|
|
|
2009-08-08 00:45:06 -04:00
|
|
|
this.positionWindows(false);
|
2009-02-04 09:50:50 -05:00
|
|
|
this.updateRemovable();
|
2009-01-23 14:21:20 -05:00
|
|
|
},
|
|
|
|
|
2009-02-04 09:50:50 -05:00
|
|
|
_windowAdded : function(metaWorkspace, metaWin) {
|
2009-08-11 07:46:10 -04:00
|
|
|
if (this.leavingOverview)
|
2009-03-17 18:22:25 -04:00
|
|
|
return;
|
|
|
|
|
2009-02-04 09:50:50 -05: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 13:24:20 -05:00
|
|
|
if (this.actor && metaWin.get_compositor_private())
|
2009-02-04 09:50:50 -05:00
|
|
|
this._windowAdded(metaWorkspace, metaWin);
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
2009-02-04 17:40:24 -05:00
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
if (!this._isOverviewWindow(win))
|
2009-02-04 17:40:24 -05:00
|
|
|
return;
|
2009-02-04 09:50:50 -05:00
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
let clone = this._addWindowClone(win);
|
2009-02-04 09:50:50 -05:00
|
|
|
|
2009-08-11 07:46:10 -04: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 09:50:50 -05:00
|
|
|
|
|
|
|
clone.actor.set_position (x, y);
|
|
|
|
clone.actor.set_scale (scale, scale);
|
|
|
|
}
|
|
|
|
|
2009-08-08 00:45:06 -04:00
|
|
|
this.positionWindows(false);
|
2009-02-04 09:50:50 -05:00
|
|
|
this.updateRemovable();
|
2009-01-23 14:21:20 -05:00
|
|
|
},
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
// Animate the full-screen to Overview transition.
|
|
|
|
zoomToOverview : function() {
|
2009-08-10 18:31:39 -04:00
|
|
|
this.actor.set_position(this.gridX, this.gridY);
|
|
|
|
this.actor.set_scale(this.scale, this.scale);
|
2009-02-03 17:58:33 -05:00
|
|
|
|
2009-08-10 18:31:39 -04:00
|
|
|
// Position and scale the windows.
|
|
|
|
this.positionWindows(true);
|
2009-02-03 17:58:33 -05:00
|
|
|
|
2009-08-10 18:31:39 -04: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 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-08-10 18:31:39 -04:00
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
|
|
|
}
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2009-08-10 18:31:39 -04:00
|
|
|
this._visible = true;
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
// Animates the return from Overview mode
|
|
|
|
zoomFromOverview : function() {
|
|
|
|
this.leavingOverview = true;
|
2009-07-23 17:36:41 -04:00
|
|
|
|
|
|
|
this._hideAllIcons();
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
Main.overview.connect('hidden', Lang.bind(this,
|
|
|
|
this._doneLeavingOverview));
|
2009-08-10 18:31:39 -04: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 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-08-10 18:31:39 -04:00
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
|
|
|
}
|
2009-01-21 15:35:20 -05:00
|
|
|
|
2009-08-10 18:31:39 -04:00
|
|
|
// Position and scale the windows.
|
2009-01-21 15:35:20 -05:00
|
|
|
for (let i = 1; i < this._windows.length; i++) {
|
2009-01-29 16:21:50 -05:00
|
|
|
let clone = this._windows[i];
|
2009-02-10 11:12:58 -05: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 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-02-10 11:12:58 -05:00
|
|
|
opacity: 255,
|
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
2008-12-22 16:51:34 -05:00
|
|
|
}
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2009-03-17 18:22:25 -04:00
|
|
|
this._visible = false;
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Animates grid shrinking/expanding when a row or column
|
|
|
|
// of workspaces is added or removed
|
|
|
|
resizeToGrid : function (oldScale) {
|
2009-07-23 17:36:41 -04:00
|
|
|
this._hideAllIcons();
|
2009-01-21 15:35:20 -05:00
|
|
|
Tweener.addTween(this.actor,
|
|
|
|
{ x: this.gridX,
|
|
|
|
y: this.gridY,
|
|
|
|
scale_x: this.scale,
|
|
|
|
scale_y: this.scale,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2009-07-23 17:36:41 -04:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: Lang.bind(this, this._fadeInAllIcons)
|
2009-01-21 15:35:20 -05:00
|
|
|
});
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
2009-07-23 17:36:41 -04:00
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
// Animates the addition of a new (empty) workspace
|
|
|
|
slideIn : function(oldScale) {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
|
|
|
if (this.gridCol > this.gridRow) {
|
2009-01-21 15:35:20 -05:00
|
|
|
this.actor.set_position(global.screen_width, this.gridY);
|
|
|
|
this.actor.set_scale(oldScale, oldScale);
|
2008-12-22 16:51:34 -05:00
|
|
|
} else {
|
2009-01-21 15:35:20 -05:00
|
|
|
this.actor.set_position(this.gridX, global.screen_height);
|
|
|
|
this.actor.set_scale(this.scale, this.scale);
|
2008-12-22 16:51:34 -05:00
|
|
|
}
|
2009-01-21 15:35:20 -05:00
|
|
|
Tweener.addTween(this.actor,
|
2008-12-22 16:51:34 -05:00
|
|
|
{ x: this.gridX,
|
|
|
|
y: this.gridY,
|
|
|
|
scale_x: this.scale,
|
|
|
|
scale_y: this.scale,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 16:51:34 -05:00
|
|
|
transition: "easeOutQuad"
|
|
|
|
});
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
this._visible = true;
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Animates the removal of a workspace
|
|
|
|
slideOut : function(onComplete) {
|
|
|
|
let global = Shell.Global.get();
|
2009-01-21 15:35:20 -05:00
|
|
|
let destX = this.actor.x, destY = this.actor.y;
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
this._hideAllIcons();
|
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
if (this.gridCol > this.gridRow)
|
|
|
|
destX = global.screen_width;
|
|
|
|
else
|
|
|
|
destY = global.screen_height;
|
2009-01-21 15:35:20 -05:00
|
|
|
Tweener.addTween(this.actor,
|
2008-12-22 16:51:34 -05:00
|
|
|
{ x: destX,
|
|
|
|
y: destY,
|
|
|
|
scale_x: this.scale,
|
|
|
|
scale_y: this.scale,
|
2009-08-11 07:46:10 -04:00
|
|
|
time: Overview.ANIMATION_TIME,
|
2008-12-22 16:51:34 -05:00
|
|
|
transition: "easeOutQuad",
|
|
|
|
onComplete: onComplete
|
|
|
|
});
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
this._visible = false;
|
2009-02-02 15:54:33 -05:00
|
|
|
|
|
|
|
// Don't let the user try to select this workspace as it's
|
|
|
|
// making its exit.
|
|
|
|
this._desktop.reactive = false;
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy : function() {
|
2009-02-04 09:50:50 -05:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
Tweener.removeTweens(this.actor);
|
2008-12-22 16:51:34 -05:00
|
|
|
this.actor.destroy();
|
|
|
|
this.actor = null;
|
2009-02-04 09:50:50 -05:00
|
|
|
|
|
|
|
this._metaWorkspace.disconnect(this._windowAddedId);
|
|
|
|
this._metaWorkspace.disconnect(this._windowRemovedId);
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
// Sets this.leavingOverview flag to false.
|
|
|
|
_doneLeavingOverview : function() {
|
|
|
|
this.leavingOverview = false;
|
2009-03-17 18:22:25 -04:00
|
|
|
},
|
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
// Tests if @win belongs to this workspaces
|
|
|
|
_isMyWindow : function (win) {
|
2009-01-23 14:21:20 -05:00
|
|
|
return win.get_workspace() == this.workspaceNum ||
|
2008-12-22 16:51:34 -05:00
|
|
|
(win.get_meta_window() && win.get_meta_window().is_on_all_workspaces());
|
|
|
|
},
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
// Tests if @win should be shown in the Overview
|
|
|
|
_isOverviewWindow : function (win) {
|
2009-01-19 18:06:59 -05:00
|
|
|
let wintype = win.get_window_type();
|
|
|
|
if (wintype == Meta.WindowType.DESKTOP ||
|
|
|
|
wintype == Meta.WindowType.DOCK)
|
|
|
|
return false;
|
|
|
|
return !win.is_override_redirect();
|
2008-12-22 16:51:34 -05:00
|
|
|
},
|
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
_createWindowIcon: function(window) {
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
let appMon = Shell.AppMonitor.get_default()
|
|
|
|
let appInfo = appMon.get_window_app(window.metaWindow);
|
|
|
|
let iconTexture = null;
|
|
|
|
// The design is application based, so prefer the application
|
|
|
|
// icon here if we have it. FIXME - should move this fallback code
|
|
|
|
// into ShellAppMonitor.
|
|
|
|
if (appInfo) {
|
|
|
|
iconTexture = appInfo.create_icon_texture(48);
|
|
|
|
} else {
|
|
|
|
let icon = window.metaWindow.icon;
|
|
|
|
iconTexture = new Clutter.Texture({ width: 48,
|
|
|
|
height: 48,
|
|
|
|
keep_aspect_ratio: true });
|
|
|
|
Shell.clutter_texture_set_from_pixbuf(iconTexture, icon);
|
|
|
|
}
|
|
|
|
return iconTexture;
|
|
|
|
},
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
// Create a clone of a (non-desktop) window and add it to the window list
|
|
|
|
_addWindowClone : function(win) {
|
2009-07-23 17:36:41 -04:00
|
|
|
let icon = this._createWindowIcon(win);
|
|
|
|
this.parentActor.add_actor(icon);
|
|
|
|
|
2009-01-29 16:21:50 -05:00
|
|
|
let clone = new WindowClone(win);
|
|
|
|
clone.connect('selected',
|
|
|
|
Lang.bind(this, this._onCloneSelected));
|
2009-07-23 17:36:41 -04:00
|
|
|
clone.connect('drag-begin',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
icon.hide();
|
|
|
|
}));
|
|
|
|
clone.connect('drag-end',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
icon.show();
|
|
|
|
}));
|
2009-01-23 14:21:20 -05:00
|
|
|
|
2009-01-29 16:21:50 -05:00
|
|
|
this.actor.add_actor(clone.actor);
|
2009-07-23 17:36:41 -04:00
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
this._windows.push(clone);
|
2009-07-23 17:36:41 -04:00
|
|
|
this._windowIcons.push(icon);
|
2009-01-23 14:21:20 -05:00
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
return clone;
|
|
|
|
},
|
|
|
|
|
|
|
|
_computeWindowPosition : function(index) {
|
|
|
|
// ignore this._windows[0], which is the desktop
|
|
|
|
let windowIndex = index - 1;
|
|
|
|
let numberOfWindows = this._windows.length - 1;
|
|
|
|
|
|
|
|
if (numberOfWindows in POSITIONS)
|
|
|
|
return POSITIONS[numberOfWindows][windowIndex];
|
|
|
|
|
|
|
|
// If we don't have a predefined scheme for this window count,
|
2009-03-31 17:40:18 -04:00
|
|
|
// arrange the windows in a grid pattern.
|
|
|
|
let gridWidth = Math.ceil(Math.sqrt(numberOfWindows));
|
|
|
|
let gridHeight = Math.ceil(numberOfWindows / gridWidth);
|
|
|
|
|
2009-08-08 16:10:40 -04:00
|
|
|
let fraction = 0.95 * (1. / gridWidth);
|
2009-03-31 17:40:18 -04:00
|
|
|
|
|
|
|
let xCenter = (.5 / gridWidth) + ((windowIndex) % gridWidth) / gridWidth;
|
|
|
|
let yCenter = (.5 / gridHeight) + Math.floor((windowIndex / gridWidth)) / gridHeight;
|
2008-12-22 16:51:34 -05:00
|
|
|
|
|
|
|
return [xCenter, yCenter, fraction];
|
|
|
|
},
|
2009-01-21 15:35:20 -05:00
|
|
|
|
2009-01-29 16:21:50 -05:00
|
|
|
_onCloneSelected : function (clone, time) {
|
2009-08-11 07:46:10 -04:00
|
|
|
Main.overview.activateWindow(clone.metaWindow, time);
|
2008-12-22 17:06:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeSelf : function(actor, event) {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
let screen = global.screen;
|
2009-01-23 14:21:20 -05:00
|
|
|
let workspace = screen.get_workspace_by_index(this.workspaceNum);
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
screen.remove_workspace(workspace, event.get_time());
|
2009-02-02 15:54:33 -05:00
|
|
|
return true;
|
2009-02-10 11:15:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Draggable target interface
|
|
|
|
acceptDrop : function(source, actor, x, y, time) {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
|
|
|
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 07:46:10 -04:00
|
|
|
win._overviewHint = {
|
2009-02-10 11:15:59 -05: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-17 20:29:54 -04:00
|
|
|
} else if (source.shellWorkspaceLaunch) {
|
2009-02-10 11:15:59 -05:00
|
|
|
this._metaWorkspace.activate(time);
|
2009-08-17 20:29:54 -04:00
|
|
|
source.shellWorkspaceLaunch();
|
2009-02-10 11:15:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-12-22 16:51:34 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
Signals.addSignalMethods(Workspace.prototype);
|
|
|
|
|
2009-02-10 17:38:06 -05:00
|
|
|
function Workspaces(width, height, x, y, addButtonSize, addButtonX, addButtonY) {
|
|
|
|
this._init(width, height, x, y, addButtonSize, addButtonX, addButtonY);
|
2008-12-02 11:15:00 -05:00
|
|
|
}
|
|
|
|
|
2008-12-04 10:20:37 -05:00
|
|
|
Workspaces.prototype = {
|
2009-02-10 17:38:06 -05:00
|
|
|
_init : function(width, height, x, y, addButtonSize, addButtonX, addButtonY) {
|
2008-12-22 16:50:23 -05:00
|
|
|
let global = Shell.Global.get();
|
2008-12-15 16:03:07 -05:00
|
|
|
|
2008-12-15 15:48:59 -05:00
|
|
|
this.actor = new Clutter.Group();
|
2008-12-04 10:16:16 -05:00
|
|
|
|
2008-12-22 16:50:23 -05:00
|
|
|
let screenHeight = global.screen_height;
|
2009-02-10 17:38:06 -05:00
|
|
|
|
|
|
|
this._width = width;
|
|
|
|
this._height = height;
|
|
|
|
this._x = x;
|
|
|
|
this._y = y;
|
2008-12-22 16:50:23 -05:00
|
|
|
|
2008-12-04 10:16:16 -05:00
|
|
|
this._workspaces = [];
|
2008-12-18 13:50:09 -05:00
|
|
|
|
2008-12-15 15:55:24 -05:00
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
let activeWorkspace;
|
2008-12-04 10:16:16 -05:00
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
// Create and position workspace objects
|
2008-12-04 10:16:16 -05:00
|
|
|
for (let w = 0; w < global.screen.n_workspaces; w++) {
|
2009-01-23 14:21:20 -05:00
|
|
|
this._addWorkspaceActor(w);
|
2009-01-21 16:12:49 -05:00
|
|
|
if (w == activeWorkspaceIndex) {
|
2008-12-15 15:55:24 -05:00
|
|
|
activeWorkspace = this._workspaces[w];
|
2009-01-21 16:12:49 -05:00
|
|
|
activeWorkspace.setSelected(true);
|
|
|
|
}
|
2008-12-02 11:15:00 -05:00
|
|
|
}
|
2008-12-22 16:51:34 -05:00
|
|
|
activeWorkspace.actor.raise_top();
|
2008-12-15 15:55:24 -05:00
|
|
|
this._positionWorkspaces(global, activeWorkspace);
|
2008-12-04 10:16:16 -05:00
|
|
|
|
2009-08-12 20:02:59 -04:00
|
|
|
// Save the button size as a global variable so we can us it to create
|
|
|
|
// matching button sizes for workspace remove buttons.
|
2009-02-10 17:38:06 -05:00
|
|
|
buttonSize = addButtonSize;
|
2009-08-12 20:02:59 -04:00
|
|
|
|
|
|
|
// Create (+) button
|
|
|
|
this.addButton = new AddWorkspaceButton(addButtonSize, addButtonX, addButtonY, Lang.bind(this, this._addWorkspaceAcceptDrop));
|
|
|
|
this.addButton.actor.connect('button-release-event', Lang.bind(this, this._appendNewWorkspace));
|
|
|
|
this.actor.add_actor(this.addButton.actor);
|
|
|
|
this.addButton.actor.lower_bottom();
|
2008-12-22 17:06:47 -05:00
|
|
|
|
|
|
|
let lastWorkspace = this._workspaces[this._workspaces.length - 1];
|
2009-02-04 09:50:50 -05:00
|
|
|
lastWorkspace.updateRemovable(true);
|
2008-12-04 10:16:16 -05:00
|
|
|
|
2009-08-10 18:31:39 -04: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 07:46:10 -04:00
|
|
|
// as an Overview member.
|
|
|
|
Main.overview.connect('showing',
|
2009-08-10 18:31:39 -04:00
|
|
|
Lang.bind(this, function() {
|
|
|
|
for (let w = 0; w < this._workspaces.length; w++)
|
2009-08-11 07:46:10 -04:00
|
|
|
this._workspaces[w].zoomToOverview();
|
2009-08-10 18:31:39 -04:00
|
|
|
}));
|
2008-12-15 16:03:07 -05:00
|
|
|
|
|
|
|
// Track changes to the number of workspaces
|
|
|
|
this._nWorkspacesNotifyId =
|
|
|
|
global.screen.connect('notify::n-workspaces',
|
2009-01-21 16:12:49 -05:00
|
|
|
Lang.bind(this, this._workspacesChanged));
|
|
|
|
this._switchWorkspaceNotifyId =
|
|
|
|
global.window_manager.connect('switch-workspace',
|
|
|
|
Lang.bind(this, this._activeWorkspaceChanged));
|
2008-12-04 10:16:16 -05:00
|
|
|
},
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2009-07-31 17:20:26 -04:00
|
|
|
_lookupCloneForMetaWindow: function (metaWindow) {
|
|
|
|
for (let i = 0; i < this._workspaces.length; i++) {
|
|
|
|
let clone = this._workspaces[i].lookupCloneForMetaWindow(metaWindow);
|
|
|
|
if (clone)
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-08-11 07:46:10 -04:00
|
|
|
// Should only be called from active Overview context
|
|
|
|
activateWindowFromOverview: function (metaWindow, time) {
|
2009-07-31 17:20:26 -04:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
let activeWorkspaceNum = global.screen.get_active_workspace_index();
|
|
|
|
let windowWorkspaceNum = metaWindow.get_workspace().index();
|
|
|
|
|
|
|
|
let clone = this._lookupCloneForMetaWindow (metaWindow);
|
|
|
|
clone.actor.raise_top();
|
|
|
|
|
|
|
|
if (windowWorkspaceNum != activeWorkspaceNum) {
|
|
|
|
let workspace = global.screen.get_workspace_by_index(windowWorkspaceNum);
|
|
|
|
workspace.activate_with_focus(metaWindow, time);
|
|
|
|
} else {
|
|
|
|
metaWindow.activate(time);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-04 10:16:16 -05:00
|
|
|
hide : function() {
|
|
|
|
let global = Shell.Global.get();
|
2008-12-15 15:55:24 -05:00
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
let activeWorkspace = this._workspaces[activeWorkspaceIndex];
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2008-12-15 15:55:24 -05:00
|
|
|
this._positionWorkspaces(global, activeWorkspace);
|
2008-12-22 16:51:34 -05:00
|
|
|
activeWorkspace.actor.raise_top();
|
2008-12-15 15:55:24 -05:00
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
for (let w = 0; w < this._workspaces.length; w++)
|
2009-08-11 07:46:10 -04:00
|
|
|
this._workspaces[w].zoomFromOverview();
|
2008-12-04 10:16:16 -05:00
|
|
|
},
|
2008-12-15 15:48:59 -05:00
|
|
|
|
|
|
|
destroy : function() {
|
2008-12-15 16:03:07 -05:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
for (let w = 0; w < this._workspaces.length; w++)
|
2008-12-04 10:16:16 -05:00
|
|
|
this._workspaces[w].destroy();
|
|
|
|
this._workspaces = [];
|
2008-12-15 15:55:24 -05:00
|
|
|
|
2008-12-22 17:06:47 -05:00
|
|
|
this.actor.destroy();
|
|
|
|
this.actor = null;
|
2008-12-15 16:03:07 -05:00
|
|
|
|
|
|
|
global.screen.disconnect(this._nWorkspacesNotifyId);
|
2009-01-21 16:12:49 -05:00
|
|
|
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
|
2008-12-15 15:55:24 -05:00
|
|
|
},
|
|
|
|
|
2009-08-10 18:31:39 -04:00
|
|
|
getScale : function() {
|
|
|
|
return this._workspaces[0].scale;
|
2009-04-21 20:23:06 -04:00
|
|
|
},
|
|
|
|
|
2009-08-10 18:31:39 -04:00
|
|
|
// Get the grid position of the active workspace.
|
|
|
|
getActiveWorkspacePosition : function() {
|
2009-04-21 20:23:06 -04:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
let activeWorkspace = this._workspaces[activeWorkspaceIndex];
|
|
|
|
|
2009-08-10 18:31:39 -04:00
|
|
|
return [activeWorkspace.gridX, activeWorkspace.gridY];
|
2009-02-03 17:58:33 -05:00
|
|
|
},
|
|
|
|
|
2008-12-15 15:58:10 -05: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!
|
2008-12-15 15:55:24 -05:00
|
|
|
_positionWorkspaces : function(global, activeWorkspace) {
|
2008-12-15 16:03:07 -05:00
|
|
|
if (!activeWorkspace) {
|
|
|
|
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
|
|
|
|
activeWorkspace = this._workspaces[activeWorkspaceIndex];
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:55:24 -05: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 15:58:10 -05:00
|
|
|
let span = 1, n = 0, row = 0, col = 0, horiz = true;
|
|
|
|
|
|
|
|
for (let w = 0; w < this._workspaces.length; w++) {
|
2008-12-15 15:55:24 -05: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 16:51:34 -05:00
|
|
|
workspace.scale = scale;
|
2008-12-15 15:55:24 -05:00
|
|
|
|
2008-12-15 15:58:10 -05:00
|
|
|
if (horiz) {
|
|
|
|
col++;
|
|
|
|
if (col == span) {
|
|
|
|
row = 0;
|
|
|
|
horiz = false;
|
|
|
|
}
|
|
|
|
} else {
|
2008-12-15 15:55:24 -05:00
|
|
|
row++;
|
2008-12-15 15:58:10 -05:00
|
|
|
if (row == span) {
|
|
|
|
col = 0;
|
|
|
|
horiz = true;
|
|
|
|
span++;
|
|
|
|
}
|
2008-12-15 15:55:24 -05:00
|
|
|
}
|
|
|
|
}
|
2008-12-02 11:15:00 -05:00
|
|
|
},
|
|
|
|
|
2008-12-15 16:03:07 -05:00
|
|
|
_workspacesChanged : function() {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
|
|
|
let oldNumWorkspaces = this._workspaces.length;
|
|
|
|
let newNumWorkspaces = global.screen.n_workspaces;
|
|
|
|
|
|
|
|
if (oldNumWorkspaces == newNumWorkspaces)
|
|
|
|
return;
|
|
|
|
|
2008-12-22 16:51:34 -05:00
|
|
|
let oldScale = this._workspaces[0].scale;
|
2008-12-15 16:03:07 -05:00
|
|
|
let oldGridWidth = Math.ceil(Math.sqrt(oldNumWorkspaces));
|
|
|
|
let oldGridHeight = Math.ceil(oldNumWorkspaces / oldGridWidth);
|
|
|
|
let lostWorkspaces = [];
|
|
|
|
|
2008-12-22 17:06:47 -05:00
|
|
|
// The old last workspace is no longer removable.
|
2009-02-04 09:50:50 -05:00
|
|
|
this._workspaces[oldNumWorkspaces - 1].updateRemovable();
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2008-12-15 16:03:07 -05:00
|
|
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
|
|
|
// Create new workspace groups
|
|
|
|
for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++) {
|
2009-01-23 14:21:20 -05:00
|
|
|
this._addWorkspaceActor(w);
|
2008-12-15 16:03:07 -05:00
|
|
|
}
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2008-12-15 16:03:07 -05: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 17:06:47 -05:00
|
|
|
// The new last workspace may be removable
|
|
|
|
let newLastWorkspace = this._workspaces[this._workspaces.length - 1];
|
2009-02-04 09:50:50 -05:00
|
|
|
newLastWorkspace.updateRemovable();
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2008-12-15 16:03:07 -05:00
|
|
|
// Figure out the new layout
|
|
|
|
this._positionWorkspaces(global);
|
2008-12-22 16:51:34 -05:00
|
|
|
let newScale = this._workspaces[0].scale;
|
2008-12-15 16:03:07 -05: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 16:51:34 -05:00
|
|
|
for (let w = 0; w < existingWorkspaces; w++)
|
|
|
|
this._workspaces[w].resizeToGrid(oldScale);
|
2008-12-15 16:03:07 -05:00
|
|
|
}
|
|
|
|
|
2009-08-08 00:45:06 -04: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 16:03:07 -05:00
|
|
|
if (newNumWorkspaces > oldNumWorkspaces) {
|
|
|
|
// Slide new workspaces in from offscreen
|
2008-12-22 16:51:34 -05:00
|
|
|
for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++)
|
|
|
|
this._workspaces[w].slideIn(oldScale);
|
2008-12-15 16:03:07 -05:00
|
|
|
} else {
|
|
|
|
// Slide old workspaces out
|
|
|
|
for (let w = 0; w < lostWorkspaces.length; w++) {
|
|
|
|
let workspace = lostWorkspaces[w];
|
2008-12-22 16:51:34 -05:00
|
|
|
workspace.slideOut(function () { workspace.destroy(); });
|
2008-12-15 16:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: deal with windows on the lost workspaces
|
|
|
|
}
|
2009-08-09 19:48:54 -04: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 17:06:47 -05:00
|
|
|
},
|
|
|
|
|
2009-01-21 16:12:49 -05:00
|
|
|
_activeWorkspaceChanged : function(wm, from, to, direction) {
|
|
|
|
this._workspaces[from].setSelected(false);
|
|
|
|
this._workspaces[to].setSelected(true);
|
|
|
|
},
|
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
_addWorkspaceActor : function(workspaceNum) {
|
2009-07-23 17:36:41 -04:00
|
|
|
let workspace = new Workspace(workspaceNum, this.actor);
|
2009-01-23 14:21:20 -05:00
|
|
|
this._workspaces[workspaceNum] = workspace;
|
|
|
|
this.actor.add_actor(workspace.actor);
|
|
|
|
},
|
|
|
|
|
2009-08-12 20:02:59 -04:00
|
|
|
_appendNewWorkspace : function() {
|
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
|
|
|
global.screen.append_new_workspace(false, global.screen.get_display().get_current_time());
|
|
|
|
},
|
|
|
|
|
|
|
|
// Creates a new workspace and drops the dropActor there
|
|
|
|
_addWorkspaceAcceptDrop : function(source, dropActor, x, y, time) {
|
|
|
|
this._appendNewWorkspace();
|
|
|
|
return this._workspaces[this._workspaces.length - 1].acceptDrop(source, dropActor, x, y, time);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function AddWorkspaceButton(buttonSize, buttonX, buttonY, acceptDropCallback) {
|
|
|
|
this._init(buttonSize, buttonX, buttonY, acceptDropCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddWorkspaceButton.prototype = {
|
|
|
|
_init : function(buttonSize, buttonX, buttonY, acceptDropCallback) {
|
|
|
|
this.actor = new Clutter.Texture({ x: buttonX,
|
|
|
|
y: buttonY,
|
|
|
|
width: buttonSize,
|
|
|
|
height: buttonSize,
|
|
|
|
reactive: true });
|
|
|
|
this._acceptDropCallback = acceptDropCallback;
|
2008-12-22 17:06:47 -05:00
|
|
|
let global = Shell.Global.get();
|
2009-08-12 20:02:59 -04:00
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.set_from_file(global.imagedir + 'add-workspace.svg');
|
|
|
|
},
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2009-08-12 20:02:59 -04:00
|
|
|
// Draggable target interface
|
|
|
|
acceptDrop : function(source, actor, x, y, time) {
|
|
|
|
return this._acceptDropCallback(source, actor, x, y, time);
|
2008-12-02 11:15:00 -05:00
|
|
|
}
|
|
|
|
};
|
2009-01-21 15:35:20 -05: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 18:33:13 -04:00
|
|
|
Tweener.registerSpecialPropertyModifier("workspace_relative", _workspaceRelativeModifier, _workspaceRelativeGet);
|
2009-01-21 15:35:20 -05:00
|
|
|
|
2009-05-02 18:33:13 -04:00
|
|
|
function _workspaceRelativeModifier(workspace) {
|
2009-08-11 07:46:10 -04:00
|
|
|
let [startX, startY] = Main.overview.getPosition();
|
|
|
|
let overviewPosX, overviewPosY, overviewScale;
|
2009-01-21 15:35:20 -05:00
|
|
|
|
2009-02-10 11:12:58 -05:00
|
|
|
if (!workspace)
|
|
|
|
return [];
|
|
|
|
|
2009-08-11 07:46:10 -04: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 17:58:33 -05:00
|
|
|
} else {
|
2009-08-11 07:46:10 -04:00
|
|
|
overviewPosX = { begin: startX, end: 0 };
|
|
|
|
overviewPosY = { begin: startY, end: 0 };
|
|
|
|
overviewScale = { begin: Main.overview.getScale(), end: 1 };
|
2009-01-21 15:35:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return [ { name: "x",
|
2009-08-10 18:31:39 -04:00
|
|
|
parameters: { workspacePos: workspace.gridX,
|
2009-08-11 07:46:10 -04:00
|
|
|
overviewPos: overviewPosX,
|
|
|
|
overviewScale: overviewScale } },
|
2009-01-21 15:35:20 -05:00
|
|
|
{ name: "y",
|
2009-08-10 18:31:39 -04:00
|
|
|
parameters: { workspacePos: workspace.gridY,
|
2009-08-11 07:46:10 -04:00
|
|
|
overviewPos: overviewPosY,
|
|
|
|
overviewScale: overviewScale } }
|
2009-01-21 15:35:20 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2009-05-02 18:33:13 -04:00
|
|
|
function _workspaceRelativeGet(begin, end, time, params) {
|
2009-08-11 07:46:10 -04: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 18:31:39 -04:00
|
|
|
|
|
|
|
// Calculate the screen position of the window.
|
|
|
|
let screen = (1 - time) *
|
2009-08-11 07:46:10 -04:00
|
|
|
((begin + params.workspacePos) * params.overviewScale.begin +
|
|
|
|
params.overviewPos.begin) +
|
2009-08-10 18:31:39 -04:00
|
|
|
time *
|
2009-08-11 07:46:10 -04:00
|
|
|
((end + params.workspacePos) * params.overviewScale.end +
|
|
|
|
params.overviewPos.end);
|
2009-08-10 18:31:39 -04:00
|
|
|
|
|
|
|
// Return the workspace coordinates.
|
2009-08-11 07:46:10 -04:00
|
|
|
return (screen - curOverviewPos) / curOverviewScale - params.workspacePos;
|
2009-02-03 17:58:33 -05:00
|
|
|
}
|