paradoxxxzero/gnome-shell-system-monitor-applet — Issue #57: Allow multiple thermal sensors (suggested patch included)
Author: dekadenZ
Created: 2011-10-24 20:04:44+00:00
State: open

It would be nice to have more than one thermal sensor displayed. I fumbled around a little to have at least textual display working. I didn't figure out how to draw the graphs though, and the column structure of the pop-up info page eludes me.

```diff
diff --git a/system-monitor@paradoxxx.zero.gmail.com/extension.js b/system-monitor@paradoxxx.zero.gmail.com/extension.js
index 2fafa12..e792fb3 100644
--- a/system-monitor@paradoxxx.zero.gmail.com/extension.js
+++ b/system-monitor@paradoxxx.zero.gmail.com/extension.js
@@ -717,38 +717,57 @@ var init = function (metadata) {
__proto__: ElementBase.prototype,
elt: 'thermal',
color_name: ['tz0'],
- text_items: [new St.Label({ style_class: "sm-status-value"}),
- new St.Label({ text: 'C', style_class: "sm-unit-label"})],
- menu_items: [new St.Label({ style_class: "sm-void"}),
+ unit: "\u00b0C",
+ _init: function() {
+ this.sensors = Schema.get_string(this.elt + '-sensor-file')
+ .split(":")
+ .map(function(sensor, i) {
+ sensor = sensor.split("=", 2);
+ if (sensor.length === 1) {
+ sensor[1] = sensor[0];
+ sensor[0] = i.toString();
+ }
+ return { key: sensor[0], value: sensor[1] };
+ });
+ this.vals = this.sensors.map(function() { return -273.15; });
+
+ this.text_items = new Array(this.sensors.length * 3);
+ this.sensors.forEach(function(sensor, i) {
+ i *= 3;
+ this.text_items[i+0] = new St.Label({ text: sensor.key, style_class: "sm-status-label"});
+ this.text_items[i+1] = new St.Label({ style_class: "sm-small-status-value"});
+ this.text_items[i+2] = new St.Label({ text: this.unit, style_class: "sm-unit-label"});
+ }, this);
+
+ this.menu_item = new PopupMenu.PopupMenuItem(_("Thermal"), {reactive: false});
+ this.menu_items = [new St.Label({ style_class: "sm-void"}),
new St.Label({ style_class: "sm-void"}),
new St.Label({ style_class: "sm-void"}),
new St.Label({ style_class: "sm-value"}),
new St.Label({ style_class: "sm-void"}),
- new St.Label({ text: 'C', style_class: "sm-label"})],
- _init: function() {
- this.temperature = -273.15;
- this.menu_item = new PopupMenu.PopupMenuItem(_("Thermal"), {reactive: false});
+ new St.Label({ text: this.unit, style_class: "sm-label"})];
+
ElementBase.prototype._init.call(this);
- this.tip_format('C');
+ this.tip_format(this.unit);
Schema.connect('changed::' + this.elt + '-sensor-file', Lang.bind(this, this.refresh));
this.update();
},
refresh: function() {
- let sfile = Schema.get_string(this.elt + '-sensor-file');
- if(GLib.file_test(sfile,1<<4)){
- //global.logError("reading sensor");
- let t_str = Shell.get_file_contents_utf8_sync(sfile).split("\n")[0];
- this.temperature = parseInt(t_str)/1000.0;
- }
- else
- global.logError("error reading: " + sfile);
-
-
-
+ this.sensors.forEach(function(sfile, i) {
+ sfile = sfile.value;
+ if(GLib.file_test(sfile,1<<4)){
+ //global.logError("reading sensor");
+ this[i] = parseInt(Shell.get_file_contents_utf8_sync(sfile))/1000.0;
+ }
+ else
+ global.logError("error reading: " + sfile);
+ }, this.vals);
},
_apply: function() {
- this.text_items[0].text = this.menu_items[3].text = this.temperature.toString();
- this.vals = [this.temperature];
+ this.vals.forEach(function(val, i) {
+ this[i*3+1].text = val.toString();
+ }, this.text_items);
+ this.menu_items[3].text = this.text_items[1].text;
this.tip_vals[0] = Math.round(this.vals[0]);
}
};
diff --git a/system-monitor@paradoxxx.zero.gmail.com/stylesheet.css b/system-monitor@paradoxxx.zero.gmail.com/stylesheet.css
index 96af321..2a3939d 100644
--- a/system-monitor@paradoxxx.zero.gmail.com/stylesheet.css
+++ b/system-monitor@paradoxxx.zero.gmail.com/stylesheet.css
@@ -21,6 +21,11 @@
padding: 0 5px 0 2px;
}

+.sm-small-status-value {
+	padding-left: 0.25em;
+ text-align: right;
+}
+
.sm-status-value {
min-width: 25px;
text-align: right;
```

There's no GUI to specify multiple sensor sources. One needs to configure them manually in org.gnome.shell.extensions.system-monitor.thermal-sensor-file. I. e. I'm using:

```
Core0=/sys/class/hwmon/hwmon0/device/temp2_input:Core1=/sys/class/hwmon/hwmon0/device/temp3_input:CPU=/sys/class/hwmon/hwmon1/device/temp1_input:Case=/sys/class/hwmon/hwmon1/device/temp2_input
```