diff --git a/extension.js b/extension.js index 8f46769..e29bd51 100644 --- a/extension.js +++ b/extension.js @@ -120,8 +120,6 @@ class MonitorWidget extends PanelMenu.Button { if (box === 'right' && position == -1) position = 0; - this.connect('enter-event', this._onEnter.bind(this)); - this.connect('leave-event', this._onLeave.bind(this)); this.connect('style-changed', this._onStyleChanged.bind(this)); // Disable click event at PanelMenu.button level @@ -129,7 +127,6 @@ class MonitorWidget extends PanelMenu.Button { this.nbClicks = 0; this.button = -1; - this.nbEnter = 0; Main.panel.addToStatusArea(this.fullname, this, position, box); } @@ -146,6 +143,13 @@ class MonitorWidget extends PanelMenu.Button { widget.set_reactive(true); widget.connect('button-release-event', Lang.bind(this, this._clicked)); } + + _disconnectWidgetSignals(widget) { + widget.connect('enter-event', this._onEnter.bind(this)); + widget.connect('leave-event', this._onLeave.bind(this)); + widget.set_reactive(true); + widget.connect('button-release-event', Lang.bind(this, this._clicked)); + } _createPopup(item) { if (!item.hasOwnProperty('items')) { @@ -277,10 +281,7 @@ class MonitorWidget extends PanelMenu.Button { } _manageLeaveEvent() { - if (this.nbEnter <= 0) { - this._manageEventAction(this.onLeave); - this.nbEnter = 0; - } + this._manageEventAction(this.onLeave); } _doClickCallback() { @@ -317,10 +318,8 @@ class MonitorWidget extends PanelMenu.Button { _onEnter() { if (this.onEnter === 'signal') this.dbus.emit_signal('onEnter', this.fullname); - else { - this.nbEnter++; + else return this._manageEventAction(this.onEnter); - } return Clutter.EVENT_STOP; } @@ -328,11 +327,8 @@ class MonitorWidget extends PanelMenu.Button { _onLeave() { if (this.onLeave === 'signal') this.dbus.emit_signal('onLeave', this.fullname); - else { - this.nbEnter--; - Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'], - Lang.bind(this, this._manageLeaveEvent)); - } + else + return this._manageEventAction(this.onEnter); return Clutter.EVENT_STOP; } @@ -392,6 +388,7 @@ class MonitorWidget extends PanelMenu.Button { } if (prevIcon) { + this._disconnectWidgetSignals(prevIcon); this.insert_child_above(this.icon, prevIcon); this.remove_child(prevIcon); //delete prevIcon; @@ -405,18 +402,28 @@ class MonitorWidget extends PanelMenu.Button { if (item.hasOwnProperty('popup')) { + let menuOpen = this.menu.isOpen; if (this.menuItem) { + if (menuOpen) + this.menu.close(); this.menu.removeAll(); //delete this.menuItem; } - this._createPopup(item['popup']); + let popup = this._createPopup(item['popup']); + if (popup !== null && menuOpen) + this.menu.open(true); } this.onClick = hash_get(item, 'on-click', this.onClick); this.onEnter = hash_get(item, 'on-enter', this.onEnter); this.onLeave = hash_get(item, 'on-leave', this.onLeave); } + + destroy() { + this.menu.close(); + super.destroy(); + } }); // From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js