dotfiles bugabingas dorkfiles
owned by bugabinga
README Source History Refs Compare Notes Search brightness: thin service delegates to brightness.js, drop narration c570f8a85ee454b8fc117932e637016a17f1f8a8
Oliver Jan Krylow <oliver@bugabinga.net > · 29 Jun 2026
unsigned
Browse files Compare with HEAD
Drop dead stateObject metadata (backend, helperProcesses, serviceOwnedActions,
boundedActions) and the unrendered brightness-gradient shader descriptor. Add
optimistic liveLevel so setLevel/increase/decrease reflect immediately (the
FileView loads once and never reloads). Add selfTest + brightnessSelfTest IPC.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changed files (2) quickshell/nuguland/Brightness.qml Modified 4 + import "brightness.js" as Brightness 12 13 property var lastOsd: ({
14 - readonly property
var boundedActions: [
"increase" ,
"decrease" ,
"set-level" ]
16 - function clamp01 (value) {
17 - const n
= Number (value);
21 - return Math .
max (
0 ,
Math .
min (
1 , n));
19 + property real liveLevel:
- 1 24 21 function intText (text, fallback) {
25 22 const n
= parseInt (
String (text
|| "" ).trim(),
10 );
37 34 function levelFraction () {
38 - return clamp01(nativeBrightness()
/ nativeMax());
36 + return Brightness .clampLevel(liveLevel);
38 + return Brightness .clampLevel(nativeBrightness()
/ nativeMax());
41 41 function osd (value) {
42 - const text
= String (
Math .
round (clamp01(value)
* 100 ));
42 + const text
= String (
Brightness .levelPercent(value));
45 45 "event" :
"brightness" ,
59 59 function stateObject () {
60 60 const level
= Math .
round (levelFraction()
* 100 )
/ 100 ;
62 - "backend" :
"Brightness.qml" ,
63 - "devicePath" : devicePath,
64 - "helperProcesses" : [
"sh" ],
65 - "serviceOwnedActions" :
true ,
66 - "boundedActions" : boundedActions,
70 - "role" : level
<= 0.15 ? "ui.minor" : level
>= 0.85 ? "warning" : "ui.accent" 73 - "kind" :
"brightness-gradient" ,
75 - "source" :
"shaders/brightness-gradient.frag.qsb" ,
76 - "priorArt" :
"GLSL luminance gradients and smoothstep bar masks plus Inigo Quilez-style rounded-box SDF alpha mask" ,
77 - "values" : [level,
1 - level, level
>= 0.85 ? 1 : 0 , level
<= 0.15 ? 1 : 0 ],
78 - "colors" : [
"ui.accent" ,
"ui.focus" ,
"warning" ,
"ui.backdrop" ]
65 + "role" :
Brightness .levelRole(level)
80 67 "lastAction" : lastAction,
86 73 return JSON .stringify(stateObject());
76 + function selfTest () {
78 + const check = (name, got, want)
=> cases.push({
80 + "ok" :
JSON .
stringify (got)
=== JSON .
stringify (want),
84 + check(
"clampLevel(-1)" ,
Brightness .clampLevel(
- 1 ),
0 );
85 + check(
"clampLevel(2)" ,
Brightness .clampLevel(
2 ),
1 );
86 + check(
"levelPercent(0.5)" ,
Brightness .levelPercent(
0.5 ),
50 );
87 + check(
"levelRole(0.15)" ,
Brightness .levelRole(
0.15 ),
"ui.minor" );
88 + check(
"levelRole(0.5)" ,
Brightness .levelRole(
0.5 ),
"ui.accent" );
89 + check(
"levelRole(0.85)" ,
Brightness .levelRole(
0.85 ),
"warning" );
90 + const fail
= cases.filter(c
=> ! c.ok).length;
91 + return JSON .
stringify ({
92 + "pass" : cases.length
- fail,
89 98 function applyNative (level) {
90 - const value
= clamp01(level);
99 + const value
= Brightness .clampLevel(level);
91 100 Quickshell .execDetached([
"sh" ,
"-c" ,
`d=' ${devicePath}
'; m=$(cat "$d/max_brightness"); n=$(awk -v v= ${value}
-v m=$m 'BEGIN { x=int(v*m); if (x<1) x=1; if (x>m) x=m; print x }'); printf '%s\n' "$n" > "$d/brightness"` ]);
94 103 function setLevel (level) {
95 - const value
= clamp01(level);
104 + const value
= Brightness .clampLevel(level);
96 105 applyNative(value);
98 108 "kind" :
"set-level" ,
99 109 "level" :
Math .
round (value
* 100 )
/ 100 quickshell/nuguland/shell.qml Modified 926 926 return brightness.stateJson();
929 + function brightnessSelfTest () : string {
930 + return brightness.selfTest();
929 933 function openBrightness () : string {
930 934 return surfaceManager.openRegisteredPopout(
"brightness" );