Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 29 additions & 38 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var VitalsMenuButton = GObject.registerClass({
this._warnings = [];
this._sensorMenuItems = {};
this._hotLabels = {};
this._hotIcons = {};
this._hotItems = {};
this._groups = {};
this._widths = {};
this._numGpus = 1;
Expand All @@ -67,7 +67,8 @@ var VitalsMenuButton = GObject.registerClass({
x_align: Clutter.ActorAlign.START,
y_align: Clutter.ActorAlign.CENTER,
reactive: true,
x_expand: true
x_expand: true,
style_class: 'vitals-panel-menu'
});

this._drawMenu();
Expand Down Expand Up @@ -219,8 +220,7 @@ var VitalsMenuButton = GObject.registerClass({
// removes sensors that are no longer available
if (!this._sensorMenuItems[sensor]) {
hotSensors.splice(i, 1);
this._removeHotLabel(sensor);
this._removeHotIcon(sensor);
this._removeHotItem(sensor);
}
}

Expand Down Expand Up @@ -255,9 +255,16 @@ var VitalsMenuButton = GObject.registerClass({
}

_createHotItem(key, value) {
let icon = this._defaultIcon(key);
this._hotIcons[key] = icon;
this._menuLayout.add_child(icon)
let item = new St.BoxLayout({
style_class: 'vitals-panel-item',
});
this._hotItems[key] = item;
this._menuLayout.add_child(item);

if (!this._settings.get_boolean('hide-icons') || key == '_default_icon_') {
let icon = this._defaultIcon(key);
item.add_child(icon);
}

// don't add a label when no sensors are in the panel
if (key == '_default_icon_') return;
Expand All @@ -268,18 +275,15 @@ var VitalsMenuButton = GObject.registerClass({
y_expand: true,
y_align: Clutter.ActorAlign.CENTER
});

// attempt to prevent ellipsizes
label.get_clutter_text().ellipsize = 0;

// keep track of label for removal later
this._hotLabels[key] = label;

// prevent "called on the widget" "which is not in the stage" errors by adding before width below
this._menuLayout.add_child(label);
item.add_child(label);

// support for fixed widths #55, save label (text) width
this._widths[key] = label.width;
this._widths[key] = label.get_clutter_text().width;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Label Width Calculation Timing Issue

Calculating label widths with label.get_clutter_text().width immediately after adding the label to its container might return incorrect or zero values. This can happen before the text is fully rendered or laid out, potentially breaking fixed-width functionality.

Fix in Cursor Fix in Web

}

_showHideSensorsChanged(self, sensor) {
Expand Down Expand Up @@ -329,35 +333,23 @@ var VitalsMenuButton = GObject.registerClass({
this._redrawMenu();
}

_removeHotLabel(key) {
if (key in this._hotLabels) {
let label = this._hotLabels[key];
delete this._hotLabels[key];
// make sure set_label is not called on non existent actor
label.destroy();
_removeHotItems(){
for (let key in this._hotItems) {
this._removeHotItem(key);
}
}

_removeHotLabels() {
for (let key in this._hotLabels)
this._removeHotLabel(key);
}

_removeHotIcon(key) {
if (key in this._hotIcons) {
this._hotIcons[key].destroy();
delete this._hotIcons[key];
_removeHotItem(key) {
if (key in this._hotItems) {
this._hotItems[key].destroy();
delete this._hotItems[key];
delete this._hotLabels[key];
delete this._widths[key];
}
}

_removeHotIcons() {
for (let key in this._hotIcons)
this._removeHotIcon(key);
}

_redrawMenu() {
this._removeHotIcons();
this._removeHotLabels();
this._removeHotItems();

for (let key in this._sensorMenuItems) {
if (key.includes('-group')) continue;
Expand Down Expand Up @@ -452,8 +444,7 @@ var VitalsMenuButton = GObject.registerClass({
} else {
// remove selected sensor from panel
hotSensors.splice(hotSensors.indexOf(self.key), 1);
this._removeHotLabel(self.key);
this._removeHotIcon(self.key);
this._removeHotItem(self.key);
}

if (hotSensors.length <= 0) {
Expand All @@ -465,7 +456,7 @@ var VitalsMenuButton = GObject.registerClass({
if (defIconPos >= 0) {
// remove generic icon from panel when sensors are selected
hotSensors.splice(defIconPos, 1);
this._removeHotIcon('_default_icon_');
this._removeHotItem('_default_icon_');
}
}

Expand Down Expand Up @@ -508,7 +499,7 @@ var VitalsMenuButton = GObject.registerClass({
// don't use the default system icon if the type is a gpu; use the universal gpu icon instead
if (type == 'default' || (!(type in this._sensorIcons) && !type.startsWith('gpu'))) {
icon.gicon = Gio.icon_new_for_string(this._sensorIconPath('system'));
} else if (!this._settings.get_boolean('hide-icons')) { // support for hide icons #80
} else { // support for hide icons #80
let iconObj = (split.length == 2)?'icon-' + split[1]:'icon';
icon.gicon = Gio.icon_new_for_string(this._sensorIconPath(type, iconObj));
}
Expand Down
Binary file added locale/my_MM/LC_MESSAGES/vitals.mo
Binary file not shown.
Loading