Work on events
This commit is contained in:
parent
bd9e3722a2
commit
d3eb13994a
39
extension.js
39
extension.js
|
@ -120,8 +120,6 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
if (box === 'right' && position == -1)
|
if (box === 'right' && position == -1)
|
||||||
position = 0;
|
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));
|
this.connect('style-changed', this._onStyleChanged.bind(this));
|
||||||
|
|
||||||
// Disable click event at PanelMenu.button level
|
// Disable click event at PanelMenu.button level
|
||||||
|
@ -129,7 +127,6 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
|
|
||||||
this.nbClicks = 0;
|
this.nbClicks = 0;
|
||||||
this.button = -1;
|
this.button = -1;
|
||||||
this.nbEnter = 0;
|
|
||||||
|
|
||||||
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
||||||
}
|
}
|
||||||
|
@ -147,6 +144,13 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
widget.connect('button-release-event', Lang.bind(this, this._clicked));
|
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) {
|
_createPopup(item) {
|
||||||
if (!item.hasOwnProperty('items')) {
|
if (!item.hasOwnProperty('items')) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -277,10 +281,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
_manageLeaveEvent() {
|
_manageLeaveEvent() {
|
||||||
if (this.nbEnter <= 0) {
|
this._manageEventAction(this.onLeave);
|
||||||
this._manageEventAction(this.onLeave);
|
|
||||||
this.nbEnter = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_doClickCallback() {
|
_doClickCallback() {
|
||||||
|
@ -317,10 +318,8 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
_onEnter() {
|
_onEnter() {
|
||||||
if (this.onEnter === 'signal')
|
if (this.onEnter === 'signal')
|
||||||
this.dbus.emit_signal('onEnter', this.fullname);
|
this.dbus.emit_signal('onEnter', this.fullname);
|
||||||
else {
|
else
|
||||||
this.nbEnter++;
|
|
||||||
return this._manageEventAction(this.onEnter);
|
return this._manageEventAction(this.onEnter);
|
||||||
}
|
|
||||||
|
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
}
|
}
|
||||||
|
@ -328,11 +327,8 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
_onLeave() {
|
_onLeave() {
|
||||||
if (this.onLeave === 'signal')
|
if (this.onLeave === 'signal')
|
||||||
this.dbus.emit_signal('onLeave', this.fullname);
|
this.dbus.emit_signal('onLeave', this.fullname);
|
||||||
else {
|
else
|
||||||
this.nbEnter--;
|
return this._manageEventAction(this.onEnter);
|
||||||
Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
|
||||||
Lang.bind(this, this._manageLeaveEvent));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
}
|
}
|
||||||
|
@ -392,6 +388,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevIcon) {
|
if (prevIcon) {
|
||||||
|
this._disconnectWidgetSignals(prevIcon);
|
||||||
this.insert_child_above(this.icon, prevIcon);
|
this.insert_child_above(this.icon, prevIcon);
|
||||||
this.remove_child(prevIcon);
|
this.remove_child(prevIcon);
|
||||||
//delete prevIcon;
|
//delete prevIcon;
|
||||||
|
@ -405,18 +402,28 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
|
|
||||||
if (item.hasOwnProperty('popup'))
|
if (item.hasOwnProperty('popup'))
|
||||||
{
|
{
|
||||||
|
let menuOpen = this.menu.isOpen;
|
||||||
if (this.menuItem) {
|
if (this.menuItem) {
|
||||||
|
if (menuOpen)
|
||||||
|
this.menu.close();
|
||||||
this.menu.removeAll();
|
this.menu.removeAll();
|
||||||
//delete this.menuItem;
|
//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.onClick = hash_get(item, 'on-click', this.onClick);
|
||||||
this.onEnter = hash_get(item, 'on-enter', this.onEnter);
|
this.onEnter = hash_get(item, 'on-enter', this.onEnter);
|
||||||
this.onLeave = hash_get(item, 'on-leave', this.onLeave);
|
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
|
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
||||||
|
|
Loading…
Reference in New Issue
Block a user