From a6c49e3599d76e352c8924d23c7d9f0bb77d5180 Mon Sep 17 00:00:00 2001 From: lost-melody Date: Thu, 12 Sep 2024 14:07:32 +0800 Subject: [PATCH 1/3] update and open menu if there's no entries --- indicatorStatusIcon.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/indicatorStatusIcon.js b/indicatorStatusIcon.js index 49ecde81..8e7c6813 100644 --- a/indicatorStatusIcon.js +++ b/indicatorStatusIcon.js @@ -403,18 +403,31 @@ class IndicatorStatusIcon extends BaseStatusIcon { } if (event.get_button() === Clutter.BUTTON_SECONDARY) { - this.menu.toggle(); + if (this.menu.numMenuItems) { + this.menu.toggle(); + } else { + // update menu if there's no entries + this._updateMenu(); + // wait for menu update + this._waitForDoubleClick().catch(logError); + } return Clutter.EVENT_PROPAGATE; } const doubleClickHandled = this._maybeHandleDoubleClick(event); if (doubleClickHandled === Clutter.EVENT_PROPAGATE && - event.get_button() === Clutter.BUTTON_PRIMARY && - this.menu.numMenuItems) { - if (this._indicator.supportsActivation !== false) + event.get_button() === Clutter.BUTTON_PRIMARY) { + if (this.menu.numMenuItems) { + if (this._indicator.supportsActivation !== false) + this._waitForDoubleClick().catch(logError); + else + this.menu.toggle(); + } else { + // update menu if there's no entries + this._updateMenu(); + // wait for double click or menu update this._waitForDoubleClick().catch(logError); - else - this.menu.toggle(); + } } return Clutter.EVENT_PROPAGATE; From fb1b31219e38c52587811ec6bc670b1db9a7bf11 Mon Sep 17 00:00:00 2001 From: lost-melody Date: Thu, 8 May 2025 18:58:03 +0800 Subject: [PATCH 2/3] Revert "update and open menu if there's no entries" This reverts commit a6c49e3599d76e352c8924d23c7d9f0bb77d5180. --- indicatorStatusIcon.js | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/indicatorStatusIcon.js b/indicatorStatusIcon.js index 8e7c6813..49ecde81 100644 --- a/indicatorStatusIcon.js +++ b/indicatorStatusIcon.js @@ -403,31 +403,18 @@ class IndicatorStatusIcon extends BaseStatusIcon { } if (event.get_button() === Clutter.BUTTON_SECONDARY) { - if (this.menu.numMenuItems) { - this.menu.toggle(); - } else { - // update menu if there's no entries - this._updateMenu(); - // wait for menu update - this._waitForDoubleClick().catch(logError); - } + this.menu.toggle(); return Clutter.EVENT_PROPAGATE; } const doubleClickHandled = this._maybeHandleDoubleClick(event); if (doubleClickHandled === Clutter.EVENT_PROPAGATE && - event.get_button() === Clutter.BUTTON_PRIMARY) { - if (this.menu.numMenuItems) { - if (this._indicator.supportsActivation !== false) - this._waitForDoubleClick().catch(logError); - else - this.menu.toggle(); - } else { - // update menu if there's no entries - this._updateMenu(); - // wait for double click or menu update + event.get_button() === Clutter.BUTTON_PRIMARY && + this.menu.numMenuItems) { + if (this._indicator.supportsActivation !== false) this._waitForDoubleClick().catch(logError); - } + else + this.menu.toggle(); } return Clutter.EVENT_PROPAGATE; From df9e8a1b31f24092a814186c2936b2f6819d71a9 Mon Sep 17 00:00:00 2001 From: lost-melody Date: Thu, 8 May 2025 19:05:48 +0800 Subject: [PATCH 3/3] handle LayoutUpdated signal for empty menus --- dbusMenu.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dbusMenu.js b/dbusMenu.js index 95dcea0b..e1ec0214 100644 --- a/dbusMenu.js +++ b/dbusMenu.js @@ -475,16 +475,23 @@ export const DBusClient = GObject.registerClass({ } } + _isEmptyMenu() { + const rootItem = this.getRoot(); + return !rootItem || rootItem.getChildren().length === 0; + } + _onSignal(_sender, signal, params) { + // an empty menu will not open, thus the signal "open-state-changed" + // will never be emitted, and thus `this._active` will always be false. if (signal === 'LayoutUpdated') { - if (!this._active) { + if (!this._active && !this._isEmptyMenu()) { this._flagLayoutUpdateRequired = true; return; } this._requestLayoutUpdate(); } else if (signal === 'ItemsPropertiesUpdated') { - if (!this._active) { + if (!this._active && !this._isEmptyMenu()) { this._flagItemsUpdateRequired = true; return; }