From 55e8dea70a376cc7fb294bbc84a534ac4db5612f Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Sat, 18 Apr 2020 17:34:45 -0400 Subject: [PATCH] Reuse system menus instead of recreating them --- extension.js | 3 +++ panel.js | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/extension.js b/extension.js index a948b67..a1f6d39 100644 --- a/extension.js +++ b/extension.js @@ -45,6 +45,9 @@ let extensionSystem = (Main.extensionManager || imports.ui.extensionSystem); function init() { Convenience.initTranslations(Utils.TRANSLATION_DOMAIN); + + //create an object that persists until gnome-shell is restarted, even if the extension is disabled + Me.persistentStorage = {}; } function enable() { diff --git a/panel.js b/panel.js index e103a3a..0cdc2fe 100644 --- a/panel.js +++ b/panel.js @@ -574,7 +574,7 @@ var dtpPanel = Utils.defineClass({ if (!Me.settings.get_boolean(settingName)) { this._removePanelMenu(propName); } else if (!this.statusArea[propName]) { - this.statusArea[propName] = new constr(); + this.statusArea[propName] = this._getPanelMenu(propName, constr); this.menuManager.addMenu(this.statusArea[propName].menu); container.insert_child_at_index(this.statusArea[propName].container, 0); } @@ -588,12 +588,29 @@ var dtpPanel = Utils.defineClass({ parent.remove_actor(this.statusArea[propName].container); } - //this.statusArea[propName].destroy(); //buggy for now, gnome-shell never destroys those menus - this.menuManager.removeMenu(this.statusArea[propName].menu); + //calling this.statusArea[propName].destroy(); is buggy for now, gnome-shell never + //destroys those panel menus... + //since we can't destroy the menu (hence properly disconnect its signals), let's + //store it so the next time a panel needs one of its kind, we can reuse it instead + //of creating a new one + let panelMenu = this.statusArea[propName]; + + this.menuManager.removeMenu(panelMenu.menu); + Me.persistentStorage[propName].push(panelMenu); this.statusArea[propName] = null; } }, + _getPanelMenu: function(propName, constr) { + Me.persistentStorage[propName] = Me.persistentStorage[propName] || []; + + if (!Me.persistentStorage[propName].length) { + Me.persistentStorage[propName].push(new constr()); + } + + return Me.persistentStorage[propName].pop(); + }, + _setPanelGhostSize: function() { this._myPanelGhost.set_size(this.width, checkIfVertical() ? 1 : this.height); }, @@ -1187,6 +1204,8 @@ var dtpSecondaryAggregateMenu = Utils.defineClass({ _init: function() { this.callParent('_init', 0.0, C_("System menu in the top bar", "System"), false); + Utils.wrapActor(this); + this.menu.actor.add_style_class_name('aggregate-menu'); let menuLayout = new Panel.AggregateLayout();