[gnome-shell-extensions/wip/rstrode/heads-up-display: 26/62] window-list: Split out workspaceIndicator
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/rstrode/heads-up-display: 26/62] window-list: Split out workspaceIndicator
- Date: Thu, 26 Aug 2021 19:31:31 +0000 (UTC)
commit 890a07fbae528f10772f2b83d3c8d49f2bad51e2
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Jun 5 00:23:13 2019 +0000
window-list: Split out workspaceIndicator
The extension has grown unwieldily big, so before starting to improve
on the workspace indicator, move it to its own source file.
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/70
extensions/window-list/extension.js | 130 +-------------------------
extensions/window-list/meson.build | 2 +-
extensions/window-list/workspaceIndicator.js | 134 +++++++++++++++++++++++++++
3 files changed, 137 insertions(+), 129 deletions(-)
---
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
index b2784b4..1f854aa 100644
--- a/extensions/window-list/extension.js
+++ b/extensions/window-list/extension.js
@@ -1,16 +1,16 @@
/* exported init */
-const { Clutter, Gio, GLib, GObject, Gtk, Meta, Shell, St } = imports.gi;
+const { Clutter, Gio, GLib, Gtk, Meta, Shell, St } = imports.gi;
const DND = imports.ui.dnd;
const Main = imports.ui.main;
const Overview = imports.ui.overview;
-const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Tweener = imports.ui.tweener;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { WindowPicker, WindowPickerToggle } = Me.imports.windowPicker;
+const { WorkspaceIndicator } = Me.imports.workspaceIndicator;
const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;
@@ -647,132 +647,6 @@ class AppButton extends BaseButton {
}
-let WorkspaceIndicator = GObject.registerClass(
-class WorkspaceIndicator extends PanelMenu.Button {
- _init() {
- super._init(0.0, _('Workspace Indicator'), true);
- this.setMenu(new PopupMenu.PopupMenu(this, 0.0, St.Side.BOTTOM));
- this.add_style_class_name('window-list-workspace-indicator');
- this.menu.actor.remove_style_class_name('panel-menu');
-
- let container = new St.Widget({
- layout_manager: new Clutter.BinLayout(),
- x_expand: true,
- y_expand: true
- });
- this.add_actor(container);
-
- let workspaceManager = global.workspace_manager;
-
- this._currentWorkspace = workspaceManager.get_active_workspace().index();
- this.statusLabel = new St.Label({
- text: this._getStatusText(),
- x_align: Clutter.ActorAlign.CENTER,
- y_align: Clutter.ActorAlign.CENTER
- });
- container.add_actor(this.statusLabel);
-
- this.workspacesItems = [];
-
- this._workspaceManagerSignals = [];
- this._workspaceManagerSignals.push(workspaceManager.connect('notify::n-workspaces',
- this._updateMenu.bind(this)));
- this._workspaceManagerSignals.push(workspaceManager.connect_after('workspace-switched',
- this._updateIndicator.bind(this)));
-
- this.connect('scroll-event', this._onScrollEvent.bind(this));
- this._updateMenu();
-
- this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.wm.preferences' });
- this._settingsChangedId =
- this._settings.connect('changed::workspace-names',
- this._updateMenu.bind(this));
- }
-
- _onDestroy() {
- for (let i = 0; i < this._workspaceManagerSignals.length; i++)
- global.workspace_manager.disconnect(this._workspaceManagerSignals[i]);
-
- if (this._settingsChangedId) {
- this._settings.disconnect(this._settingsChangedId);
- this._settingsChangedId = 0;
- }
-
- super._onDestroy();
- }
-
- _updateIndicator() {
- this.workspacesItems[this._currentWorkspace].setOrnament(PopupMenu.Ornament.NONE);
- this._currentWorkspace = global.workspace_manager.get_active_workspace().index();
- this.workspacesItems[this._currentWorkspace].setOrnament(PopupMenu.Ornament.DOT);
-
- this.statusLabel.set_text(this._getStatusText());
- }
-
- _getStatusText() {
- let workspaceManager = global.workspace_manager;
- let current = workspaceManager.get_active_workspace().index();
- let total = workspaceManager.n_workspaces;
-
- return '%d / %d'.format(current + 1, total);
- }
-
- _updateMenu() {
- let workspaceManager = global.workspace_manager;
-
- this.menu.removeAll();
- this.workspacesItems = [];
- this._currentWorkspace = workspaceManager.get_active_workspace().index();
-
- for (let i = 0; i < workspaceManager.n_workspaces; i++) {
- let name = Meta.prefs_get_workspace_name(i);
- let item = new PopupMenu.PopupMenuItem(name);
- item.workspaceId = i;
-
- item.connect('activate', (item, _event) => {
- this._activate(item.workspaceId);
- });
-
- if (i == this._currentWorkspace)
- item.setOrnament(PopupMenu.Ornament.DOT);
-
- this.menu.addMenuItem(item);
- this.workspacesItems[i] = item;
- }
-
- this.statusLabel.set_text(this._getStatusText());
- }
-
- _activate(index) {
- let workspaceManager = global.workspace_manager;
-
- if (index >= 0 && index < workspaceManager.n_workspaces) {
- let metaWorkspace = workspaceManager.get_workspace_by_index(index);
- metaWorkspace.activate(global.get_current_time());
- }
- }
-
- _onScrollEvent(actor, event) {
- let direction = event.get_scroll_direction();
- let diff = 0;
- if (direction == Clutter.ScrollDirection.DOWN) {
- diff = 1;
- } else if (direction == Clutter.ScrollDirection.UP) {
- diff = -1;
- } else {
- return;
- }
-
- let newIndex = this._currentWorkspace + diff;
- this._activate(newIndex);
- }
-
- _allocate(actor, box, flags) {
- if (actor.get_n_children() > 0)
- actor.get_first_child().allocate(box, flags);
- }
-});
-
class WindowList {
constructor(perMonitor, monitor) {
this._perMonitor = perMonitor;
diff --git a/extensions/window-list/meson.build b/extensions/window-list/meson.build
index 5b1f5f5..34d7c3f 100644
--- a/extensions/window-list/meson.build
+++ b/extensions/window-list/meson.build
@@ -4,7 +4,7 @@ extension_data += configure_file(
configuration: metadata_conf
)
-extension_sources += files('prefs.js', 'windowPicker.js')
+extension_sources += files('prefs.js', 'windowPicker.js', 'workspaceIndicator.js')
extension_schemas += files(metadata_conf.get('gschemaname') + '.gschema.xml')
if classic_mode_enabled
diff --git a/extensions/window-list/workspaceIndicator.js b/extensions/window-list/workspaceIndicator.js
new file mode 100644
index 0000000..ed3a3de
--- /dev/null
+++ b/extensions/window-list/workspaceIndicator.js
@@ -0,0 +1,134 @@
+/* exported WorkspaceIndicator */
+const { Clutter, Gio, GObject, Meta, St } = imports.gi;
+
+const PanelMenu = imports.ui.panelMenu;
+const PopupMenu = imports.ui.popupMenu;
+
+const Gettext = imports.gettext.domain('gnome-shell-extensions');
+const _ = Gettext.gettext;
+
+var WorkspaceIndicator = GObject.registerClass(
+class WorkspaceIndicator extends PanelMenu.Button {
+ _init() {
+ super._init(0.0, _('Workspace Indicator'), true);
+ this.setMenu(new PopupMenu.PopupMenu(this, 0.0, St.Side.BOTTOM));
+ this.add_style_class_name('window-list-workspace-indicator');
+ this.menu.actor.remove_style_class_name('panel-menu');
+
+ let container = new St.Widget({
+ layout_manager: new Clutter.BinLayout(),
+ x_expand: true,
+ y_expand: true
+ });
+ this.add_actor(container);
+
+ let workspaceManager = global.workspace_manager;
+
+ this._currentWorkspace = workspaceManager.get_active_workspace().index();
+ this.statusLabel = new St.Label({
+ text: this._getStatusText(),
+ x_align: Clutter.ActorAlign.CENTER,
+ y_align: Clutter.ActorAlign.CENTER
+ });
+ container.add_actor(this.statusLabel);
+
+ this.workspacesItems = [];
+
+ this._workspaceManagerSignals = [
+ workspaceManager.connect('notify::n-workspaces',
+ this._updateMenu.bind(this)),
+ workspaceManager.connect_after('workspace-switched',
+ this._updateIndicator.bind(this))
+ ];
+
+ this.connect('scroll-event', this._onScrollEvent.bind(this));
+ this._updateMenu();
+
+ this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.wm.preferences' });
+ this._settingsChangedId = this._settings.connect(
+ 'changed::workspace-names', this._updateMenu.bind(this));
+ }
+
+ _onDestroy() {
+ for (let i = 0; i < this._workspaceManagerSignals.length; i++)
+ global.workspace_manager.disconnect(this._workspaceManagerSignals[i]);
+
+ if (this._settingsChangedId) {
+ this._settings.disconnect(this._settingsChangedId);
+ this._settingsChangedId = 0;
+ }
+
+ super._onDestroy();
+ }
+
+ _updateIndicator() {
+ this.workspacesItems[this._currentWorkspace].setOrnament(PopupMenu.Ornament.NONE);
+ this._currentWorkspace = global.workspace_manager.get_active_workspace().index();
+ this.workspacesItems[this._currentWorkspace].setOrnament(PopupMenu.Ornament.DOT);
+
+ this.statusLabel.set_text(this._getStatusText());
+ }
+
+ _getStatusText() {
+ let workspaceManager = global.workspace_manager;
+ let current = workspaceManager.get_active_workspace().index();
+ let total = workspaceManager.n_workspaces;
+
+ return '%d / %d'.format(current + 1, total);
+ }
+
+ _updateMenu() {
+ let workspaceManager = global.workspace_manager;
+
+ this.menu.removeAll();
+ this.workspacesItems = [];
+ this._currentWorkspace = workspaceManager.get_active_workspace().index();
+
+ for (let i = 0; i < workspaceManager.n_workspaces; i++) {
+ let name = Meta.prefs_get_workspace_name(i);
+ let item = new PopupMenu.PopupMenuItem(name);
+ item.workspaceId = i;
+
+ item.connect('activate', (item, _event) => {
+ this._activate(item.workspaceId);
+ });
+
+ if (i == this._currentWorkspace)
+ item.setOrnament(PopupMenu.Ornament.DOT);
+
+ this.menu.addMenuItem(item);
+ this.workspacesItems[i] = item;
+ }
+
+ this.statusLabel.set_text(this._getStatusText());
+ }
+
+ _activate(index) {
+ let workspaceManager = global.workspace_manager;
+
+ if (index >= 0 && index < workspaceManager.n_workspaces) {
+ let metaWorkspace = workspaceManager.get_workspace_by_index(index);
+ metaWorkspace.activate(global.get_current_time());
+ }
+ }
+
+ _onScrollEvent(actor, event) {
+ let direction = event.get_scroll_direction();
+ let diff = 0;
+ if (direction == Clutter.ScrollDirection.DOWN) {
+ diff = 1;
+ } else if (direction == Clutter.ScrollDirection.UP) {
+ diff = -1;
+ } else {
+ return;
+ }
+
+ let newIndex = this._currentWorkspace + diff;
+ this._activate(newIndex);
+ }
+
+ _allocate(actor, box, flags) {
+ if (actor.get_n_children() > 0)
+ actor.get_first_child().allocate(box, flags);
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]