repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

redesign nuguland brightness popup

1c5bb1ffa252477713c582bb08e668822598d8e6

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

+593 / −10 text lines

Diff layout

docs/super/plans/2026-07-08-nuguland-brightness-popup.md

Added
new file mode 100644

+134 / −0 text lines

1# Nuguland Brightness Popup Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use /skill:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** Implement the accepted Nuguland brightness popup with real display rows, DDC setup CTA, and mixed-state global control.
6
7**Architecture:** Keep native/sysfs/pkexec work in `Brightness.qml`; put row/global shaping in `brightness.js`; keep `BrightnessPanel.qml` as visual QML. Pass `Niri` into `Brightness.qml` so external monitors come from live output state instead of fake data.
8
9**Tech Stack:** QML/QtQuick, Quickshell, Node `assert` tests.
11**Roadmap:** None
13**Phase:** Single-plan implementation
15---
17### Task 1: Pure display shaping
19**Files:**
21- Modify: `quickshell/nuguland/brightness.test.js`
22- Modify: `quickshell/nuguland/brightness.js`
24- [x] **Step 1: Add failing tests for display rows and global state**
26Add tests that require:
28- no fake built-in row when no backlight exists;
29- external outputs become `DDC?` issue rows when ddc is unresolved;
30- built-in backlight row appears when present;
31- global state is `none`, `synced`, or `mixed` from controllable display levels.
33- [x] **Step 2: Run test to verify it fails**
35Run:
37```sh
38cd quickshell/nuguland && node brightness.test.js
39```
41Expected: FAIL because new shaping functions do not exist.
43- [x] **Step 3: Implement shaping helpers**
45Add small pure helpers to `brightness.js` and export them.
47- [x] **Step 4: Run test to verify it passes**
49Run:
51```sh
52cd quickshell/nuguland && node brightness.test.js
53```
55Expected: `brightness.test.js: ALL PASS`.
57### Task 2: Native brightness state and setup action
59**Files:**
61- Modify: `quickshell/nuguland/Brightness.qml`
62- Modify: `quickshell/nuguland/shell.qml`
64- [x] **Step 1: Add Niri dependency**
66Add `property Niri niriService` to `Brightness.qml` and pass `niriService: niri` from `shell.qml`.
68- [x] **Step 2: Shape state with real rows**
70Make `Brightness.qml stateObject()` include:
72- `displays`: shaped rows from current backlight and `niriService.outputList()`;
73- `global`: shaped global state;
74- `setup`: whether DDC setup is available/needed.
76- [x] **Step 3: Add `setupDdc()` action**
78Expose a method that launches a fixed `pkexec` command for Arch hosts using `pacman`, `modprobe i2c-dev`, and `udevadm trigger`.
80### Task 3: Visual panel redesign
82**Files:**
84- Modify: `quickshell/nuguland/BrightnessPanel.qml`
86- [x] **Step 1: Replace popup UI with accepted layout**
88Render:
90- setup button only when setup is needed;
91- no fake global control when no controllable display exists;
92- merged multislider when global state is mixed;
93- normal bar when synced;
94- presets only with controllable displays;
95- per-display rows with issue badges only when needed.
97- [x] **Step 2: Wire interactions**
99Global control and presets call `setAll(level)`. Per-display rows call `setDisplay(id, level)`.
101### Task 4: Verification and commit
103**Files:**
105- Verify: `quickshell/nuguland/brightness.test.js`
106- Verify: `quickshell/nuguland/BrightnessPanel.qml`
108- [x] **Step 1: Format**
110Run:
112```sh
113cd quickshell/nuguland && just fmt
114```
116- [x] **Step 2: Run tests**
118Run:
120```sh
121cd quickshell/nuguland && node brightness.test.js
122```
124- [x] **Step 3: Run lint**
126Run:
128```sh
129cd quickshell/nuguland && just lint
130```
132- [x] **Step 4: Commit focused changes**
134Commit only brightness redesign files and this plan, not unrelated dirty `PopoutHost.qml`.

quickshell/nuguland/Brightness.qml

Modified

+67 / −8 text lines

