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
* onEnter
* onLeave
* onScrollUp
* onScrollDown
Other signals are available when extension is activated/deactivated :

View File

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

View File

@ -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() {