diff --git a/extension.js b/extension.js index 71b5ded..b467e2d 100644 --- a/extension.js +++ b/extension.js @@ -22,6 +22,7 @@ // 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; @@ -66,11 +67,13 @@ var MonitorWidget = GObject.registerClass({ }, class MonitorWidget extends PanelMenu.Button { - _init(item, group, lastWidget) { + + _init(item, group, position) { super._init(0.0); this.name = item['name']; this.group = group; + this.fullname = this.name + '@' + this.group; if (item.hasOwnProperty('icon')) { @@ -105,8 +108,15 @@ class MonitorWidget extends PanelMenu.Button { this.connect('enter-event', this._onEnter.bind(this)); this.connect('leave-event', this._onLeave.bind(this)); + this.connect('style-changed', this._onStyleChanged.bind(this)); + + Main.panel.addToStatusArea(this.fullname, this, position, box); + } - Main.panel.addToStatusArea(group, this, (lastWidget>0)?lastWidget:-1, box); + _onStyleChanged(actor) { + // Force these values to avoid big spaces between each widgets + this._minHPadding = 1; + this._natHPadding = 1; } _onEnter() { @@ -473,8 +483,22 @@ class GenericMonitorDBUS { // New widget if (monitorWidget === null) { - let lastWidget = group.length - 1; - monitorWidget = new MonitorWidget(item, groupName, lastWidget); + let position = group.length - 1; + // Find real position + if (position != -1) { + let lastWidget = group[position].container; + let childrens = lastWidget.get_parent().get_children(); + for(;position < childrens.length; position++) + { + if (childrens[position] == lastWidget) { + position++; + break; + } + } + if (position >= childrens.length) + position = -1; + } + monitorWidget = new MonitorWidget(item, groupName, position); group.push(monitorWidget); // Connect signals // if (onClick !== '') {