77 id: root
99 property Osd osdService
10 property Niri niriService
1011 property string devicePath: "/sys/class/backlight/intel_backlight"
12 property var ddcDisplays: ({})
1113 property var lastAction: ({})
1214 property var lastOsd: ({})
1315 // Optimistic session level. The sysfs write is async (execDetached) and the
2123 return isFinite(n) ? n : fallback;
2224 }
26 function backlightPresent() {
27 return String(maxFile.text() || "").trim().length > 0 && String(brightnessFile.text() || "").trim().length > 0;
28 }
2430 function nativeMax() {
2531 return Math.max(1, intText(maxFile.text(), 1));
2632 }
3036 }
3238 function levelFraction() {
39 if (!backlightPresent())
40 return 0;
3342 if (liveLevel >= 0)
3443 return Brightness.clampLevel(liveLevel);
3645 return Brightness.clampLevel(nativeBrightness() / nativeMax());
3746 }
48 function outputRows() {
49 return niriService ? niriService.outputList() : [];
50 }
3952 function osd(value) {
4053 const text = String(Brightness.levelPercent(value));
4154 if (!osdService)
5770 function stateObject() {
5871 const level = Math.round(levelFraction() * 100) / 100;
72 const displays = Brightness.displayRows({
73 "present": backlightPresent(),
74 "level": level
75 }, outputRows(), ddcDisplays);
76 const global = Brightness.globalState(displays);
77 const setupNeeded = displays.some(row => row.kind === "ddc" && !row.controllable);
5978 return {
60 "level": level,
79 "level": global.level,
80 "displays": displays,
81 "global": global,
82 "setup": {
83 "needed": setupNeeded,
84 "available": true
85 },
6186 "compact": {
62 "label": "Bright",
63 "role": Brightness.levelRole(level)
87 "label": "brightness",
88 "role": Brightness.levelRole(global.level)
6489 },
6590 "lastAction": lastAction,
6691 "lastOsd": lastOsd
94119 }
96121 function applyNative(level) {
122 if (!backlightPresent())
123 return;
97125 const value = Brightness.clampLevel(level);
98126 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"`]);
99127 }
101 function setLevel(level) {
102 const value = Brightness.clampLevel(level);
103 applyNative(value);
104 liveLevel = value;
129 function setupDdc() {
105130 lastAction = {
106 "kind": "set-level",
131 "kind": "setup-ddc"
132 };
133 Quickshell.execDetached(["pkexec", "sh", "-c", "pacman -S --needed --noconfirm ddcutil && modprobe i2c-dev && udevadm trigger --subsystem-match=i2c-dev"]);
134 return stateJson();
135 }
137 function setDisplay(id, level) {
138 const value = Brightness.clampLevel(level);
139 if (String(id) === "backlight") {
140 applyNative(value);
141 liveLevel = value;
142 }
143 lastAction = {
144 "kind": "set-display",
145 "id": String(id),
107146 "level": Math.round(value * 100) / 100
108147 };
109148 lastOsd = osd(value);
110149 return stateJson();
111150 }
152 function setAll(level) {
153 const value = Brightness.clampLevel(level);
154 const rows = stateObject().displays || [];
155 for (let i = 0; i < rows.length; i++) {
156 if (rows[i].controllable)
157 setDisplay(rows[i].id, value);
158 }
159 lastAction = {
160 "kind": "set-all",
161 "level": Math.round(value * 100) / 100
162 };
163 lastOsd = osd(value);
164 return stateJson();
165 }
167 function setLevel(level) {
168 const value = Brightness.clampLevel(level);
169 return setAll(value);
170 }
113172 function increase() {
114173 return setLevel(levelFraction() + 0.05);
115174 }

quickshell/nuguland/BrightnessPanel.qml

Added
new file mode 100644

+297 / −0 text lines

1pragma ComponentBehavior: Bound
2import QtQuick
3import "Util.js" as Util
4
5Column {
6 id: root
7
8 required property Theme theme
9 required property Brightness brightnessService
10 property var panelState: brightnessService ? Util.parseJson(brightnessService.stateJson(), {
11 "displays": [],
12 "global": {
13 "mode": "none",
14 "level": 0,
15 "levels": []
16 },
17 "setup": {
18 "needed": false,
19 "available": false
20 }
21 }) : ({
22 "displays": [],
23 "global": {
24 "mode": "none",
25 "level": 0,
26 "levels": []
27 },
28 "setup": {
29 "needed": false,
30 "available": false
31 }
32 })
33 readonly property var displays: panelState.displays || []
34 readonly property var global: panelState.global || ({
35 "mode": "none",
36 "level": 0,
37 "levels": []
38 })
39 readonly property var setup: panelState.setup || ({
40 "needed": false,
41 "available": false
42 })
43 readonly property bool hasGlobal: global.mode !== "none"
45 function refreshFrom(text) {
46 panelState = Util.parseJson(text, panelState);
47 }
49 function setAllAt(x, width) {
50 if (brightnessService && root.hasGlobal)
51 refreshFrom(brightnessService.setAll(Math.max(0, Math.min(1, x / width))));
52 }
54 function setDisplayAt(id, x, width) {
55 if (brightnessService)
56 refreshFrom(brightnessService.setDisplay(id, Math.max(0, Math.min(1, x / width))));
57 }
59 width: parent ? parent.width : 0
60 spacing: 12
62 Row {
63 width: parent.width
64 height: root.setup.needed ? 34 : 0
65 visible: root.setup.needed
67 Item {
68 width: Math.max(1, parent.width - setupButton.width)
69 height: 1
70 }
72 Rectangle {
73 id: setupButton
75 width: 112
76 height: 34
77 radius: 12
78 color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, setupArea.containsMouse ? 0.34 : 0.24) : "transparent"
79 border.width: 1
80 border.color: root.theme ? root.theme.ui.accent : "white"
82 NuguText {
83 anchors.centerIn: parent
84 theme: root.theme
85 variant: "meta"
86 text: "setup ddc"
87 color: root.theme ? root.theme.content.normal : "white"
88 }
90 MouseArea {
91 id: setupArea
93 anchors.fill: parent
94 hoverEnabled: true
95 cursorShape: Qt.PointingHandCursor
96 onClicked: if (root.brightnessService)
97 root.refreshFrom(root.brightnessService.setupDdc())
98 }
99 }
100 }
102 Rectangle {
103 id: globalTrack
105 width: parent.width
106 height: root.hasGlobal ? 64 : 0
107 visible: root.hasGlobal
108 radius: 16
109 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.12) : "transparent"
110 border.width: 1
111 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.42) : "white"
112 clip: true
114 Repeater {
115 model: root.global.mode === "mixed" ? root.global.levels : [root.global.level]
117 delegate: Rectangle {
118 id: globalLine
120 required property int index
121 required property real modelData
122 readonly property int lineCount: root.global.mode === "mixed" ? Math.max(1, root.global.levels.length) : 1
124 x: 0
125 y: Math.round(index * globalTrack.height / lineCount)
126 width: globalTrack.width
127 height: Math.ceil(globalTrack.height / lineCount)
128 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.18) : "transparent"
130 Rectangle {
131 width: Math.round(parent.width * Math.max(0, Math.min(1, globalLine.modelData)))
132 height: parent.height
133 color: root.theme ? root.theme.ui.accent : "white"
134 }
135 }
136 }
138 MouseArea {
139 anchors.fill: parent
140 hoverEnabled: true
141 cursorShape: Qt.PointingHandCursor
142 onPressed: mouse => root.setAllAt(mouse.x, width)
143 onPositionChanged: mouse => {
144 if (pressed)
145 root.setAllAt(mouse.x, width);
146 }
147 }
148 }
150 Grid {
151 id: presetGrid
153 width: parent.width
154 height: root.hasGlobal ? 36 : 0
155 visible: root.hasGlobal
156 columns: 4
157 columnSpacing: 8
159 Repeater {
160 model: [0.25, 0.5, 0.75, 1]
162 delegate: Rectangle {
163 id: preset
165 required property real modelData
167 width: Math.floor((presetGrid.width - presetGrid.columnSpacing * (presetGrid.columns - 1)) / presetGrid.columns)
168 height: 36
169 radius: 12
170 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, presetArea.containsMouse ? 0.18 : 0.11) : "transparent"
171 border.width: 1
172 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.4) : "white"
174 NuguText {
175 anchors.centerIn: parent
176 theme: root.theme
177 variant: "meta"
178 text: `${Math.round(preset.modelData * 100)}%`
179 color: root.theme ? root.theme.content.normal : "white"
180 }
182 MouseArea {
183 id: presetArea
185 anchors.fill: parent
186 hoverEnabled: true
187 cursorShape: Qt.PointingHandCursor
188 onClicked: if (root.brightnessService)
189 root.refreshFrom(root.brightnessService.setAll(preset.modelData))
190 }
191 }
192 }
193 }
195 Column {
196 width: parent.width
197 spacing: 8
199 Repeater {
200 model: root.displays
202 delegate: Rectangle {
203 id: displayRow
205 required property var modelData
206 readonly property bool controllable: !!modelData.controllable
207 readonly property string issue: String(modelData.issue || "")
208 readonly property real level: Math.max(0, Math.min(1, Number(modelData.level || 0)))
210 width: root.width
211 height: 38
212 radius: 12
213 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, controllable ? 0.1 : 0.07) : "transparent"
214 border.width: 1
215 border.color: root.theme ? root.theme.withAlpha(issue.length > 0 ? root.theme.warning : root.theme.ui.minor, issue.length > 0 ? 0.48 : 0.32) : "white"
216 opacity: controllable ? 1 : 0.74
218 NuguText {
219 id: displayName
221 anchors.left: parent.left
222 anchors.leftMargin: 10
223 anchors.verticalCenter: parent.verticalCenter
224 width: 128
225 theme: root.theme
226 text: String(displayRow.modelData.name || "display")
227 color: root.theme ? root.theme.content.normal : "white"
228 elide: Text.ElideRight
229 }
231 Rectangle {
232 id: displaySlider
234 anchors.left: displayName.right
235 anchors.leftMargin: 10
236 anchors.right: displayPercent.left
237 anchors.rightMargin: 10
238 anchors.verticalCenter: parent.verticalCenter
239 height: 18
240 radius: 9
241 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.16) : "transparent"
242 border.width: 1
243 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.32) : "white"
244 clip: true
246 Rectangle {
247 width: Math.round(parent.width * displayRow.level)
248 height: parent.height
249 radius: parent.radius
250 color: root.theme ? (displayRow.controllable ? root.theme.ui.accent : root.theme.ui.minor) : "white"
251 }
253 MouseArea {
254 anchors.fill: parent
255 enabled: displayRow.controllable
256 hoverEnabled: true
257 cursorShape: Qt.PointingHandCursor
258 onPressed: mouse => root.setDisplayAt(String(displayRow.modelData.id || ""), mouse.x, width)
259 onPositionChanged: mouse => {
260 if (pressed)
261 root.setDisplayAt(String(displayRow.modelData.id || ""), mouse.x, width);
262 }
263 }
264 }
266 NuguText {
267 id: displayPercent
269 anchors.right: issueBadge.visible ? issueBadge.left : parent.right
270 anchors.rightMargin: issueBadge.visible ? 10 : 10
271 anchors.verticalCenter: parent.verticalCenter
272 width: 44
273 theme: root.theme
274 variant: "meta"
275 text: displayRow.controllable ? `${Math.round(displayRow.level * 100)}%` : "—"
276 color: root.theme ? root.theme.content.normal : "white"
277 horizontalAlignment: Text.AlignRight
278 }
280 NuguText {
281 id: issueBadge
283 visible: displayRow.issue.length > 0
284 anchors.right: parent.right
285 anchors.rightMargin: 10
286 anchors.verticalCenter: parent.verticalCenter
287 width: 70
288 theme: root.theme
289 variant: "meta"
290 text: displayRow.issue.toLowerCase()
291 color: root.theme ? root.theme.warning : "white"
292 horizontalAlignment: Text.AlignRight
293 }
294 }
295 }
296 }
297}

