Skip to content

Commit 533aac3

Browse files
committed
Proposed Background Opacity Setting
What I added: 1. A new `desklet-background-color` entry in `settings-schema.json`, using the same `colorchooser` widget type your `font-color` and `static-theme-color` settings already use. That widget's picker has an alpha slider built in, so one control gives you both color *and* transparency - no separate opacity slider needed. Default is `rgba(0,0,0,0)` (fully transparent), so existing users see no change until they pick a color. 2. A `refreshBackground()` method in `desklet.js` that sets `this.content.style = "background-color: " + this.desklet_background_color + ";"` which is same pattern the original code already used for `font-color` in `getTextLabelStyle()`. 3. Wired it to run once at startup and again whenever settings change (`on_setting_changed`), so picking a new color updates in real time. 4. I also gave `show-background` a clearer label ("Show gauge track") and a tooltip, since it's easy to confuse with the new setting. You can see all the changes in [`desklet-background-color.patch`](https://github.com/EvilSupahFly/cpu-load/blob/main/desklet-background-color.patch).
1 parent b4d2217 commit 533aac3

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

cpuload@kimse/files/cpuload@kimse/desklet.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ CpuLoadDesklet.prototype = {
4545
this.settings.bindProperty(Settings.BindingDirection.IN, 'static-theme-color', 'static_theme_color', this.on_setting_changed);
4646
this.settings.bindProperty(Settings.BindingDirection.IN, 'show-background', 'show_background', this.on_setting_changed);
4747
this.settings.bindProperty(Settings.BindingDirection.IN, 'hide-decorations', 'hide_decorations', this.on_setting_changed);
48+
this.settings.bindProperty(Settings.BindingDirection.IN, 'desklet-background-color', 'desklet_background_color', this.on_setting_changed);
4849

4950
// Properties
5051
this.cpus_utilization = [];
@@ -73,6 +74,7 @@ CpuLoadDesklet.prototype = {
7374
// Refresh the desklet window
7475
this.refreshScalingSizes();
7576
this.toggleDecoration();
77+
this.refreshBackground();
7678

7779
// Start the main desklet loop
7880
this.main();
@@ -89,6 +91,17 @@ CpuLoadDesklet.prototype = {
8991
this._updateDecoration();
9092
},
9193

94+
/**
95+
* Apply the user-selected background color/transparency to the
96+
* desklet face. `this.content` is the St.Bin the base Desklet class
97+
* wraps our window in (see setContent() in ui/desklet.js) - styling
98+
* it, rather than this.window, covers the full desklet bounding box
99+
* instead of just the area behind the gauges.
100+
*/
101+
refreshBackground() {
102+
this.content.style = "background-color: " + this.desklet_background_color + ";";
103+
},
104+
92105
/**
93106
* Refresh desklet scaling.
94107
*/
@@ -621,6 +634,9 @@ CpuLoadDesklet.prototype = {
621634
// Update decoration settings
622635
this.toggleDecoration();
623636

637+
// Refresh background color/transparency
638+
this.refreshBackground();
639+
624640
// Refresh scaling sizes
625641
this.refreshScalingSizes();
626642

cpuload@kimse/files/cpuload@kimse/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"description": "Displays CPU load",
44
"name": "CPU Load",
55
"version": "0.8",
6-
"uuid": "cpuload@kimse"
7-
}
6+
"uuid": "cpuload@kimse",
7+
"author": "schorschii"
8+
}

cpuload@kimse/files/cpuload@kimse/settings-schema.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,17 @@
9494
"type": "header",
9595
"description": "Background"
9696
},
97+
"desklet-background-color": {
98+
"type": "colorchooser",
99+
"default": "rgba(0,0,0,0)",
100+
"description": "Desklet background",
101+
"tooltip": "Background color for the whole desklet face. Use the alpha slider in the color picker to set transparency - alpha 0 keeps it fully see-through, matching the old behavior."
102+
},
97103
"show-background": {
98104
"type": "checkbox",
99-
"description": "Show background",
100-
"default": true
105+
"description": "Show gauge track",
106+
"default": true,
107+
"tooltip": "Show a faint ring behind each CPU gauge. This is separate from the desklet background above."
101108
},
102109
"hide-decorations": {
103110
"type": "checkbox",

0 commit comments

Comments
 (0)