Skip to content

Commit 86e2f5d

Browse files
authored
Merge pull request #494 from SuiziM/fix/panel-icon-padding-new
Fix: Panel Icon Padding Issues
2 parents f183191 + 56cf3f0 commit 86e2f5d

File tree

3 files changed

+43
-49
lines changed

3 files changed

+43
-49
lines changed

extension.js

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var VitalsMenuButton = GObject.registerClass({
5151
this._warnings = [];
5252
this._sensorMenuItems = {};
5353
this._hotLabels = {};
54-
this._hotIcons = {};
54+
this._hotItems = {};
5555
this._groups = {};
5656
this._widths = {};
5757
this._numGpus = 1;
@@ -67,7 +67,8 @@ var VitalsMenuButton = GObject.registerClass({
6767
x_align: Clutter.ActorAlign.START,
6868
y_align: Clutter.ActorAlign.CENTER,
6969
reactive: true,
70-
x_expand: true
70+
x_expand: true,
71+
style_class: 'vitals-panel-menu'
7172
});
7273

7374
this._drawMenu();
@@ -219,8 +220,7 @@ var VitalsMenuButton = GObject.registerClass({
219220
// removes sensors that are no longer available
220221
if (!this._sensorMenuItems[sensor]) {
221222
hotSensors.splice(i, 1);
222-
this._removeHotLabel(sensor);
223-
this._removeHotIcon(sensor);
223+
this._removeHotItem(sensor);
224224
}
225225
}
226226

@@ -255,9 +255,16 @@ var VitalsMenuButton = GObject.registerClass({
255255
}
256256

257257
_createHotItem(key, value) {
258-
let icon = this._defaultIcon(key);
259-
this._hotIcons[key] = icon;
260-
this._menuLayout.add_child(icon)
258+
let item = new St.BoxLayout({
259+
style_class: 'vitals-panel-item',
260+
});
261+
this._hotItems[key] = item;
262+
this._menuLayout.add_child(item);
263+
264+
if (!this._settings.get_boolean('hide-icons') || key == '_default_icon_') {
265+
let icon = this._defaultIcon(key);
266+
item.add_child(icon);
267+
}
261268

262269
// don't add a label when no sensors are in the panel
263270
if (key == '_default_icon_') return;
@@ -268,18 +275,15 @@ var VitalsMenuButton = GObject.registerClass({
268275
y_expand: true,
269276
y_align: Clutter.ActorAlign.CENTER
270277
});
271-
272278
// attempt to prevent ellipsizes
273279
label.get_clutter_text().ellipsize = 0;
274-
275280
// keep track of label for removal later
276281
this._hotLabels[key] = label;
277-
278282
// prevent "called on the widget" "which is not in the stage" errors by adding before width below
279-
this._menuLayout.add_child(label);
283+
item.add_child(label);
280284

281285
// support for fixed widths #55, save label (text) width
282-
this._widths[key] = label.width;
286+
this._widths[key] = label.get_clutter_text().width;
283287
}
284288

285289
_showHideSensorsChanged(self, sensor) {
@@ -329,35 +333,23 @@ var VitalsMenuButton = GObject.registerClass({
329333
this._redrawMenu();
330334
}
331335

332-
_removeHotLabel(key) {
333-
if (key in this._hotLabels) {
334-
let label = this._hotLabels[key];
335-
delete this._hotLabels[key];
336-
// make sure set_label is not called on non existent actor
337-
label.destroy();
336+
_removeHotItems(){
337+
for (let key in this._hotItems) {
338+
this._removeHotItem(key);
338339
}
339340
}
340341

341-
_removeHotLabels() {
342-
for (let key in this._hotLabels)
343-
this._removeHotLabel(key);
344-
}
345-
346-
_removeHotIcon(key) {
347-
if (key in this._hotIcons) {
348-
this._hotIcons[key].destroy();
349-
delete this._hotIcons[key];
342+
_removeHotItem(key) {
343+
if (key in this._hotItems) {
344+
this._hotItems[key].destroy();
345+
delete this._hotItems[key];
346+
delete this._hotLabels[key];
347+
delete this._widths[key];
350348
}
351349
}
352350

353-
_removeHotIcons() {
354-
for (let key in this._hotIcons)
355-
this._removeHotIcon(key);
356-
}
357-
358351
_redrawMenu() {
359-
this._removeHotIcons();
360-
this._removeHotLabels();
352+
this._removeHotItems();
361353

362354
for (let key in this._sensorMenuItems) {
363355
if (key.includes('-group')) continue;
@@ -452,8 +444,7 @@ var VitalsMenuButton = GObject.registerClass({
452444
} else {
453445
// remove selected sensor from panel
454446
hotSensors.splice(hotSensors.indexOf(self.key), 1);
455-
this._removeHotLabel(self.key);
456-
this._removeHotIcon(self.key);
447+
this._removeHotItem(self.key);
457448
}
458449

459450
if (hotSensors.length <= 0) {
@@ -465,7 +456,7 @@ var VitalsMenuButton = GObject.registerClass({
465456
if (defIconPos >= 0) {
466457
// remove generic icon from panel when sensors are selected
467458
hotSensors.splice(defIconPos, 1);
468-
this._removeHotIcon('_default_icon_');
459+
this._removeHotItem('_default_icon_');
469460
}
470461
}
471462

@@ -508,7 +499,7 @@ var VitalsMenuButton = GObject.registerClass({
508499
// don't use the default system icon if the type is a gpu; use the universal gpu icon instead
509500
if (type == 'default' || (!(type in this._sensorIcons) && !type.startsWith('gpu'))) {
510501
icon.gicon = Gio.icon_new_for_string(this._sensorIconPath('system'));
511-
} else if (!this._settings.get_boolean('hide-icons')) { // support for hide icons #80
502+
} else { // support for hide icons #80
512503
let iconObj = (split.length == 2)?'icon-' + split[1]:'icon';
513504
icon.gicon = Gio.icon_new_for_string(this._sensorIconPath(type, iconObj));
514505
}

stylesheet.css

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
.vitals-icon { icon-size: 16px; }
22
.vitals-menu-button-container {}
3-
.vitals-panel-icon-temperature { margin: 0 1px 0 8px; padding: 0; }
4-
.vitals-panel-icon-voltage { margin: 0 0 0 8px; padding: 0; }
5-
.vitals-panel-icon-fan { margin: 0 4px 0 8px; padding: 0; }
6-
.vitals-panel-icon-memory { margin: 0 2px 0 8px; padding: 0; }
7-
.vitals-panel-icon-processor { margin: 0 3px 0 8px; padding: 0; }
8-
.vitals-panel-icon-system { margin: 0 3px 0 8px; padding: 0; }
9-
.vitals-panel-icon-network { margin: 0 3px 0 8px; padding: 0; }
10-
.vitals-panel-icon-storage { margin: 0 2px 0 8px; padding: 0; }
11-
.vitals-panel-icon-battery { margin: 0 4px 0 8px; padding: 0; }
12-
.vitals-panel-label { margin: 0 3px 0 0; padding: 0; }
3+
.vitals-panel-item{spacing: 0;}
4+
.vitals-panel-menu{spacing: 11px; padding: 3px; }
5+
.vitals-panel-icon-default {}
6+
.vitals-panel-icon-temperature { margin: 0 1px 0 0; padding: 0; }
7+
.vitals-panel-icon-voltage { margin: 0 0 0 0; padding: 0; }
8+
.vitals-panel-icon-fan { margin: 0 4px 0 0; padding: 0; }
9+
.vitals-panel-icon-memory { margin: 0 2px 0 0; padding: 0; }
10+
.vitals-panel-icon-processor { margin: 0 3px 0 0; padding: 0; }
11+
.vitals-panel-icon-system { margin: 0 3px 0 0; padding: 0; }
12+
.vitals-panel-icon-network { margin: 0 3px 0 0; padding: 0; }
13+
.vitals-panel-icon-storage { margin: 0 2px 0 0; padding: 0; }
14+
.vitals-panel-icon-battery { margin: 0 4px 0 0; padding: 0; }
15+
.vitals-panel-label {}
1316
.vitals-button-action { -st-icon-style: symbolic; border-radius: 32px; margin: 0px; min-height: 22px; min-width: 22px; padding: 10px; font-size: 100%; border: 1px solid transparent; }
1417
.vitals-button-action:hover, .vitals-button-action:focus { border-color: #777; }
1518
.vitals-button-action > StIcon { icon-size: 16px; }

values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export const Values = GObject.registerClass({
200200
ending = 'Wh';
201201
break;
202202
case 'load':
203-
format = (use_higher_precision)?'%.2f %s':'%.1f %s';
203+
format = (use_higher_precision)?'%.2f %s':'%.1f';
204204
break;
205205
case 'pcie':
206206
let split = value.split('x');

0 commit comments

Comments
 (0)