repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

redesign nuguland power popup

61af1f01568a10c4c67145a96cefa6a5e3ac65e8

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

+533 / −0 text lines

Diff layout

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

Added
new file mode 100644

+134 / −0 text lines

1# Nuguland Power 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 two-zone Nuguland power popup from `docs/super/specs/2026-07-08-nuguland-power-popup-design.md`.
6
7**Architecture:** Keep session routing in `Power.qml`/`power.js`; change visual hierarchy in `PowerPanel.qml`. Add one pure `hasMainBattery()` helper so desktops do not render fake `0% unknown` battery heroes.
8
9**Tech Stack:** QML/QtQuick, Quickshell, Node `assert` tests for pure JavaScript shaping.
11**Roadmap:** None
13**Phase:** Single-plan implementation
15---
17### Task 1: Battery presence shaping
19**Files:**
21- Modify: `quickshell/nuguland/power.test.js`
22- Modify: `quickshell/nuguland/power.js`
23- Modify: `quickshell/nuguland/Power.qml`
25- [x] **Step 1: Write the failing test**
27Add assertions to `quickshell/nuguland/power.test.js` before the routing-table section:
29```js
30// --- hasMainBattery --------------------------------------------------------
31eq(P.hasMainBattery({ percent: 0, state: 'unknown', timeEstimate: 'unknown', health: -1 }), false, 'desktop display device placeholder is not a main battery');
32eq(P.hasMainBattery({ percent: 72, state: 'charging', timeEstimate: '1h', health: 91 }), true, 'real laptop battery is a main battery');
33eq(P.hasMainBattery({ percent: 0, state: 'discharging', timeEstimate: 'unknown', health: -1 }), true, 'reported discharging state is a main battery even at zero percent');
34```
36- [x] **Step 2: Run test to verify it fails**
38Run:
40```sh
41cd quickshell/nuguland && node power.test.js
42```
44Expected: FAIL with `TypeError: P.hasMainBattery is not a function`.
46- [x] **Step 3: Implement minimal helper and export**
48Add to `quickshell/nuguland/power.js` near battery helpers:
50```js
51function hasMainBattery(battery) {
52 var b = battery || {};
53 var state = cleanState(b.state);
54 return Number(b.percent || 0) > 0 || state !== 'unknown' || String(b.timeEstimate || 'unknown') !== 'unknown' || Number(b.health || -1) >= 0;
55}
56```
58Export it in `module.exports`.
60- [x] **Step 4: Mark native battery objects**
62In `Power.qml`, set `b.present = Power.hasMainBattery(b);` inside `batteryObject()` before assigning `role`.
64- [x] **Step 5: Run test to verify it passes**
66Run:
68```sh
69cd quickshell/nuguland && node power.test.js
70```
72Expected: `power.test.js: ALL PASS`.
74### Task 2: Two-zone panel layout
76**Files:**
78- Modify: `quickshell/nuguland/PowerPanel.qml`
80- [x] **Step 1: Replace the old equal-weight layout**
82Rewrite `PowerPanel.qml` to keep existing service functions and key behavior, but render:
84- optional circular battery hero when `battery.present` is true;
85- compact external device chips;
86- one safe-action grid with `lock`, `suspend`, `monitor-off`, `monitor-on` filtered from `sessionActions`;
87- one danger region with `logout`, `reboot`, `poweroff` filtered from `sessionActions`;
88- confirmation card replacing the danger action grid while `pendingConfirmation` is set.
90- [x] **Step 2: Run formatter**
92Run:
94```sh
95cd quickshell/nuguland && just fmt
96```
98Expected: command exits 0.
100### Task 3: Verification
102**Files:**
104- Verify: `quickshell/nuguland/power.test.js`
105- Verify: `quickshell/nuguland/PowerPanel.qml`
107- [x] **Step 1: Run pure tests**
109Run:
111```sh
112cd quickshell/nuguland && node power.test.js
113```
115Expected: `power.test.js: ALL PASS`.
117- [x] **Step 2: Run Nuguland lint gate**
119Run:
121```sh
122cd quickshell/nuguland && just lint
123```
125Expected: command exits 0 with no warnings.
127- [x] **Step 3: Commit focused changes**
129Run:
131```sh
132git add docs/super/plans/2026-07-08-nuguland-power-popup.md quickshell/nuguland/power.test.js quickshell/nuguland/power.js quickshell/nuguland/Power.qml quickshell/nuguland/PowerPanel.qml
133git commit -m "redesign nuguland power popup"
134```

quickshell/nuguland/Power.qml

Modified

