2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Clutter, GLib, GObject, Meta, St } = imports.gi;
|
2010-02-12 22:52:15 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
|
2012-04-14 12:40:30 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-02-12 22:52:15 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var ANIMATION_TIME = 0.1;
|
|
|
|
var DISPLAY_TIMEOUT = 600;
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var WorkspaceSwitcherPopupList = GObject.registerClass(
|
|
|
|
class WorkspaceSwitcherPopupList extends St.Widget {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init() {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init({ style_class: 'workspace-switcher' });
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2010-06-09 17:09:48 +00:00
|
|
|
this._itemSpacing = 0;
|
2011-02-09 15:00:29 +00:00
|
|
|
this._childHeight = 0;
|
|
|
|
this._childWidth = 0;
|
2010-02-16 21:34:57 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
this.connect('style-changed', () => {
|
|
|
|
this._itemSpacing = this.get_theme_node().get_length('spacing');
|
|
|
|
});
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
vfunc_get_preferred_height(forWidth) {
|
2013-01-28 05:09:12 +00:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
2018-07-15 21:00:07 +00:00
|
|
|
let themeNode = this.get_theme_node();
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2013-01-28 05:09:12 +00:00
|
|
|
let availHeight = workArea.height;
|
2018-07-15 21:00:07 +00:00
|
|
|
availHeight -= themeNode.get_vertical_padding();
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2011-02-09 15:00:29 +00:00
|
|
|
let height = 0;
|
2018-07-15 21:00:07 +00:00
|
|
|
for (let child of this.get_children()) {
|
|
|
|
let [childMinHeight, childNaturalHeight] = child.get_preferred_height(-1);
|
|
|
|
let [childMinWidth, childNaturalWidth] = child.get_preferred_width(childNaturalHeight);
|
2013-01-28 05:09:12 +00:00
|
|
|
height += childNaturalHeight * workArea.width / workArea.height;
|
2010-06-09 17:09:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let spacing = this._itemSpacing * (workspaceManager.n_workspaces - 1);
|
2011-02-09 15:00:29 +00:00
|
|
|
height += spacing;
|
|
|
|
height = Math.min(height, availHeight);
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
this._childHeight = (height - spacing) / workspaceManager.n_workspaces;
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
return themeNode.adjust_preferred_height(height, height);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
vfunc_get_preferred_width(forHeight) {
|
2013-01-28 05:09:12 +00:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
|
|
|
this._childWidth = Math.round(this._childHeight * workArea.width / workArea.height);
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
return [this._childWidth, this._childWidth];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
vfunc_allocate(box, flags) {
|
|
|
|
this.set_allocation(box, flags);
|
|
|
|
|
|
|
|
let themeNode = this.get_theme_node();
|
|
|
|
box = themeNode.get_content_box(box);
|
|
|
|
|
2010-06-09 17:09:48 +00:00
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
2011-02-09 15:00:29 +00:00
|
|
|
let y = box.y1;
|
|
|
|
let prevChildBoxY2 = box.y1 - this._itemSpacing;
|
2018-07-15 21:00:07 +00:00
|
|
|
for (let child of this.get_children()) {
|
2011-02-09 15:00:29 +00: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;
|
2018-07-15 21:00:07 +00:00
|
|
|
child.allocate(childBox, flags);
|
2010-06-09 17:09:48 +00:00
|
|
|
}
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2018-07-15 21:00:07 +00:00
|
|
|
});
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var WorkspaceSwitcherPopup = GObject.registerClass(
|
|
|
|
class WorkspaceSwitcherPopup extends St.Widget {
|
2018-07-15 21:00:07 +00:00
|
|
|
_init() {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init({ x: 0,
|
2018-07-15 21:00:07 +00:00
|
|
|
y: 0,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_height,
|
|
|
|
style_class: 'workspace-switcher-group' });
|
|
|
|
|
|
|
|
Main.uiGroup.add_actor(this);
|
|
|
|
|
|
|
|
this._timeoutId = 0;
|
|
|
|
|
|
|
|
this._container = new St.BoxLayout({ style_class: 'workspace-switcher-container' });
|
|
|
|
this.add_child(this._container);
|
|
|
|
|
|
|
|
this._list = new WorkspaceSwitcherPopupList();
|
|
|
|
this._container.add_child(this._list);
|
|
|
|
|
|
|
|
this._redisplay();
|
|
|
|
|
|
|
|
this.hide();
|
|
|
|
|
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
this._workspaceManagerSignals = [];
|
|
|
|
this._workspaceManagerSignals.push(workspaceManager.connect('workspace-added',
|
|
|
|
this._redisplay.bind(this)));
|
|
|
|
this._workspaceManagerSignals.push(workspaceManager.connect('workspace-removed',
|
|
|
|
this._redisplay.bind(this)));
|
|
|
|
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-06-09 17:09:48 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_redisplay() {
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
|
2012-02-16 18:27:09 +00:00
|
|
|
this._list.destroy_all_children();
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
for (let i = 0; i < workspaceManager.n_workspaces; i++) {
|
2010-02-12 22:52:15 +00:00
|
|
|
let indicator = null;
|
|
|
|
|
2012-06-27 19:13:32 +00:00
|
|
|
if (i == this._activeWorkspaceIndex && this._direction == Meta.MotionDirection.UP)
|
2011-02-09 15:00:29 +00:00
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-active-up' });
|
2019-01-29 01:27:05 +00:00
|
|
|
else if (i == this._activeWorkspaceIndex && this._direction == Meta.MotionDirection.DOWN)
|
2011-02-09 15:00:29 +00:00
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-active-down' });
|
2010-02-12 22:52:15 +00:00
|
|
|
else
|
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-box' });
|
|
|
|
|
2010-06-09 17:09:48 +00:00
|
|
|
this._list.add_actor(indicator);
|
2010-02-12 22:52:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-28 05:09:12 +00:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
2012-06-27 19:13:32 +00:00
|
|
|
let [containerMinHeight, containerNatHeight] = this._container.get_preferred_height(global.screen_width);
|
|
|
|
let [containerMinWidth, containerNatWidth] = this._container.get_preferred_width(containerNatHeight);
|
2013-01-28 05:09:12 +00:00
|
|
|
this._container.x = workArea.x + Math.floor((workArea.width - containerNatWidth) / 2);
|
|
|
|
this._container.y = workArea.y + Math.floor((workArea.height - containerNatHeight) / 2);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_show() {
|
2010-02-12 22:52:15 +00:00
|
|
|
Tweener.addTween(this._container, { opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 19:46:04 +00:00
|
|
|
transition: 'easeOutQuad'
|
2010-02-12 22:52:15 +00:00
|
|
|
});
|
2019-04-09 23:26:19 +00:00
|
|
|
this.show();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
display(direction, activeWorkspaceIndex) {
|
2012-06-27 19:13:32 +00:00
|
|
|
this._direction = direction;
|
|
|
|
this._activeWorkspaceIndex = activeWorkspaceIndex;
|
|
|
|
|
|
|
|
this._redisplay();
|
2010-02-12 22:52:15 +00:00
|
|
|
if (this._timeoutId != 0)
|
|
|
|
Mainloop.source_remove(this._timeoutId);
|
2017-12-02 00:27:35 +00:00
|
|
|
this._timeoutId = Mainloop.timeout_add(DISPLAY_TIMEOUT, this._onTimeout.bind(this));
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(this._timeoutId, '[gnome-shell] this._onTimeout');
|
2010-02-12 22:52:15 +00:00
|
|
|
this._show();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onTimeout() {
|
2010-02-12 22:52:15 +00:00
|
|
|
Mainloop.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = 0;
|
|
|
|
Tweener.addTween(this._container, { opacity: 0.0,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 19:46:04 +00:00
|
|
|
transition: 'easeOutQuad',
|
2017-10-31 00:03:21 +00:00
|
|
|
onComplete() { this.destroy(); },
|
2010-02-12 22:52:15 +00:00
|
|
|
onCompleteScope: this
|
|
|
|
});
|
2013-11-29 00:45:39 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-06-27 19:13:32 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
_onDestroy() {
|
2012-06-27 19:13:32 +00:00
|
|
|
if (this._timeoutId)
|
|
|
|
Mainloop.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = 0;
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
for (let i = 0; i < this._workspaceManagerSignals.length; i++)
|
|
|
|
workspaceManager.disconnect(this._workspaceManagerSignals[i]);
|
2012-06-27 19:13:32 +00:00
|
|
|
|
2018-07-15 21:00:07 +00:00
|
|
|
this._workspaceManagerSignals = [];
|
2010-02-12 22:52:15 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|