4 Commits
v4 ... v5

2 changed files with 45 additions and 25 deletions

View File

@@ -63,7 +63,8 @@ class SignalMgt {
this.fullname = this.name + '@' + this.group; this.fullname = this.name + '@' + this.group;
this.dbus = dbus; this.dbus = dbus;
this.menu = menu; this.menu = menu;
this.signals = {} this.signals = new WeakMap();
this.widgets = new Array();
this.nbClicks = 0; this.nbClicks = 0;
this.button = -1; this.button = -1;
@@ -78,8 +79,8 @@ class SignalMgt {
} }
destructor() { destructor() {
for(let widgetIdx in this.signals) for(let widgetIdx in this.widgets)
this.disconnectWidgetSignals(this.signals[widgetIdx]); this.disconnectWidgetSignals(this.widgets[widgetIdx]);
} }
updateSignals(item) { updateSignals(item) {
@@ -93,23 +94,26 @@ class SignalMgt {
} }
connectWidgetSignals(widget) { connectWidgetSignals(widget) {
this.signals[widget] = []; this.widgets.push(widget);
let array = new Array();
this.signals.set(widget, array);
let id; let id;
id = widget.connect('enter-event', this._onEnter.bind(this)); id = widget.connect('enter-event', this._onEnter.bind(this));
this.signals[widget].push(id); array.push(id);
id = widget.connect('leave-event', this._onLeave.bind(this)); id = widget.connect('leave-event', this._onLeave.bind(this));
this.signals[widget].push(id); array.push(id);
id = widget.connect('scroll-event', this._onScroll.bind(this)); id = widget.connect('scroll-event', this._onScroll.bind(this));
this.signals[widget].push(id); array.push(id);
widget.set_reactive(true); widget.set_reactive(true);
id = 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); array.push(id);
} }
disconnectWidgetSignals(widget) { disconnectWidgetSignals(widget) {
for(let idx in this.signals[widget]) let array = this.signals.get(widget);
widget.disconnect(this.signals[widget][idx]); for(let idx in array)
this.signals[widget] = null; widget.disconnect(array[idx]);
this.signals.set(widget, null);
} }
_manageEventAction(action, signalName) { _manageEventAction(action, signalName) {
@@ -222,8 +226,9 @@ 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 = new SignalMgt(item, this.name, group, dbus, this.menu); this.signalManager = new SignalMgt(item, this.name, group, dbus, this.menu);
this.popup_signals = {}; this.popup_signals = null;
this.popup_widgets = null;
if (item.hasOwnProperty('icon')) if (item.hasOwnProperty('icon'))
{ {
@@ -232,7 +237,7 @@ class MonitorWidget extends PanelMenu.Button {
else else
this.icon = this._createIcon(item['icon']); this.icon = this._createIcon(item['icon']);
if (this.icon !== null) { if (this.icon !== null) {
this.signals.connectWidgetSignals(this.icon); this.signalManager.connectWidgetSignals(this.icon);
this.add_child(this.icon); this.add_child(this.icon);
} }
} else } else
@@ -246,7 +251,7 @@ class MonitorWidget extends PanelMenu.Button {
this.widget = this._createText(item['text']); this.widget = this._createText(item['text']);
if (this.widget !== null) { if (this.widget !== null) {
this.signals.connectWidgetSignals(this.widget); this.signalManager.connectWidgetSignals(this.widget);
this.add_child(this.widget); this.add_child(this.widget);
} }
} else } else
@@ -320,7 +325,7 @@ class MonitorWidget extends PanelMenu.Button {
} }
if (prevIcon) { if (prevIcon) {
this.signals.disconnectWidgetSignals(prevIcon); this.signalManager.disconnectWidgetSignals(prevIcon);
this.insert_child_above(this.icon, prevIcon); this.insert_child_above(this.icon, prevIcon);
this.remove_child(prevIcon); this.remove_child(prevIcon);
//delete prevIcon; //delete prevIcon;
@@ -338,8 +343,8 @@ class MonitorWidget extends PanelMenu.Button {
if (this.menuItem) { if (this.menuItem) {
if (menuOpen) if (menuOpen)
this.menu.close(); this.menu.close();
for(let widgetIdx in this.popup_signals) for(let widgetIdx in this.popup_widgets)
this.signals.disconnectWidgetSignals(this.popup_signals[widgetIdx]); this.signalManager.disconnectWidgetSignals(this.popup_widgets[widgetIdx]);
this.menu.removeAll(); this.menu.removeAll();
//delete this.menuItem; //delete this.menuItem;
} }
@@ -349,7 +354,7 @@ class MonitorWidget extends PanelMenu.Button {
this.menu.open(true); this.menu.open(true);
} }
this.signals.updateSignals(item); this.signalManager.updateSignals(item);
} }
openPopup() { openPopup() {
@@ -381,6 +386,8 @@ class MonitorWidget extends PanelMenu.Button {
} }
let widgets = []; let widgets = [];
this.popup_signals = new WeakMap();
this.popup_widgets = new Array();
for (let itemIndex in item['items']) { for (let itemIndex in item['items']) {
let widget = null; let widget = null;
let widgetDict = item['items'][itemIndex]; let widgetDict = item['items'][itemIndex];
@@ -388,7 +395,7 @@ class MonitorWidget extends PanelMenu.Button {
let nestedItem = null; let nestedItem = null;
if (widgetDict.hasOwnProperty('text')) { if (widgetDict.hasOwnProperty('text')) {
nestedItem = widgetDict['text']; nestedItem = widgetDict['text'];
widget = this._createText(nestedItem); widget = this._createLabel(nestedItem);
} else if (widgetDict.hasOwnProperty('picture')) { } else if (widgetDict.hasOwnProperty('picture')) {
nestedItem = widgetDict['picture']; nestedItem = widgetDict['picture'];
widget = this._createPicture(nestedItem); widget = this._createPicture(nestedItem);
@@ -406,6 +413,7 @@ class MonitorWidget extends PanelMenu.Button {
this.fullname, this.dbus, this.fullname, this.dbus,
this.menu); this.menu);
this.popup_signals[widget].connectWidgetSignals(widget); this.popup_signals[widget].connectWidgetSignals(widget);
this.popup_widgets.push(widget);
} }
if (widgets.length > 0) { if (widgets.length > 0) {
@@ -426,7 +434,7 @@ class MonitorWidget extends PanelMenu.Button {
return this._createText(itemValues); return this._createText(itemValues);
} }
_createText(item) { __createText(item, isLabel) {
if (!item.hasOwnProperty('text')) { if (!item.hasOwnProperty('text')) {
log('Text must have a \'text\' value'); log('Text must have a \'text\' value');
return null; return null;
@@ -439,13 +447,25 @@ class MonitorWidget extends PanelMenu.Button {
if (item['text'] === '') { if (item['text'] === '') {
return null; return null;
} else { } else {
const widget = new St.Button({ label: item['text'] }); let widget = null;
if (isLabel)
widget = new St.Label({ text: item['text'] });
else
widget = new St.Button({ label: item['text'] });
widget.set_style(style); widget.set_style(style);
return widget; return widget;
} }
} }
_createText(item) {
return this.__createText(item, false);
}
_createLabel(item) {
return this.__createText(item, true);
}
_createIconOld(item) { _createIconOld(item) {
var itemValues = {}; var itemValues = {};
itemValues = { 'path':item['icon'] }; itemValues = { 'path':item['icon'] };

View File

@@ -2,11 +2,11 @@
"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": "4", "version": "5",
"shell-version": [ "shell-version": [
"40",
"3.38", "3.38",
"3.36", "3.36"
"3.34"
], ],
"url": "http://indefero.soutade.fr/p/genericmonitor" "url": "http://indefero.soutade.fr/p/genericmonitor"
} }