+1 / −0 text lines

4242 function batteryObject() {
4343 const b = nativeBattery();
44 b.present = Power.hasMainBattery(b);
4445 b.role = Power.batteryRole(b.percent);
4546 return b;
4647 }

quickshell/nuguland/PowerPanel.qml

Added
new file mode 100644

+386 / −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 Power powerService
10 property var panelState: powerService ? Util.parseJson(powerService.stateJson(), {
11 "battery": {},
12 "externalDevices": []
13 }) : ({
14 "battery": {},
15 "externalDevices": []
16 })
17 readonly property var battery: panelState.battery || ({})
18 readonly property var devices: panelState.externalDevices || []
19 readonly property var sessionActions: panelState.sessionActions || ["lock", "suspend", "monitor-off", "monitor-on", "logout", "reboot", "poweroff"]
20 readonly property bool hasMainBattery: !!(battery && battery.present)
21 readonly property var safeActionNames: ["lock", "suspend", "monitor-off", "monitor-on"]
22 readonly property var destructiveActionNames: ["logout", "reboot", "poweroff"]
23 readonly property var safeActions: actionSubset(safeActionNames)
24 readonly property var destructiveActions: actionSubset(destructiveActionNames)
26 function refreshFrom(text) {
27 panelState = Util.parseJson(text, panelState);
28 }
30 function runSession(action) {
31 if (powerService)
32 refreshFrom(powerService.sessionAction(action));
33 }
35 function confirm(action) {
36 if (powerService)
37 refreshFrom(powerService.confirmAction(action));
38 }
40 function cancel() {
41 if (powerService)
42 refreshFrom(powerService.cancelAction());
43 }
45 function roleColor(role) {
46 if (!theme)
47 return "white";
49 if (role === "warning")
50 return theme.warning;
52 if (role === "error")
53 return theme.error;
55 if (role === "ui.minor")
56 return theme.ui.minor;
58 return theme.ui.accent;
59 }
61 function actionSubset(names) {
62 const rows = [];
63 for (let i = 0; i < names.length; i++) {
64 if (sessionActions.indexOf(names[i]) >= 0)
65 rows.push(names[i]);
66 }
67 return rows;
68 }
70 function actionLabel(action) {
71 if (action === "monitor-off")
72 return "display off";
74 if (action === "monitor-on")
75 return "display on";
77 if (action === "poweroff")
78 return "power off";
80 return action;
81 }
83 function batteryMeta() {
84 const parts = [];
85 if (battery.timeEstimate && battery.timeEstimate !== "unknown")
86 parts.push(battery.timeEstimate);
87 if (battery.health >= 0)
88 parts.push(`health ${battery.health}%`);
89 return parts.join(" · ");
90 }
92 spacing: 12
93 width: parent ? parent.width : 0
94 focus: true
95 Keys.onEscapePressed: root.cancel()
96 Keys.onReturnPressed: root.panelState.pendingConfirmation ? root.confirm(root.panelState.pendingConfirmation) : root.runSession("lock")
97 Keys.onEnterPressed: root.panelState.pendingConfirmation ? root.confirm(root.panelState.pendingConfirmation) : root.runSession("lock")
99 Rectangle {
100 objectName: "batteryHero"
101 width: parent.width
102 height: root.hasMainBattery ? 116 : 0
103 radius: 18
104 visible: root.hasMainBattery
105 color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.56) : "transparent"
106 border.width: 1
107 border.color: root.theme ? root.theme.withAlpha(root.roleColor(root.battery.role || "ui.accent"), 0.65) : "transparent"
109 Rectangle {
110 id: batteryDial
112 anchors.left: parent.left
113 anchors.leftMargin: 12
114 anchors.verticalCenter: parent.verticalCenter
115 width: 92
116 height: 92
117 radius: 46
118 color: root.theme ? root.theme.withAlpha(root.roleColor(root.battery.role || "ui.accent"), 0.18) : "transparent"
119 border.width: 1
120 border.color: root.theme ? root.roleColor(root.battery.role || "ui.accent") : "transparent"
122 NuguText {
123 anchors.centerIn: parent
124 theme: root.theme
125 variant: "title"
126 font.pixelSize: 25
127 text: `${root.battery.percent || 0}%`
128 color: root.theme ? root.theme.content.normal : "white"
129 }
130 }
132 Column {
133 anchors.left: batteryDial.right
134 anchors.leftMargin: 14
135 anchors.right: parent.right
136 anchors.rightMargin: 14
137 anchors.verticalCenter: parent.verticalCenter
138 spacing: 8
140 NuguText {
141 theme: root.theme
142 variant: "title"
143 width: parent.width
144 text: root.battery.state || "unknown"
145 color: root.theme ? root.roleColor(root.battery.role || "ui.accent") : "white"
146 elide: Text.ElideRight
147 }
149 NuguText {
150 theme: root.theme
151 variant: "meta"
152 width: parent.width
153 visible: root.batteryMeta().length > 0
154 text: root.batteryMeta()
155 color: root.theme ? root.theme.ui.minor : "white"
156 elide: Text.ElideRight
157 }
158 }
159 }
161 Flow {
162 id: deviceFlow
164 objectName: "externalDeviceBatteryChips"
165 width: parent.width
166 height: visible ? implicitHeight : 0
167 spacing: 8
168 visible: root.devices.length > 0
170 Repeater {
171 model: root.devices
173 delegate: Rectangle {
174 id: deviceChip
176 required property var modelData
178 width: Math.floor((root.width - 8) / 2)
179 height: 32
180 radius: 11
181 color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.55) : "transparent"
182 border.width: 1
183 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.42) : "transparent"
185 NuguText {
186 anchors.left: parent.left
187 anchors.leftMargin: 9
188 anchors.right: devicePercent.left
189 anchors.rightMargin: 8
190 anchors.verticalCenter: parent.verticalCenter
191 theme: root.theme
192 variant: "meta"
193 text: `${deviceChip.modelData.name}`
194 color: root.theme ? root.theme.ui.minor : "white"
195 elide: Text.ElideRight
196 }
198 NuguText {
199 id: devicePercent
201 anchors.right: parent.right
202 anchors.rightMargin: 9
203 anchors.verticalCenter: parent.verticalCenter
204 theme: root.theme
205 variant: "meta"
206 selected: true
207 text: `${deviceChip.modelData.percent}%`
208 }
209 }
210 }
211 }
213 Grid {
214 id: safeGrid
216 objectName: "safeActionGrid"
217 width: parent.width
218 columns: 2
219 columnSpacing: 8
220 rowSpacing: 8
222 Repeater {
223 model: root.safeActions
225 delegate: Rectangle {
226 id: safeButton
228 required property string modelData
229 readonly property bool primary: modelData === "lock"
231 width: Math.floor((root.width - safeGrid.columnSpacing) / safeGrid.columns)
232 height: 42
233 radius: 13
234 color: root.theme ? root.theme.withAlpha(primary ? root.theme.ui.accent : root.theme.ui.backdrop, primary ? 0.26 : 0.56) : "transparent"
235 border.width: primary ? 1 : 0
236 border.color: root.theme ? (primary ? root.theme.ui.accent : "transparent") : "transparent"
238 NuguText {
239 anchors.centerIn: parent
240 theme: root.theme
241 variant: "meta"
242 selected: safeButton.primary
243 text: root.actionLabel(safeButton.modelData)
244 color: root.theme ? (safeButton.primary ? root.theme.ui.accent : root.theme.content.normal) : "white"
245 }
247 MouseArea {
248 anchors.fill: parent
249 hoverEnabled: true
250 cursorShape: Qt.PointingHandCursor
251 onClicked: root.runSession(safeButton.modelData)
252 }
253 }
254 }
255 }
257 Rectangle {
258 objectName: "dangerRegion"
259 width: parent.width
260 height: root.panelState.pendingConfirmation ? 62 : 58
261 radius: 18
262 color: root.theme ? root.theme.withAlpha(root.panelState.pendingConfirmation ? root.theme.warning : root.theme.error, root.panelState.pendingConfirmation ? 0.12 : 0.08) : "transparent"
263 border.width: 1
264 border.color: root.theme ? root.theme.withAlpha(root.panelState.pendingConfirmation ? root.theme.warning : root.theme.error, 0.62) : "transparent"
266 Grid {
267 id: dangerGrid
269 anchors.fill: parent
270 anchors.margins: 10
271 columns: 3
272 columnSpacing: 8
273 visible: !root.panelState.pendingConfirmation
275 Repeater {
276 model: root.destructiveActions
278 delegate: Rectangle {
279 id: dangerButton
281 required property string modelData
283 width: Math.floor((dangerGrid.width - dangerGrid.columnSpacing * 2) / 3)
284 height: 38
285 radius: 12
286 color: root.theme ? root.theme.withAlpha(root.theme.error, dangerArea.containsMouse ? 0.2 : 0.12) : "transparent"
287 border.width: 1
288 border.color: root.theme ? root.theme.withAlpha(root.theme.error, 0.5) : "transparent"
290 NuguText {
291 anchors.centerIn: parent
292 theme: root.theme
293 variant: "meta"
294 text: root.actionLabel(dangerButton.modelData)
295 color: root.theme ? root.theme.error : "white"
296 }
298 MouseArea {
299 id: dangerArea
301 anchors.fill: parent
302 hoverEnabled: true
303 cursorShape: Qt.PointingHandCursor
304 onClicked: root.runSession(dangerButton.modelData)
305 }
306 }
307 }
308 }
310 Row {
311 anchors.fill: parent
312 anchors.margins: 10
313 spacing: 8
314 visible: !!root.panelState.pendingConfirmation
316 NuguText {
317 anchors.verticalCenter: parent.verticalCenter
318 theme: root.theme
319 variant: "title"
320 text: root.actionLabel(root.panelState.pendingConfirmation)
321 color: root.theme ? root.theme.warning : "white"
322 width: parent.width - confirmButton.width - cancelButton.width - 16
323 elide: Text.ElideRight
324 }
326 Rectangle {
327 id: confirmButton
329 anchors.verticalCenter: parent.verticalCenter
330 width: 82
331 height: 38
332 radius: 12
333 color: root.theme ? root.theme.withAlpha(root.theme.warning, confirmArea.containsMouse ? 0.28 : 0.18) : "transparent"
334 border.width: 1
335 border.color: root.theme ? root.theme.warning : "transparent"
337 NuguText {
338 anchors.centerIn: parent
339 theme: root.theme
340 variant: "meta"
341 selected: true
342 text: "confirm"
343 color: root.theme ? root.theme.warning : "white"
344 }
346 MouseArea {
347 id: confirmArea
349 anchors.fill: parent
350 hoverEnabled: true
351 cursorShape: Qt.PointingHandCursor
352 onClicked: root.confirm(root.panelState.pendingConfirmation)
353 }
354 }
356 Rectangle {
357 id: cancelButton
359 anchors.verticalCenter: parent.verticalCenter
360 width: 74
361 height: 38
362 radius: 12
363 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, cancelArea.containsMouse ? 0.18 : 0.1) : "transparent"
364 border.width: 0
365 border.color: "transparent"
367 NuguText {
368 anchors.centerIn: parent
369 theme: root.theme
370 variant: "meta"
371 text: "cancel"
372 color: root.theme ? root.theme.content.normal : "white"
373 }
375 MouseArea {
376 id: cancelArea
378 anchors.fill: parent
379 hoverEnabled: true
380 cursorShape: Qt.PointingHandCursor
381 onClicked: root.cancel()
382 }
383 }
384 }
385 }
386}

