Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
02d3e8b72a | |||
78254a550e | |||
7a5f506c23 | |||
1d3328f71e | |||
45d0cc9d11 | |||
4d6fe82790 | |||
9943a9075f |
75
extension.js
75
extension.js
@@ -31,7 +31,6 @@
|
||||
|
||||
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;
|
||||
@@ -63,7 +62,9 @@ class SignalMgt {
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.menu = menu;
|
||||
this.signals = {}
|
||||
this.signals = new WeakMap();
|
||||
this.widgets = new Array();
|
||||
this.timeouts = new Array();
|
||||
|
||||
this.nbClicks = 0;
|
||||
this.button = -1;
|
||||
@@ -78,8 +79,10 @@ class SignalMgt {
|
||||
}
|
||||
|
||||
destructor() {
|
||||
for(let widgetIdx in this.signals)
|
||||
this.disconnectWidgetSignals(this.signals[widgetIdx]);
|
||||
for(let widgetIdx in this.widgets)
|
||||
this.disconnectWidgetSignals(this.widgets[widgetIdx]);
|
||||
for(let timeoutIdx in this.timeouts)
|
||||
GLib.Source.remove(this.timeouts[timeoutIdx]);
|
||||
}
|
||||
|
||||
updateSignals(item) {
|
||||
@@ -93,23 +96,26 @@ class SignalMgt {
|
||||
}
|
||||
|
||||
connectWidgetSignals(widget) {
|
||||
this.signals[widget] = [];
|
||||
this.widgets.push(widget);
|
||||
let array = new Array();
|
||||
this.signals.set(widget, array);
|
||||
let id;
|
||||
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));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
||||
this.signals[widget].push(id);
|
||||
array.push(id);
|
||||
widget.set_reactive(true);
|
||||
id = widget.connect('button-release-event', Lang.bind(this, this._clicked));
|
||||
this.signals[widget].push(id);
|
||||
id = widget.connect('button-release-event', this._clicked.bind(this));
|
||||
array.push(id);
|
||||
}
|
||||
|
||||
disconnectWidgetSignals(widget) {
|
||||
for(let idx in this.signals[widget])
|
||||
widget.disconnect(this.signals[widget][idx]);
|
||||
this.signals[widget] = null;
|
||||
let array = this.signals.get(widget);
|
||||
for(let idx in array)
|
||||
widget.disconnect(array[idx]);
|
||||
this.signals.set(widget, null);
|
||||
}
|
||||
|
||||
_manageEventAction(action, signalName) {
|
||||
@@ -165,8 +171,9 @@ class SignalMgt {
|
||||
this.button = event.get_button();
|
||||
this.nbClicks = 1;
|
||||
|
||||
Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
||||
Lang.bind(this, this._doClickCallback));
|
||||
let sourceId = Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
||||
this._doClickCallback.bind(this));
|
||||
this.timeouts.push(sourceId);
|
||||
}
|
||||
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
@@ -222,8 +229,9 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
this.group = group;
|
||||
this.fullname = this.name + '@' + this.group;
|
||||
this.dbus = dbus;
|
||||
this.signals = new SignalMgt(item, this.name, group, dbus, this.menu);
|
||||
this.popup_signals = {};
|
||||
this.signalManager = new SignalMgt(item, this.name, group, dbus, this.menu);
|
||||
this.popup_signals = null;
|
||||
this.popup_widgets = null;
|
||||
|
||||
if (item.hasOwnProperty('icon'))
|
||||
{
|
||||
@@ -232,7 +240,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
else
|
||||
this.icon = this._createIcon(item['icon']);
|
||||
if (this.icon !== null) {
|
||||
this.signals.connectWidgetSignals(this.icon);
|
||||
this.signalManager.connectWidgetSignals(this.icon);
|
||||
this.add_child(this.icon);
|
||||
}
|
||||
} else
|
||||
@@ -246,7 +254,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
this.widget = this._createText(item['text']);
|
||||
|
||||
if (this.widget !== null) {
|
||||
this.signals.connectWidgetSignals(this.widget);
|
||||
this.signalManager.connectWidgetSignals(this.widget);
|
||||
this.add_child(this.widget);
|
||||
}
|
||||
} else
|
||||
@@ -320,7 +328,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
if (prevIcon) {
|
||||
this.signals.disconnectWidgetSignals(prevIcon);
|
||||
this.signalManager.disconnectWidgetSignals(prevIcon);
|
||||
this.insert_child_above(this.icon, prevIcon);
|
||||
this.remove_child(prevIcon);
|
||||
//delete prevIcon;
|
||||
@@ -338,8 +346,8 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
if (this.menuItem) {
|
||||
if (menuOpen)
|
||||
this.menu.close();
|
||||
for(let widgetIdx in this.popup_signals)
|
||||
this.signals.disconnectWidgetSignals(this.popup_signals[widgetIdx]);
|
||||
for(let widgetIdx in this.popup_widgets)
|
||||
this.signalManager.disconnectWidgetSignals(this.popup_widgets[widgetIdx]);
|
||||
this.menu.removeAll();
|
||||
//delete this.menuItem;
|
||||
}
|
||||
@@ -349,7 +357,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
this.menu.open(true);
|
||||
}
|
||||
|
||||
this.signals.updateSignals(item);
|
||||
this.signalManager.updateSignals(item);
|
||||
}
|
||||
|
||||
openPopup() {
|
||||
@@ -381,6 +389,8 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
let widgets = [];
|
||||
this.popup_signals = new WeakMap();
|
||||
this.popup_widgets = new Array();
|
||||
for (let itemIndex in item['items']) {
|
||||
let widget = null;
|
||||
let widgetDict = item['items'][itemIndex];
|
||||
@@ -388,7 +398,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
let nestedItem = null;
|
||||
if (widgetDict.hasOwnProperty('text')) {
|
||||
nestedItem = widgetDict['text'];
|
||||
widget = this._createText(nestedItem);
|
||||
widget = this._createLabel(nestedItem);
|
||||
} else if (widgetDict.hasOwnProperty('picture')) {
|
||||
nestedItem = widgetDict['picture'];
|
||||
widget = this._createPicture(nestedItem);
|
||||
@@ -406,6 +416,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
this.fullname, this.dbus,
|
||||
this.menu);
|
||||
this.popup_signals[widget].connectWidgetSignals(widget);
|
||||
this.popup_widgets.push(widget);
|
||||
}
|
||||
|
||||
if (widgets.length > 0) {
|
||||
@@ -426,7 +437,7 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
return this._createText(itemValues);
|
||||
}
|
||||
|
||||
_createText(item) {
|
||||
__createText(item, isLabel) {
|
||||
if (!item.hasOwnProperty('text')) {
|
||||
log('Text must have a \'text\' value');
|
||||
return null;
|
||||
@@ -439,13 +450,25 @@ class MonitorWidget extends PanelMenu.Button {
|
||||
if (item['text'] === '') {
|
||||
return null;
|
||||
} 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);
|
||||
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
|
||||
_createText(item) {
|
||||
return this.__createText(item, false);
|
||||
}
|
||||
|
||||
_createLabel(item) {
|
||||
return this.__createText(item, true);
|
||||
}
|
||||
|
||||
_createIconOld(item) {
|
||||
var itemValues = {};
|
||||
itemValues = { 'path':item['icon'] };
|
||||
|
@@ -2,11 +2,12 @@
|
||||
"uuid": "generic-monitor@gnome-shell-extensions",
|
||||
"name": "Generic Monitor",
|
||||
"description": "Display text & icon on systray using DBUS",
|
||||
"version": "4",
|
||||
"version": "6",
|
||||
"shell-version": [
|
||||
"41",
|
||||
"40",
|
||||
"3.38",
|
||||
"3.36",
|
||||
"3.34"
|
||||
"3.36"
|
||||
],
|
||||
"url": "http://indefero.soutade.fr/p/genericmonitor"
|
||||
}
|
||||
|
Reference in New Issue
Block a user