2 Commits
v15 ... master

Author SHA1 Message Date
b4af852a0f Fix formatting in README 2025-07-05 18:10:38 +02:00
6aa9f15d70 Update extension for GNOME 48 2025-03-31 15:14:59 +02:00
3 changed files with 92 additions and 72 deletions

View File

@@ -13,8 +13,11 @@ OR
Create a symbolic link from your _.local_ directory and enable extension Create a symbolic link from your _.local_ directory and enable extension
ln -s $PWD/generic-monitor@gnome-shell-extensions/ ~/.local/share/gnome-shell/extensions/ ```bash
gnome-extensions enable generic-monitor@gnome-shell-extensions ln -s $PWD/generic-monitor@gnome-shell-extensions/ ~/.local/share/gnome-shell/extensions/
gnome-extensions enable generic-monitor@gnome-shell-extensions
```
Restart GNOME Restart GNOME
@@ -24,6 +27,7 @@ DBUS protocol
All functions read JSON formatted parameters All functions read JSON formatted parameters
```js
notify(): notify():
{ {
"group": "groupname", "group": "groupname",
@@ -64,26 +68,32 @@ All functions read JSON formatted parameters
{ {
"item": "<itemName>@<groupName>" "item": "<itemName>@<groupName>"
} }
```
DBUS object DBUS object
=========== ===========
<text_object> is defined as : <text_object> is defined as:
```js
"text" : { "text" : {
"name" : "" // Optional, used with popup nested element "name" : "" // Optional, used with popup nested element
<signals_description>, // Optional, used with popup nested element <signals_description>, // Optional, used with popup nested element
"text" : "Text to be displayed", "text" : "Text to be displayed",
"style" : "CSS style to be applied", // Optional "style" : "CSS style to be applied", // Optional
} }
```
<icon_object> is defined as : <icon_object> is defined as:
```js
"icon" : { "icon" : {
"path" : "Icon path", "path" : "Icon path",
"style" : "CSS style to be applied", // Optional "style" : "CSS style to be applied", // Optional
} }
```
<picture_object> is defined as : <picture_object> is defined as:
```js
"picture" : { "picture" : {
"name" : "" // Optional, used with popup nested element "name" : "" // Optional, used with popup nested element
<signals_description>, // Optional, used with popup nested element <signals_description>, // Optional, used with popup nested element
@@ -91,18 +101,21 @@ DBUS object
"width" : XXX, // Optional : Force width in pixels, can be -1 for defaut value "width" : XXX, // Optional : Force width in pixels, can be -1 for defaut value
"height" : XXX, // Optional : Force height in pixels, can be -1 for defaut value "height" : XXX, // Optional : Force height in pixels, can be -1 for defaut value
} }
```
<popup_object is defuned as : <popup_object> is defined as:
```js
"popup" : { "popup" : {
"items": [<text_objects> and/or <picture_objects>] "items": [<text_objects> and/or <picture_objects>]
} }
```
Signals description Signals description
=================== ===================
Signals can be : Signals can be :
```js
"on-click" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"] "on-click" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
"on-dblclick" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"] "on-dblclick" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
"on-rightclick" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"] "on-rightclick" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
@@ -110,6 +123,7 @@ Signals can be :
"on-enter" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"] "on-enter" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
"on-leave" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"] "on-leave" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
"on-scroll" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"] "on-scroll" : ["signal"|"delete"|"open-popup"|"close-popup"|"toggle-popup"]
```
Targets : Targets :
@@ -120,7 +134,7 @@ Targets :
* toggle-popup : Toggle (open/close) the popup if there is one * toggle-popup : Toggle (open/close) the popup if there is one
Signal names emit when action "signal" is specified : Signal names emit when action "signal" is specified:
* onClick * onClick
* onDblClick * onDblClick
@@ -131,11 +145,11 @@ Signal names emit when action "signal" is specified :
* onScrollUp * onScrollUp
* onScrollDown * onScrollDown
Each signal is sent with one parameter : "<itemName>@<groupName>" Each signal is sent with one parameter: "<itemName>@<groupName>"
For popup nested elements, parameter is "<nestedName>@<itemName>@<groupName>" For popup nested elements, parameter is "<nestedName>@<itemName>@<groupName>"
where nestedName can be empty if not defined by user where nestedName can be empty if not defined by user
Other signals are available when extension is activated/deactivated : Other signals are available when extension is activated/deactivated:
* onActivate * onActivate
* onDeactivate * onDeactivate
@@ -144,11 +158,15 @@ Other signals are available when extension is activated/deactivated :
Example Example
------- -------
You can test it with command line : You can test it with command line:
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.notify '{"group":"new","items":[{"name":"first","on-click":"toggle-popup","text":{"text":"Hello","style":"color:green"},"popup":{"items":[{"picture":{"path":"/tmp/cat.jpg"}}]}}]}' ```bash
# Create new group and add items
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.notify '{"group":"new","items":[{"name":"first","on-click":"toggle-popup","text":{"text":"Hello","style":"color:green"},"popup":{"items":[{"picture":{"path":"/tmp/cat.jpg"}}]}}]}'
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.deleteGroups '{"groups":["new"]}' # Delete group
gdbus call --session --dest org.gnome.Shell --object-path /com/soutade/GenericMonitor --method com.soutade.GenericMonitor.deleteGroups '{"groups":["new"]}'
```
Python examples are available @ https://indefero.soutade.fr/p/genericmonitor/source/tree/master/examples Python examples are available @ https://indefero.soutade.fr/p/genericmonitor/source/tree/master/examples
@@ -158,12 +176,15 @@ Development
After doing code update, you can test it within a nested window. In other cases you have to restart GNOME. After doing code update, you can test it within a nested window. In other cases you have to restart GNOME.
dbus-run-session -- gnome-shell --nested [--wayland] ```bash
dbus-run-session -- gnome-shell --nested [--wayland]
```
To see log & errors : To see log & errors:
journalctl /usr/bin/gnome-shell
```bash
journalctl /usr/bin/gnome-shell
```
Licence Licence
------- -------