quickshell/nuguland/power.js

Modified

+7 / −0 text lines

5151 : minutesToLabel(secsToEmpty);
54function hasMainBattery(battery) {
55 var b = battery || {};
56 var state = cleanState(b.state);
57 return Number(b.percent || 0) > 0 || state !== "unknown" || String(b.timeEstimate || "unknown") !== "unknown" || Number(b.health || -1) >= 0;
58}
5460// isLowPower(state) — running on battery (drives global animation throttling).
5561function isLowPower(state) {
5662 var s = cleanState(state);
104110 cleanState: cleanState,
105111 batteryRole: batteryRole,
106112 timeEstimateLabel: timeEstimateLabel,
113 hasMainBattery: hasMainBattery,
107114 isLowPower: isLowPower,
108115 SESSION_ACTIONS: SESSION_ACTIONS,
109116 DESTRUCTIVE_ACTIONS: DESTRUCTIVE_ACTIONS,

quickshell/nuguland/power.test.js

Modified

+5 / −0 text lines

4545eq(P.isLowPower('Charging'), false, 'charging is not');
4646eq(P.isLowPower('Fully charged'), false, 'full is not');
48// --- hasMainBattery --------------------------------------------------------
49eq(P.hasMainBattery({ percent: 0, state: 'unknown', timeEstimate: 'unknown', health: -1 }), false, 'desktop display device placeholder is not a main battery');
50eq(P.hasMainBattery({ percent: 72, state: 'charging', timeEstimate: '1h', health: 91 }), true, 'real laptop battery is a main battery');
51eq(P.hasMainBattery({ percent: 0, state: 'discharging', timeEstimate: 'unknown', health: -1 }), true, 'reported discharging state is a main battery even at zero percent');
4853// --- requiresConfirmation --------------------------------------------------
4954eq(P.requiresConfirmation('poweroff'), true, 'poweroff confirms');
5055eq(P.requiresConfirmation('reboot'), true, 'reboot confirms');