Add management for onDblClick, onRightClick and onRightDblClick events. Before they were put under Click event.

This commit is contained in:
Grégory Soutadé 2020-11-18 16:17:58 +01:00
parent 8a480254cd
commit 4c52c9fa8e

View File

@ -17,12 +17,18 @@
*/
/* Based on https://stackoverflow.com/questions/33001192/how-to-send-a-string-to-a-gnome-shell-extension */
// https://github.com/bananenfisch/RecentItems/blob/master/extension.js
// https://github.com/julio641742/gnome-shell-extension-reference/blob/master/tutorials/POPUPMENU-EXTENSION.md
// https://gjs-docs.gnome.org/st10~1.0_api/st.widget
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/panelMenu.js
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/panel.js
/*
Some useful documentation :
https://github.com/bananenfisch/RecentItems/blob/master/extension.js
https://github.com/julio641742/gnome-shell-extension-reference/blob/master/tutorials/POPUPMENU-EXTENSION.md
https://gjs-docs.gnome.org/st10~1.0_api/st.widget
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/panelMenu.js
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/popupMenu.js
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/panel.js
*/
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
@ -79,7 +85,7 @@ class MonitorWidget extends PanelMenu.Button {
this.fullname = this.name + '@' + this.group;
this.dbus = dbus;
this.signals = {}
if (item.hasOwnProperty('icon'))
{
if (typeof(item['icon']) === "string")
@ -112,10 +118,13 @@ 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.onScroll = hash_get(item, 'on-scroll', '');
this.onClick = hash_get(item, 'on-click', '');
this.onDblClick = hash_get(item, 'on-dblclick', '');
this.onRightClick = hash_get(item, 'on-rightclick', '');
this.onRightDblClick = hash_get(item, 'on-rightdblclick', '');
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');
@ -298,17 +307,26 @@ class MonitorWidget extends PanelMenu.Button {
}
_doClickCallback() {
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';
let right = '';
let nbClicks = '';
if (this.button == 3)
right = 'Right';
if (this.nbClicks > 1)
nbClicks = 'Dbl';
let signalName = 'on' + right + nbClicks + 'Click';
let action = 'signal';
switch(signalName) {
case 'onClick': action = this.onClick; break;
case 'onDblClick': action = this.onDblClick; break;
case 'onRightClick': action = this.onRightClick; break;
case 'onRightDblClick': action = this.onRightDblClick; break;
}
if (action === 'signal')
this.dbus.emit_signal(signalName, this.fullname);
} else
this._manageEventAction(this.onClick);
else
this._manageEventAction(action);
this.nbClicks = 0;
this.button = -1;
@ -442,10 +460,13 @@ 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.onScroll = hash_get(item, 'on-scroll', this.onScroll);
this.onClick = hash_get(item, 'on-click', this.onClick);
this.onDblClick = hash_get(item, 'on-dblclick', this.onDblClick);
this.onRightClick = hash_get(item, 'on-rightclick', this.onRightClick);
this.onRightDblClick = hash_get(item, 'on-rightdblclick', this.onRightDblClick);
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() {