quickshell/nuguland/SurfaceManager.qml

Modified

+1 / −1 text lines

129129 case "brightness":
130130 return {
131131 "width": width,
132 "height": heightBudget(260)
132 "height": heightBudget(340)
133133 };
134134 case "connectivity":
135135 return {

quickshell/nuguland/brightness.js

Modified

+67 / −1 text lines

2222 return "ui.accent";
25function outputArray(outputs) {
26 if (Array.isArray(outputs)) return outputs;
27 var obj = outputs || {};
28 return Object.keys(obj).map(function (name) {
29 var row = obj[name] || {};
30 var copy = {};
31 Object.keys(row).forEach(function (key) { copy[key] = row[key]; });
32 copy.name = copy.name || name;
33 return copy;
34 });
35}
37function displayName(output) {
38 var name = String(output.name || "display");
39 var model = String(output.model || "");
40 return model.length > 0 && model !== "Unknown" ? name + " · " + model : name;
41}
43function displayRows(backlight, outputs, ddc) {
44 var rows = [];
45 var b = backlight || {};
46 if (b.present) {
47 rows.push({
48 id: "backlight",
49 name: "built-in",
50 kind: "backlight",
51 level: clampLevel(b.level),
52 controllable: true,
53 issue: ""
54 });
55 }
57 var ddcMap = ddc || {};
58 outputArray(outputs).forEach(function (output) {
59 var key = String(output.name || "");
60 if (key.length === 0) return;
61 var state = ddcMap[key] || {};
62 var ok = !!state.controllable;
63 rows.push({
64 id: "ddc:" + key,
65 name: displayName(output),
66 kind: "ddc",
67 level: ok ? clampLevel(state.level) : 0,
68 controllable: ok,
69 issue: ok ? "" : "DDC?"
70 });
71 });
72 return rows;
73}
75function globalState(rows) {
76 var levels = (rows || []).filter(function (row) {
77 return !!row.controllable;
78 }).map(function (row) {
79 return Math.round(clampLevel(row.level) * 100) / 100;
80 });
81 if (levels.length === 0) return { mode: "none", level: 0, levels: [] };
83 var first = levels[0];
84 var mixed = levels.some(function (level) { return level !== first; });
85 if (!mixed) return { mode: "synced", level: first, levels: levels };
87 var sum = levels.reduce(function (a, b) { return a + b; }, 0);
88 return { mode: "mixed", level: Math.round(sum / levels.length * 100) / 100, levels: levels };
89}
2591if (typeof module !== 'undefined' && module.exports) {
2692 module.exports = { clampLevel: clampLevel, levelPercent: levelPercent,
27 levelRole: levelRole };
93 levelRole: levelRole, displayRows: displayRows, globalState: globalState };

quickshell/nuguland/brightness.test.js

Modified

+26 / −0 text lines

2727assert.strictEqual(B.levelRole(1), "warning");
2828assert.strictEqual(B.levelRole(null), "ui.minor"); // 0 -> dim
30// displayRows: no fake built-in; unresolved external outputs get issue badges
31assert.deepStrictEqual(B.displayRows({ present: false, level: 0.55 }, {
32 "DP-1": { model: "27E6QC" },
33 "DP-2": { model: "27E6QC" }
34}, {}), [
35 { id: "ddc:DP-1", name: "DP-1 · 27E6QC", kind: "ddc", level: 0, controllable: false, issue: "DDC?" },
36 { id: "ddc:DP-2", name: "DP-2 · 27E6QC", kind: "ddc", level: 0, controllable: false, issue: "DDC?" }
37]);
39assert.deepStrictEqual(B.displayRows({ present: true, level: 0.55 }, {}, {}), [
40 { id: "backlight", name: "built-in", kind: "backlight", level: 0.55, controllable: true, issue: "" }
41]);
43assert.deepStrictEqual(B.displayRows({ present: true, level: 0.75 }, [
44 { name: "DP-1", model: "27E6QC" }
45], { "DP-1": { level: 0.25, controllable: true } }), [
46 { id: "backlight", name: "built-in", kind: "backlight", level: 0.75, controllable: true, issue: "" },
47 { id: "ddc:DP-1", name: "DP-1 · 27E6QC", kind: "ddc", level: 0.25, controllable: true, issue: "" }
48]);
50// globalState: none/synced/mixed from controllable displays only
51assert.deepStrictEqual(B.globalState([]), { mode: "none", level: 0, levels: [] });
52assert.deepStrictEqual(B.globalState([{ controllable: false, level: 0.2 }]), { mode: "none", level: 0, levels: [] });
53assert.deepStrictEqual(B.globalState([{ controllable: true, level: 0.5 }, { controllable: true, level: 0.5 }]), { mode: "synced", level: 0.5, levels: [0.5, 0.5] });
54assert.deepStrictEqual(B.globalState([{ controllable: true, level: 0.75 }, { controllable: true, level: 0.25 }]), { mode: "mixed", level: 0.5, levels: [0.75, 0.25] });
3056console.log('brightness.test.js: ALL PASS');

quickshell/nuguland/shell.qml

Modified

+1 / −0 text lines

112112 id: brightness
114114 osdService: osd
115 niriService: niri
115116 }
117118 Idle {