Add onScroll[Up|Down] event

This commit is contained in:
Grégory Soutadé 2020-11-12 14:16:17 +01:00
parent 6b1fe1dd2d
commit b10b73135d
3 changed files with 70 additions and 38 deletions

View File

@ -60,6 +60,8 @@ extension emit one of the following signals :
* onRightDblClick * onRightDblClick
* onEnter * onEnter
* onLeave * onLeave
* onScrollUp
* onScrollDown
Other signals are available when extension is activated/deactivated : Other signals are available when extension is activated/deactivated :

View File

@ -18,7 +18,7 @@
<method name="togglePopup"> <method name="togglePopup">
<arg type="s" direction="in" /> <arg type="s" direction="in" />
</method> </method>
<!-- Click events --> <!-- Events -->
<signal name="onClick"> <signal name="onClick">
<arg type="s" direction="out" /> <arg type="s" direction="out" />
</signal> </signal>
@ -31,6 +31,12 @@
<signal name="onRightDblClick"> <signal name="onRightDblClick">
<arg type="s" direction="out" /> <arg type="s" direction="out" />
</signal> </signal>
<signal name="onScrollUp">
<arg type="s" direction="out" />
</signal>
<signal name="onScrollDown">
<arg type="s" direction="out" />
</signal>
<signal name="onEnter"> <signal name="onEnter">
<arg type="s" direction="out" /> <arg type="s" direction="out" />
</signal> </signal>

View File

@ -78,6 +78,7 @@ class MonitorWidget extends PanelMenu.Button {
this.group = group; this.group = group;
this.fullname = this.name + '@' + this.group; this.fullname = this.name + '@' + this.group;
this.dbus = dbus; this.dbus = dbus;
this.signals = {}
if (item.hasOwnProperty('icon')) if (item.hasOwnProperty('icon'))
{ {
@ -111,9 +112,10 @@ class MonitorWidget extends PanelMenu.Button {
if (item.hasOwnProperty('popup')) if (item.hasOwnProperty('popup'))
this._createPopup(item['popup']); this._createPopup(item['popup']);
this.onClick = hash_get(item, 'on-click', ''); this.onClick = hash_get(item, 'on-click', '');
this.onEnter = hash_get(item, 'on-enter', ''); this.onEnter = hash_get(item, 'on-enter', '');
this.onLeave = hash_get(item, 'on-leave', ''); this.onLeave = hash_get(item, 'on-leave', '');
this.onScroll = hash_get(item, 'on-scroll', '');
let box = hash_get(item, 'box', 'center'); let box = hash_get(item, 'box', 'center');
@ -138,17 +140,23 @@ class MonitorWidget extends PanelMenu.Button {
} }
_connectWidgetSignals(widget) { _connectWidgetSignals(widget) {
widget.connect('enter-event', this._onEnter.bind(this)); this.signals[widget] = [];
widget.connect('leave-event', this._onLeave.bind(this)); 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.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) { _disconnectWidgetSignals(widget) {
widget.connect('enter-event', this._onEnter.bind(this)); for(let idx in this.signals[widget])
widget.connect('leave-event', this._onLeave.bind(this)); widget.disconnect(this.signals[widget][idx]);
widget.set_reactive(true); this.signals[widget] = null;
widget.connect('button-release-event', Lang.bind(this, this._clicked));
} }
_createPopup(item) { _createPopup(item) {
@ -273,6 +281,8 @@ class MonitorWidget extends PanelMenu.Button {
this.menu.open(true); this.menu.open(true);
else if (action === 'close-popup') else if (action === 'close-popup')
this.menu.close(); this.menu.close();
else if (action === 'toggle-popup')
this.menu.toggle();
else if (action == 'delete') else if (action == 'delete')
this.dbus.deleteItem(this, this.group); this.dbus.deleteItem(this, this.group);
else else
@ -285,37 +295,37 @@ class MonitorWidget extends PanelMenu.Button {
} }
_doClickCallback() { _doClickCallback() {
let right = ''; if (this.onClick === 'signal') {
let nbClicks = ''; let right = '';
if (this.button == 3) let nbClicks = '';
right = 'Right'; if (this.button == 3)
if (this.nbClicks > 1) right = 'Right';
nbClicks = 'Dbl'; if (this.nbClicks > 1)
let signalName = 'on' + right + nbClicks + 'Click'; nbClicks = 'Dbl';
this.dbus.emit_signal(signalName, this.fullname); let signalName = 'on' + right + nbClicks + 'Click';
this.dbus.emit_signal(signalName, this.fullname);
} else
this._manageEventAction(this.onClick);
this.nbClicks = 0; this.nbClicks = 0;
this.button = -1; this.button = -1;
return false;
} }
_clicked(actor, event) { _clicked(actor, event) {
if (this.onClick === 'signal') { if (event.get_button() == this.button) {
if (event.get_button() == this.button) { this.nbClicks++;
this.nbClicks++; } else {
} else { this.button = event.get_button();
this.button = event.get_button(); this.nbClicks = 1;
this.nbClicks = 1;
Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'], Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
Lang.bind(this, this._doClickCallback)); Lang.bind(this, this._doClickCallback));
} }
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
} else if (this.onClick === 'open-popup') {
this.menu.toggle();
} else
return this._manageEventAction(this.onClick);
} }
_onEnter() { _onEnter(actor, event) {
if (this.onEnter === 'signal') if (this.onEnter === 'signal')
this.dbus.emit_signal('onEnter', this.fullname); this.dbus.emit_signal('onEnter', this.fullname);
else else
@ -324,7 +334,7 @@ class MonitorWidget extends PanelMenu.Button {
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
} }
_onLeave() { _onLeave(actor, event) {
if (this.onLeave === 'signal') if (this.onLeave === 'signal')
this.dbus.emit_signal('onLeave', this.fullname); this.dbus.emit_signal('onLeave', this.fullname);
else else
@ -333,6 +343,19 @@ class MonitorWidget extends PanelMenu.Button {
return Clutter.EVENT_STOP; 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) { update(item) {
let prevWidget = this.widget; let prevWidget = this.widget;
let prevIcon = this.icon; let prevIcon = this.icon;
@ -415,9 +438,10 @@ class MonitorWidget extends PanelMenu.Button {
this.menu.open(true); 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);
this.onScroll = hash_get(item, 'on-scroll', this.onScroll);
} }
openPopup() { openPopup() {