[gnome-shell-extensions/wip/rstrode/heads-up-display: 32/62] window-list: Refactor workspace signal handlers




commit 35e120e54689d6373be70ca342de3aa8cbc23523
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Jun 5 05:08:31 2019 +0200

    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 help 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 ace4e25..80b355a 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();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]