View File

@@ -49,18 +49,14 @@ function hashGet(hash, key, defaultValue) {
return defaultValue; return defaultValue;
} }
function log(message) {
console.error('[GenericMontior]', message);
}
class SignalMgt { class SignalMgt {
constructor(item, name, group, dbus, buttonMenu) { constructor(item, name, group, dbus, logger, buttonMenu) {
this.name = name; this.name = name;
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.logger = logger;
this.buttonMenu = buttonMenu; this.buttonMenu = buttonMenu;
this.signals = new WeakMap(); this.signals = new WeakMap();
this.widgets = new Array(); this.widgets = new Array();
@@ -100,6 +96,7 @@ class SignalMgt {
this.widgets.push(widget); this.widgets.push(widget);
let array = new Array(); let array = new Array();
this.signals.set(widget, array); this.signals.set(widget, array);
widget.set_reactive(true);
let id; let id;
id = widget.connect('enter-event', this._onEnter.bind(this)); id = widget.connect('enter-event', this._onEnter.bind(this));
array.push(id); array.push(id);
@@ -107,7 +104,6 @@ class SignalMgt {
array.push(id); array.push(id);
id = widget.connect('scroll-event', this._onScroll.bind(this)); id = widget.connect('scroll-event', this._onScroll.bind(this));
array.push(id); array.push(id);
widget.set_reactive(true);
id = widget.connect('button-release-event', this._clicked.bind(this)); id = widget.connect('button-release-event', this._clicked.bind(this));
array.push(id); array.push(id);
} }
@@ -119,38 +115,34 @@ class SignalMgt {
this.signals.set(widget, null); this.signals.set(widget, null);
} }
toggleMenu() {
if (this.menuOpen)
{
this.buttonMenu.menu.close();
this.menuOpen = false;
}
else
{
this.buttonMenu.menu.open(true);
this.menuOpen = true;
}
}
_manageEventAction(action, signalName) { _manageEventAction(action, signalName) {
/*
GNOME 48 : onEnter && this.buttonMenu.menuOpen == close popup without onClick event
*/
if (signalName == "onEnter" && this.buttonMenu.menuOpen)
{
this.buttonMenu.menuOpen = false;
return Clutter.EVENT_STOP;
}
if (action === 'open-popup') if (action === 'open-popup')
{ {
this.buttonMenu.menu.open(true); this.buttonMenu.openPopup();
this.menuOpen = true;
} }
else if (action === 'close-popup') else if (action === 'close-popup')
{ {
this.buttonMenu.menu.close(); this.buttonMenu.closePopup();
this.menuOpen = false;
} }
else if (action === 'toggle-popup') else if (action === 'toggle-popup')
{ {
this.toggleMenu(); this.buttonMenu.togglePopup();
} }
else if (action === 'delete') else if (action === 'delete')
this.dbus.deleteItem(this, this.group); this.dbus.deleteItem(this, this.group);
else if (action === 'signal') else if (action === 'signal')
this.dbus.emitSignal(signalName, this.fullname); this.dbus.emitSignal(signalName, this.fullname);
else
return Clutter.EVENT_PROPAGATE;
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
} }
@@ -174,11 +166,11 @@ class SignalMgt {
case 'onRightDblClick': action = this.onRightDblClick; break; case 'onRightDblClick': action = this.onRightDblClick; break;
} }
this._manageEventAction(action, signalName);
this.nbClicks = 0; this.nbClicks = 0;
this.button = -1; this.button = -1;
this._manageEventAction(action, signalName);
return false; return false;
} }
@@ -195,7 +187,7 @@ class SignalMgt {
this.timeouts.push(sourceId); this.timeouts.push(sourceId);
} }
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_STOP;
} }
_onEnter(/*actor, event*/) { _onEnter(/*actor, event*/) {
@@ -226,7 +218,7 @@ class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
super._init(params); super._init(params);
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' }); this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
this.box.set_vertical(true); this.box.set_orientation(Clutter.Orientation.VERTICAL);
for (let widgetIndex in widgets) for (let widgetIndex in widgets)
this.box.add_child(widgets[widgetIndex]); this.box.add_child(widgets[widgetIndex]);
@@ -241,15 +233,16 @@ var MonitorWidget = GObject.registerClass({
}, },
class MonitorWidget extends PanelMenu.Button { class MonitorWidget extends PanelMenu.Button {
_init(item, group, dbus, position) { _init(item, group, dbus, logger, position) {
super._init(0.0); super._init(0.0);
this.name = item['name']; this.name = item['name'];
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.logger = logger;
this.menuItem = null; this.menuItem = null;
this.signalManager = new SignalMgt(item, this.name, group, dbus, this); this.signalManager = new SignalMgt(item, this.name, group, dbus, logger, this);
this.popup_signals = null; this.popup_signals = null;
this.popup_widgets = null; this.popup_widgets = null;
@@ -382,14 +375,19 @@ class MonitorWidget extends PanelMenu.Button {
openPopup() { openPopup() {
this.menu.open(true); this.menu.open(true);
this.menuOpen = this.menu.isOpen = true;
} }
closePopup() { closePopup() {
this.menu.close(); this.menu.close();
this.menuOpen = this.menu.isOpen = false;
} }
togglePopup() { togglePopup() {
this.menu.toggle(); if (this.menuOpen)
this.closePopup();
else
this.openPopup();
} }
destroy() { destroy() {
@@ -424,7 +422,7 @@ class MonitorWidget extends PanelMenu.Button {
nestedItem = widgetDict['picture']; nestedItem = widgetDict['picture'];
widget = this._createPicture(nestedItem); widget = this._createPicture(nestedItem);
} else { } else {
log('No known widget defined in popup'); this.logger.error('No known widget defined in popup');
} }
if (nestedItem === null) { if (nestedItem === null) {
@@ -435,7 +433,7 @@ class MonitorWidget extends PanelMenu.Button {
const name = hashGet(nestedItem, 'name', ''); const name = hashGet(nestedItem, 'name', '');
this.popup_signals[widget] = new SignalMgt(nestedItem, name, this.popup_signals[widget] = new SignalMgt(nestedItem, name,
this.fullname, this.dbus, this.fullname, this.dbus,
this); this.logger, this);
this.popup_signals[widget].connectWidgetSignals(widget); this.popup_signals[widget].connectWidgetSignals(widget);
this.popup_widgets.push(widget); this.popup_widgets.push(widget);
} }
@@ -460,7 +458,7 @@ class MonitorWidget extends PanelMenu.Button {
__createText(item, isLabel) { __createText(item, isLabel) {
if (!item.hasOwnProperty('text')) { if (!item.hasOwnProperty('text')) {
log('Text must have a \'text\' value'); this.logger.error('Text must have a \'text\' value');
return null; return null;
} }
@@ -500,7 +498,7 @@ class MonitorWidget extends PanelMenu.Button {
_createIcon(item) { _createIcon(item) {
if (!item.hasOwnProperty('path')) { if (!item.hasOwnProperty('path')) {
log('Icon must have a \'path\' value'); this.logger.error('Icon must have a \'path\' value');
return null; return null;
} }
@@ -521,7 +519,7 @@ class MonitorWidget extends PanelMenu.Button {
_createPicture(item) { _createPicture(item) {
if (!item.hasOwnProperty('path')) { if (!item.hasOwnProperty('path')) {
log('Picture must have a \'path\' value'); this.logger.error('Picture must have a \'path\' value');
return null; return null;
} }
@@ -534,9 +532,11 @@ class MonitorWidget extends PanelMenu.Button {
if (typeof(height) === 'string') if (typeof(height) === 'string')
height = parseInt(height, 10); height = parseInt(height, 10);
const img = new Clutter.Image();
const initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']); const initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
img.set_data(initialPixbuf.get_pixels(), const img = St.ImageContent.new_with_preferred_size(initialPixbuf.get_width(),
initialPixbuf.get_height());
img.set_data(global.stage.context.get_backend().get_cogl_context(),
initialPixbuf.get_pixels(),
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
: Cogl.PixelFormat.RGB_888, : Cogl.PixelFormat.RGB_888,
initialPixbuf.get_width(), initialPixbuf.get_width(),
@@ -584,6 +584,7 @@ function loadInterfaceXml(extension, filename) {
class GenericMonitorDBUS { class GenericMonitorDBUS {
constructor(extension) { constructor(extension) {
this.logger = extension.getLogger();
this.monitor_groups = {}; this.monitor_groups = {};
this.actor_clicked = {}; this.actor_clicked = {};
this.ClutterSettings = Clutter.Settings.get_default(); this.ClutterSettings = Clutter.Settings.get_default();
@@ -598,19 +599,19 @@ class GenericMonitorDBUS {
_checkParameters(parameters) { _checkParameters(parameters) {
if (!parameters.hasOwnProperty('group')) { if (!parameters.hasOwnProperty('group')) {
log('No group defined'); this.logger.error('No group defined');
return false; return false;
} }
if (!parameters.hasOwnProperty('items')) { if (!parameters.hasOwnProperty('items')) {
log('No items defined'); this.logger.error('No items defined');
return false; return false;
} }
for (let itemIndex in parameters['items']) { for (let itemIndex in parameters['items']) {
const item = parameters['items'][itemIndex]; const item = parameters['items'][itemIndex];
if (!item.hasOwnProperty('name')) { if (!item.hasOwnProperty('name')) {
log('No name defined for item'); this.logger.error('No name defined for item');
return false; return false;
} }
} }
@@ -631,7 +632,7 @@ class GenericMonitorDBUS {
_getItemFromFullName(fullname) { _getItemFromFullName(fullname) {
const splitName = fullname.split('@'); const splitName = fullname.split('@');
if (splitName.length !== 2) { if (splitName.length !== 2) {
log(`Invalid name ${fullname}`); this.logger.error(`Invalid name ${fullname}`);
return null; return null;
} }
if (!this.monitor_groups.hasOwnProperty(splitName[1])) if (!this.monitor_groups.hasOwnProperty(splitName[1]))
@@ -686,7 +687,7 @@ class GenericMonitorDBUS {
if (position >= childrens.length) if (position >= childrens.length)
position = -1; position = -1;
} }
monitorWidget = new MonitorWidget(item, groupName, this, position); monitorWidget = new MonitorWidget(item, groupName, this, this.logger, position);
group.push(monitorWidget); group.push(monitorWidget);
} else { } else {
monitorWidget.update(item); monitorWidget.update(item);
@@ -708,7 +709,7 @@ class GenericMonitorDBUS {
const parameters = JSON.parse(str); const parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('items')) { if (!parameters.hasOwnProperty('items')) {
log('No items defined'); this.logger.error('No items defined');
return false; return false;
} }
@@ -716,7 +717,7 @@ class GenericMonitorDBUS {
let itemName = parameters['items'][itemIndex]; let itemName = parameters['items'][itemIndex];
const splitName = itemName.split('@'); const splitName = itemName.split('@');
if (splitName.length !== 2) { if (splitName.length !== 2) {
log(`Invalid name ${itemName}`); this.logger.error(`Invalid name ${itemName}`);
return false; return false;
} }
itemName = splitName[0]; itemName = splitName[0];
@@ -735,7 +736,7 @@ class GenericMonitorDBUS {
const parameters = JSON.parse(str); const parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('groups')) { if (!parameters.hasOwnProperty('groups')) {
log('No groups defined'); this.logger.error('No groups defined');
return false; return false;
} }
@@ -759,7 +760,7 @@ class GenericMonitorDBUS {
const parameters = JSON.parse(str); const parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('item')) { if (!parameters.hasOwnProperty('item')) {
log('No item defined'); this.logger.error('No item defined');
return false; return false;
} }
@@ -767,7 +768,7 @@ class GenericMonitorDBUS {
if (monitorWidget !== null) if (monitorWidget !== null)
return monitorWidget; return monitorWidget;
else else
log(`Item ${str} not found`); this.logger.error(`Item ${str} not found`);
return null; return null;
} }

View File

@@ -2,11 +2,9 @@
"uuid": "generic-monitor@gnome-shell-extensions", "uuid": "generic-monitor@gnome-shell-extensions",
"name": "Generic Monitor", "name": "Generic Monitor",
"description": "Display text & icon on systray using DBUS", "description": "Display text & icon on systray using DBUS",
"version": "15", "version": "16",
"shell-version": [ "shell-version": [
"47", "48"
"46",
"45"
], ],
"url": "https://forge.soutade.fr/soutade/GnomeShellGenericMonitor" "url": "https://forge.soutade.fr/soutade/GnomeShellGenericMonitor"
} }