2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2013-11-28 19:45:39 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
2010-02-12 17:52:15 -05:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
2012-04-14 08:40:30 -04:00
|
|
|
const Meta = imports.gi.Meta;
|
2010-02-12 17:52:15 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2012-06-27 15:13:32 -04:00
|
|
|
const Signals = imports.signals;
|
2010-02-12 17:52:15 -05:00
|
|
|
const St = imports.gi.St;
|
|
|
|
|
2012-04-14 08:40:30 -04:00
|
|
|
const Main = imports.ui.main;
|
2010-02-12 17:52:15 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var ANIMATION_TIME = 0.1;
|
|
|
|
var DISPLAY_TIMEOUT = 600;
|
2010-02-12 17:52:15 -05:00
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var WorkspaceSwitcherPopup = new Lang.Class({
|
2011-11-20 12:56:27 -05:00
|
|
|
Name: 'WorkspaceSwitcherPopup',
|
2010-02-12 17:52:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2016-08-25 09:46:15 -04:00
|
|
|
this.actor = new St.Widget({ x: 0,
|
2012-02-14 11:33:26 -05:00
|
|
|
y: 0,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_height,
|
|
|
|
style_class: 'workspace-switcher-group' });
|
2010-05-06 17:18:10 -04:00
|
|
|
Main.uiGroup.add_actor(this.actor);
|
2010-02-12 17:52:15 -05:00
|
|
|
|
2010-05-13 15:46:04 -04:00
|
|
|
this._container = new St.BoxLayout({ style_class: 'workspace-switcher-container' });
|
2010-06-09 13:09:48 -04:00
|
|
|
this._list = new Shell.GenericContainer({ style_class: 'workspace-switcher' });
|
|
|
|
this._itemSpacing = 0;
|
2011-02-09 10:00:29 -05:00
|
|
|
this._childHeight = 0;
|
|
|
|
this._childWidth = 0;
|
2017-09-17 04:37:17 -04:00
|
|
|
this._timeoutId = 0;
|
2017-10-30 20:38:18 -04:00
|
|
|
this._list.connect('style-changed', () => {
|
|
|
|
this._itemSpacing = this._list.get_theme_node().get_length('spacing');
|
|
|
|
});
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._list.connect('get-preferred-width', this._getPreferredWidth.bind(this));
|
|
|
|
this._list.connect('get-preferred-height', this._getPreferredHeight.bind(this));
|
|
|
|
this._list.connect('allocate', this._allocate.bind(this));
|
2010-02-12 17:52:15 -05:00
|
|
|
this._container.add(this._list);
|
2010-02-16 16:34:57 -05:00
|
|
|
|
2010-02-12 17:52:15 -05:00
|
|
|
this.actor.add_actor(this._container);
|
|
|
|
|
2012-06-27 15:13:32 -04:00
|
|
|
this._redisplay();
|
2010-02-12 17:52:15 -05:00
|
|
|
|
2011-02-09 17:57:23 -05:00
|
|
|
this.actor.hide();
|
|
|
|
|
2012-06-27 15:13:32 -04:00
|
|
|
this._globalSignals = [];
|
2017-12-01 19:27:35 -05:00
|
|
|
this._globalSignals.push(global.screen.connect('workspace-added', this._redisplay.bind(this)));
|
|
|
|
this._globalSignals.push(global.screen.connect('workspace-removed', this._redisplay.bind(this)));
|
2010-02-12 17:52:15 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getPreferredHeight(actor, forWidth, alloc) {
|
2010-06-09 13:09:48 -04:00
|
|
|
let children = this._list.get_children();
|
2013-01-28 00:09:12 -05:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2013-01-28 00:09:12 -05:00
|
|
|
let availHeight = workArea.height;
|
2011-02-09 10:00:29 -05:00
|
|
|
availHeight -= this.actor.get_theme_node().get_vertical_padding();
|
|
|
|
availHeight -= this._container.get_theme_node().get_vertical_padding();
|
|
|
|
availHeight -= this._list.get_theme_node().get_vertical_padding();
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
let height = 0;
|
2010-06-09 13:09:48 -04:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
2011-02-09 10:00:29 -05:00
|
|
|
let [childMinHeight, childNaturalHeight] = children[i].get_preferred_height(-1);
|
|
|
|
let [childMinWidth, childNaturalWidth] = children[i].get_preferred_width(childNaturalHeight);
|
2013-01-28 00:09:12 -05:00
|
|
|
height += childNaturalHeight * workArea.width / workArea.height;
|
2010-06-09 13:09:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let spacing = this._itemSpacing * (global.screen.n_workspaces - 1);
|
2011-02-09 10:00:29 -05:00
|
|
|
height += spacing;
|
|
|
|
height = Math.min(height, availHeight);
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
this._childHeight = (height - spacing) / global.screen.n_workspaces;
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
alloc.min_size = height;
|
|
|
|
alloc.natural_size = height;
|
2010-06-09 13:09:48 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getPreferredWidth(actor, forHeight, alloc) {
|
2013-01-28 00:09:12 -05:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
|
|
|
this._childWidth = Math.round(this._childHeight * workArea.width / workArea.height);
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
alloc.min_size = this._childWidth;
|
|
|
|
alloc.natural_size = this._childWidth;
|
2010-06-09 13:09:48 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_allocate(actor, box, flags) {
|
2010-06-09 13:09:48 -04:00
|
|
|
let children = this._list.get_children();
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
let y = box.y1;
|
|
|
|
let prevChildBoxY2 = box.y1 - this._itemSpacing;
|
2010-06-09 13:09:48 -04:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
2011-02-09 10:00:29 -05:00
|
|
|
childBox.x1 = box.x1;
|
|
|
|
childBox.x2 = box.x1 + this._childWidth;
|
|
|
|
childBox.y1 = prevChildBoxY2 + this._itemSpacing;
|
|
|
|
childBox.y2 = Math.round(y + this._childHeight);
|
|
|
|
y += this._childHeight + this._itemSpacing;
|
|
|
|
prevChildBoxY2 = childBox.y2;
|
2010-06-09 13:09:48 -04:00
|
|
|
children[i].allocate(childBox, flags);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_redisplay() {
|
2012-02-16 13:27:09 -05:00
|
|
|
this._list.destroy_all_children();
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < global.screen.n_workspaces; i++) {
|
|
|
|
let indicator = null;
|
|
|
|
|
2012-06-27 15:13:32 -04:00
|
|
|
if (i == this._activeWorkspaceIndex && this._direction == Meta.MotionDirection.UP)
|
2011-02-09 10:00:29 -05:00
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-active-up' });
|
2012-06-27 15:13:32 -04:00
|
|
|
else if(i == this._activeWorkspaceIndex && this._direction == Meta.MotionDirection.DOWN)
|
2011-02-09 10:00:29 -05:00
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-active-down' });
|
2010-02-12 17:52:15 -05:00
|
|
|
else
|
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-box' });
|
|
|
|
|
2010-06-09 13:09:48 -04:00
|
|
|
this._list.add_actor(indicator);
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-28 00:09:12 -05:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
2012-06-27 15:13:32 -04:00
|
|
|
let [containerMinHeight, containerNatHeight] = this._container.get_preferred_height(global.screen_width);
|
|
|
|
let [containerMinWidth, containerNatWidth] = this._container.get_preferred_width(containerNatHeight);
|
2013-01-28 00:09:12 -05:00
|
|
|
this._container.x = workArea.x + Math.floor((workArea.width - containerNatWidth) / 2);
|
|
|
|
this._container.y = workArea.y + Math.floor((workArea.height - containerNatHeight) / 2);
|
2010-02-12 17:52:15 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_show() {
|
2010-02-12 17:52:15 -05:00
|
|
|
Tweener.addTween(this._container, { opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad'
|
2010-02-12 17:52:15 -05:00
|
|
|
});
|
|
|
|
this.actor.show();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
display(direction, activeWorkspaceIndex) {
|
2012-06-27 15:13:32 -04:00
|
|
|
this._direction = direction;
|
|
|
|
this._activeWorkspaceIndex = activeWorkspaceIndex;
|
|
|
|
|
|
|
|
this._redisplay();
|
2010-02-12 17:52:15 -05:00
|
|
|
if (this._timeoutId != 0)
|
|
|
|
Mainloop.source_remove(this._timeoutId);
|
2017-12-01 19:27:35 -05:00
|
|
|
this._timeoutId = Mainloop.timeout_add(DISPLAY_TIMEOUT, this._onTimeout.bind(this));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._timeoutId, '[gnome-shell] this._onTimeout');
|
2010-02-12 17:52:15 -05:00
|
|
|
this._show();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onTimeout() {
|
2010-02-12 17:52:15 -05:00
|
|
|
Mainloop.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = 0;
|
|
|
|
Tweener.addTween(this._container, { opacity: 0.0,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad',
|
2017-10-30 20:03:21 -04:00
|
|
|
onComplete() { this.destroy(); },
|
2010-02-12 17:52:15 -05:00
|
|
|
onCompleteScope: this
|
|
|
|
});
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2012-06-27 15:13:32 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2012-06-27 15:13:32 -04:00
|
|
|
if (this._timeoutId)
|
|
|
|
Mainloop.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._globalSignals.length; i++)
|
|
|
|
global.screen.disconnect(this._globalSignals[i]);
|
|
|
|
|
|
|
|
this.actor.destroy();
|
|
|
|
|
|
|
|
this.emit('destroy');
|
2010-02-12 17:52:15 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2012-06-27 15:13:32 -04:00
|
|
|
Signals.addSignalMethods(WorkspaceSwitcherPopup.prototype);
|