diff --git a/README.md b/README.md index a1465fa..3ea91bb 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ extension emit one of the following signals : * onRightDblClick * onEnter * onLeave + * onScrollUp + * onScrollDown Other signals are available when extension is activated/deactivated : diff --git a/dbus.xml b/dbus.xml index 4819b05..52274ce 100644 --- a/dbus.xml +++ b/dbus.xml @@ -18,7 +18,7 @@ - + @@ -31,6 +31,12 @@ + + + + + + diff --git a/extension.js b/extension.js index 56c5129..bf4684c 100644 --- a/extension.js +++ b/extension.js @@ -78,6 +78,7 @@ class MonitorWidget extends PanelMenu.Button { this.group = group; this.fullname = this.name + '@' + this.group; this.dbus = dbus; + this.signals = {} if (item.hasOwnProperty('icon')) { @@ -111,9 +112,10 @@ class MonitorWidget extends PanelMenu.Button { if (item.hasOwnProperty('popup')) this._createPopup(item['popup']); - this.onClick = hash_get(item, 'on-click', ''); - this.onEnter = hash_get(item, 'on-enter', ''); - this.onLeave = hash_get(item, 'on-leave', ''); + this.onClick = hash_get(item, 'on-click', ''); + this.onEnter = hash_get(item, 'on-enter', ''); + this.onLeave = hash_get(item, 'on-leave', ''); + this.onScroll = hash_get(item, 'on-scroll', ''); let box = hash_get(item, 'box', 'center'); @@ -138,17 +140,23 @@ class MonitorWidget extends PanelMenu.Button { } _connectWidgetSignals(widget) { - widget.connect('enter-event', this._onEnter.bind(this)); - widget.connect('leave-event', this._onLeave.bind(this)); + this.signals[widget] = []; + let id; + id = widget.connect('enter-event', this._onEnter.bind(this)); + this.signals[widget].push(id); + id = widget.connect('leave-event', this._onLeave.bind(this)); + this.signals[widget].push(id); + id = widget.connect('scroll-event', this._onScroll.bind(this)); + this.signals[widget].push(id); widget.set_reactive(true); - widget.connect('button-release-event', Lang.bind(this, this._clicked)); + id = widget.connect('button-release-event', Lang.bind(this, this._clicked)); + this.signals[widget].push(id); } _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)); + for(let idx in this.signals[widget]) + widget.disconnect(this.signals[widget][idx]); + this.signals[widget] = null; } _createPopup(item) { @@ -273,6 +281,8 @@ class MonitorWidget extends PanelMenu.Button { this.menu.open(true); else if (action === 'close-popup') this.menu.close(); + else if (action === 'toggle-popup') + this.menu.toggle(); else if (action == 'delete') this.dbus.deleteItem(this, this.group); else @@ -285,37 +295,37 @@ class MonitorWidget extends PanelMenu.Button { } _doClickCallback() { - let right = ''; - let nbClicks = ''; - if (this.button == 3) - right = 'Right'; - if (this.nbClicks > 1) - nbClicks = 'Dbl'; - let signalName = 'on' + right + nbClicks + 'Click'; - this.dbus.emit_signal(signalName, this.fullname); + if (this.onClick === 'signal') { + let right = ''; + let nbClicks = ''; + if (this.button == 3) + right = 'Right'; + if (this.nbClicks > 1) + nbClicks = 'Dbl'; + let signalName = 'on' + right + nbClicks + 'Click'; + this.dbus.emit_signal(signalName, this.fullname); + } else + this._manageEventAction(this.onClick); this.nbClicks = 0; this.button = -1; + + return false; } _clicked(actor, event) { - if (this.onClick === 'signal') { - if (event.get_button() == this.button) { - this.nbClicks++; - } else { - this.button = event.get_button(); - this.nbClicks = 1; + if (event.get_button() == this.button) { + this.nbClicks++; + } else { + this.button = event.get_button(); + this.nbClicks = 1; - Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'], - Lang.bind(this, this._doClickCallback)); - } - return Clutter.EVENT_STOP; - } else if (this.onClick === 'open-popup') { - this.menu.toggle(); - } else - return this._manageEventAction(this.onClick); + Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'], + Lang.bind(this, this._doClickCallback)); + } + return Clutter.EVENT_STOP; } - _onEnter() { + _onEnter(actor, event) { if (this.onEnter === 'signal') this.dbus.emit_signal('onEnter', this.fullname); else @@ -324,7 +334,7 @@ class MonitorWidget extends PanelMenu.Button { return Clutter.EVENT_STOP; } - _onLeave() { + _onLeave(actor, event) { if (this.onLeave === 'signal') this.dbus.emit_signal('onLeave', this.fullname); else @@ -333,6 +343,19 @@ class MonitorWidget extends PanelMenu.Button { return Clutter.EVENT_STOP; } + _onScroll(actor, event) { + if (this.onScroll === 'signal') { + let direction = event.get_scroll_direction (); + if (direction == Clutter.ScrollDirection.UP) + this.dbus.emit_signal('onScrollUp', this.fullname); + else if (direction == Clutter.ScrollDirection.DOWN) + this.dbus.emit_signal('onScrollDown', this.fullname); + } else + return this._manageEventAction(this.onEnter); + + return Clutter.EVENT_STOP; + } + update(item) { let prevWidget = this.widget; let prevIcon = this.icon; @@ -415,9 +438,10 @@ class MonitorWidget extends PanelMenu.Button { 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); + 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); + this.onScroll = hash_get(item, 'on-scroll', this.onScroll); } openPopup() {