Gnome SHELL Generic Monitor

Gnome SHELL Generic Monitor Commit Details

Date:2020-05-04 10:08:39 (6 months 25 days ago)
Author:Grégory Soutadé
Branch:master
Commit:c7462662f4312e16c5f08ff9ee1d7965d902829d
Parents: b3200da89c0413dd19a2ee58403b0353a8250515
Message:Add onClick feature

Changes:
MREADME.md (3 diffs)
Mdbus.xml (1 diff)
Mextension.js (8 diffs)
Mmetadata.json (1 diff)

File differences

README.md
2525
2626
2727
28
2829
2930
3031
......
3233
3334
3435
36
3537
3638
3739
......
4850
4951
5052
53
54
55
56
57
58
59
60
61
5162
5263
5364
"group": "groupname",
// style and icon-style are optional
// item can have text and/or icon
// item can have click action "signal" or "delete"
"items": [
{
"name":"",
"style":"",
"icon-style":"",
"icon":"",
"on-click":"",
}, ...
]
}
}
When text/icon is clicked and on-click parameter is set to "signal",
extension emit one of the following signals :
* onClick
* onRightClick
* onDblClick
* onRightDblClick
Example
-------
dbus.xml
88
99
1010
11
12
13
14
15
16
17
18
19
20
21
22
1123
<method name="deleteGroups">
<arg type="s" direction="in" />
</method>
<signal name="onClick">
<arg type="s" direction="out" />
</signal>
<signal name="onRightClick">
<arg type="s" direction="out" />
</signal>
<signal name="onDblClick">
<arg type="s" direction="out" />
</signal>
<signal name="onRightDblClick">
<arg type="s" direction="out" />
</signal>
</interface>
extension.js
2020
2121
2222
23
24
2325
26
27
2428
2529
26
30
2731
2832
2933
3034
35
3136
3237
3338
......
100105
101106
102107
108
109
103110
104111
105112
......
118125
119126
120127
128
129
130
131
121132
122133
123134
......
131142
132143
133144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
134212
135213
136214
......
158236
159237
160238
161
239
240
241
242
162243
163244
164245
165246
166247
167
248
168249
169250
170251
......
175256
176257
177258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
178273
179274
180275
......
201296
202297
203298
299
300
301
302
303
304
305
306
307
308
204309
205310
206311
......
219324
220325
221326
222
223
224
225
327
226328
227329
228330
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const GLib = imports.gi.GLib
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
const clutter = imports.gi.Clutter;
class MonitorWidget {
constructor(name, group, text, style, icon, iconStyle) {
constructor(name, group, text, style, icon, iconStyle, onClick) {
this.name = name;
this.group = group;
this._createIcon(icon, iconStyle);
this._createText(text, style);
this.onClick = onClick;
}
_createText(text, style) {
class GenericMonitorDBUS {
constructor() {
this.monitor_groups = {};
this.actor_clicked = {};
this.clutterSettings = clutter.Settings.get_default();
this.box = Main.panel._centerBox;
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
throw new Error('No name defined for item');
if (!item.hasOwnProperty('text') && !item.hasOwnProperty('icon'))
throw new Error('No text not icon defined for item');
if (item.hasOwnProperty('on-click')) {
if (item['on-click'] !== 'signal' && item['on-click'] !== 'delete')
throw new Error('Invalid on-click value');
}
}
}
return null;
}
_doClickCallback() {
for(let itemIndex in this.actor_clicked) {
let item = this.actor_clicked[itemIndex];
let right = '';
let nbClicks = '';
if (item['button'] == 3)
right = 'Right';
if (item['nbClicks'] > 1)
nbClicks = 'Dbl';
let signalName = 'on' + right + nbClicks + 'Click';
this._dbusImpl.emit_signal(signalName, GLib.Variant.new('(s)',[item['name']]));
}
this.actor_clicked = {}
}
_actorToMonitorWidget(actor) {
for (let groupName in this.monitor_groups) {
let group = this.monitor_groups[groupName];
for (let itemIndex in group) {
let item = group[itemIndex];
if (item.widget === actor ||
item.icon === actor)
return [groupName, item];
}
}
return null;
}
_removeFromArray(array, value) {
for(let i=0; i<array.length; i++) {
if (array[i] === value) {
array.splice(i, 1);
if (array === null)
array = [];
break;
}
}
return array;
}
// https://stackoverflow.com/questions/50100546/how-do-i-detect-clicks-on-the-gnome-appmenu
_clicked(actor, event) {
let result = this._actorToMonitorWidget(actor);
if (result === null)
return;
let groupName = result[0];
let monitorWidget = result[1];
if (monitorWidget.onClick == 'signal') {
let actorName = monitorWidget.name + '@' + groupName;
if (!this.actor_clicked.hasOwnProperty(actorName)) {
let clickItem = {};
clickItem['name'] = actorName;
clickItem['nbClicks'] = 1;
clickItem['button'] = event.get_button();
this.actor_clicked[actorName] = clickItem;
Mainloop.timeout_add(this.clutterSettings['double-click-time'],
Lang.bind(this, this._doClickCallback));
} else {
this.actor_clicked[actorName]['nbClicks'] = 2;
}
} else if (monitorWidget.onClick == 'delete') {
this.deleteItem(monitorWidget, groupName);
}
}
notify(str) {
let parameters = JSON.parse(str);
this._checkParmeters(parameters);
let iconStyle = '';
if (item.hasOwnProperty('icon-style'))
iconStyle = item['icon-style'];
let onClick = '';
if (item.hasOwnProperty('on-click'))
onClick = item['on-click'];
let monitorWidget = this._getItemFromGroup(group, item['name']);
let lastWidget = null;
// New widget
if (monitorWidget === null) {
monitorWidget = new MonitorWidget(item['name'], groupName, text, style, icon, iconStyle);
monitorWidget = new MonitorWidget(item['name'], groupName, text, style, icon, iconStyle, onClick);
if (group.length)
lastWidget = group[group.length - 1].widget;
group.push(monitorWidget);
}
if (monitorWidget.widget)
this.box.insert_child_above(monitorWidget.widget, lastWidget);
// Connect signals
if (onClick !== '') {
if (monitorWidget.widget)
monitorWidget.widget.set_reactive(true);
monitorWidget.widget.connect(
'button-release-event', Lang.bind(this, this._clicked)
);
if (monitorWidget.icon) {
monitorWidget.icon.set_reactive(true);
monitorWidget.icon.connect(
'button-release-event', Lang.bind(this, this._clicked)
);
}
}
} else {
let prevWidget = monitorWidget.widget;
let prevIcon = monitorWidget.icon;
this.box.remove_child(item.icon);
}
deleteItem(item, groupName) {
let group = this.monitor_groups[groupName];
this._removeItemFromBox(item);
group = this._removeFromArray(group, item);
if (group.length === 0)
delete this.monitor_groups[groupName];
else
this.monitor_groups = group;
}
deleteItems(str) {
let parameters = JSON.parse(str);
let group = this.monitor_groups[groupName];
let item = this._getItemFromGroup(group, itemName);
if (item !== null) {
this._removeItemFromBox(item);
delete group[item['name']];
if (group.length === 0)
delete this.monitor_groups[groupName];
this.deleteItem(item, groupName);
}
}
}
metadata.json
11
22
33
4
5
4
5
66
77
88
{
"uuid": "generic-monitor@gnome-shell-extensions",
"name": "Generic Monitor",
"description": "Generic monitor using DBUS",
"version": "1",
"description": "Display text & icon on systray using DBUS",
"version": "2",
"shell-version": [
"3.34"
],

Archive Download the corresponding diff file

Branches

Tags