From 5a30ebe403c4e97d810c2a16ec148b4cf064ceb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 5 Jun 2019 05:08:31 +0200 Subject: [PATCH] window-list: Refactor workspace signal handlers We are about to support a separate representation if horizontal workspaces are used. To prepare for that, rename the handlers to something more generic and split out menu-specific bits into a dedicated helper function. https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/70 --- extensions/window-list/workspaceIndicator.js | 25 +++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/extensions/window-list/workspaceIndicator.js b/extensions/window-list/workspaceIndicator.js index 598c5165..78ca97e9 100644 --- a/extensions/window-list/workspaceIndicator.js +++ b/extensions/window-list/workspaceIndicator.js @@ -40,9 +40,9 @@ var WorkspaceIndicator = GObject.registerClass({ this._workspaceManagerSignals = [ workspaceManager.connect('notify::n-workspaces', - this._updateMenu.bind(this)), + this._nWorkspacesChanged.bind(this)), workspaceManager.connect_after('workspace-switched', - this._updateIndicator.bind(this)) + this._onWorkspaceSwitched.bind(this)) ]; this.connect('scroll-event', this._onScrollEvent.bind(this)); @@ -65,14 +65,27 @@ var WorkspaceIndicator = GObject.registerClass({ 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); + _onWorkspaceSwitched() { + let workspaceManager = global.workspace_manager; + this._currentWorkspace = workspaceManager.get_active_workspace_index(); + + this._updateMenuOrnament(); this._statusLabel.set_text(this._getStatusText()); } + _nWorkspacesChanged() { + this._updateMenu(); + } + + _updateMenuOrnament() { + for (let i = 0; i < this._workspacesItems.length; i++) { + this._workspacesItems[i].setOrnament(i == this._currentWorkspace + ? PopupMenu.Ornament.DOT + : PopupMenu.Ornament.NONE); + } + } + _getStatusText() { let workspaceManager = global.workspace_manager; let current = workspaceManager.get_active_workspace_index();