2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported WorkspaceSwitcherPopup */
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2022-01-26 00:26:44 +00:00
|
|
|
const { Clutter, GLib, GObject, St } = imports.gi;
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2022-01-26 00:33:21 +00:00
|
|
|
const Layout = imports.ui.layout;
|
2012-04-14 12:40:30 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2019-08-01 23:13:10 +00:00
|
|
|
var ANIMATION_TIME = 100;
|
2017-07-18 17:47:27 +00:00
|
|
|
var DISPLAY_TIMEOUT = 600;
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2022-01-26 00:33:21 +00:00
|
|
|
|
|
|
|
var WorkspaceSwitcherPopup = GObject.registerClass(
|
|
|
|
class WorkspaceSwitcherPopup extends Clutter.Actor {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init() {
|
2020-07-08 10:06:39 +00:00
|
|
|
super._init({
|
|
|
|
offscreen_redirect: Clutter.OffscreenRedirect.ALWAYS,
|
2022-01-26 00:33:21 +00:00
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.END,
|
2020-07-08 10:06:39 +00:00
|
|
|
});
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2022-01-26 00:33:21 +00:00
|
|
|
const constraint = new Layout.MonitorConstraint({ primary: true });
|
|
|
|
this.add_constraint(constraint);
|
2018-07-15 21:00:07 +00:00
|
|
|
|
|
|
|
Main.uiGroup.add_actor(this);
|
|
|
|
|
|
|
|
this._timeoutId = 0;
|
|
|
|
|
2022-01-26 00:33:21 +00:00
|
|
|
this._list = new St.BoxLayout({
|
|
|
|
style_class: 'workspace-switcher',
|
|
|
|
});
|
|
|
|
this.add_child(this._list);
|
2018-07-15 21:00:07 +00:00
|
|
|
|
|
|
|
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++) {
|
2022-01-26 00:26:44 +00:00
|
|
|
const indicator = new St.Bin({
|
|
|
|
style_class: 'ws-switcher-indicator',
|
|
|
|
});
|
|
|
|
|
|
|
|
if (i === this._activeWorkspaceIndex)
|
|
|
|
indicator.add_style_pseudo_class('active');
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2019-01-29 19:36:54 +00:00
|
|
|
this._list.add_actor(indicator);
|
2010-02-12 22:52:15 +00:00
|
|
|
}
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2010-02-12 22:52:15 +00:00
|
|
|
|
2022-01-26 00:26:44 +00:00
|
|
|
display(activeWorkspaceIndex) {
|
2012-06-27 19:13:32 +00:00
|
|
|
this._activeWorkspaceIndex = activeWorkspaceIndex;
|
|
|
|
|
|
|
|
this._redisplay();
|
2010-02-12 22:52:15 +00:00
|
|
|
if (this._timeoutId != 0)
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 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');
|
2022-01-26 00:43:15 +00:00
|
|
|
|
|
|
|
const duration = this.visible ? 0 : ANIMATION_TIME;
|
|
|
|
this.show();
|
2022-01-26 00:33:21 +00:00
|
|
|
this.opacity = 0;
|
|
|
|
this.ease({
|
2022-01-26 00:43:15 +00:00
|
|
|
opacity: 255,
|
|
|
|
duration,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
});
|
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() {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._timeoutId);
|
2010-02-12 22:52:15 +00:00
|
|
|
this._timeoutId = 0;
|
2022-01-26 00:33:21 +00:00
|
|
|
this.ease({
|
2018-07-20 19:46:19 +00:00
|
|
|
opacity: 0.0,
|
|
|
|
duration: ANIMATION_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-20 21:43:54 +00:00
|
|
|
onComplete: () => this.destroy(),
|
2018-07-20 19:46:19 +00:00
|
|
|
});
|
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)
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._timeoutId);
|
2012-06-27 19:13:32 +00:00
|
|
|
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
|
|
|
});
|