redesign nuguland brightness popup
1c5bb1ffa252477713c582bb08e668822598d8e6
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: d1354bd6ec8f
bugabingas dorkfiles
1c5bb1ffa252477713c582bb08e668822598d8e6
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+593 / −10 text lines
new file mode 100644+134 / −0 text lines
# Nuguland Brightness Popup Implementation Plan> **For agentic workers:** REQUIRED SUB-SKILL: Use /skill:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.**Goal:** Implement the accepted Nuguland brightness popup with real display rows, DDC setup CTA, and mixed-state global control.**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.**Tech Stack:** QML/QtQuick, Quickshell, Node `assert` tests.**Roadmap:** None**Phase:** Single-plan implementation---### Task 1: Pure display shaping**Files:**- Modify: `quickshell/nuguland/brightness.test.js`- Modify: `quickshell/nuguland/brightness.js`- [x] **Step 1: Add failing tests for display rows and global state**Add tests that require:- no fake built-in row when no backlight exists;- external outputs become `DDC?` issue rows when ddc is unresolved;- built-in backlight row appears when present;- global state is `none`, `synced`, or `mixed` from controllable display levels.- [x] **Step 2: Run test to verify it fails**Run:```shcd quickshell/nuguland && node brightness.test.js```Expected: FAIL because new shaping functions do not exist.- [x] **Step 3: Implement shaping helpers**Add small pure helpers to `brightness.js` and export them.- [x] **Step 4: Run test to verify it passes**Run:```shcd quickshell/nuguland && node brightness.test.js```Expected: `brightness.test.js: ALL PASS`.### Task 2: Native brightness state and setup action**Files:**- Modify: `quickshell/nuguland/Brightness.qml`- Modify: `quickshell/nuguland/shell.qml`- [x] **Step 1: Add Niri dependency**Add `property Niri niriService` to `Brightness.qml` and pass `niriService: niri` from `shell.qml`.- [x] **Step 2: Shape state with real rows**Make `Brightness.qml stateObject()` include:- `displays`: shaped rows from current backlight and `niriService.outputList()`;- `global`: shaped global state;- `setup`: whether DDC setup is available/needed.- [x] **Step 3: Add `setupDdc()` action**Expose a method that launches a fixed `pkexec` command for Arch hosts using `pacman`, `modprobe i2c-dev`, and `udevadm trigger`.### Task 3: Visual panel redesign**Files:**- Modify: `quickshell/nuguland/BrightnessPanel.qml`- [x] **Step 1: Replace popup UI with accepted layout**Render:- setup button only when setup is needed;- no fake global control when no controllable display exists;- merged multislider when global state is mixed;- normal bar when synced;- presets only with controllable displays;- per-display rows with issue badges only when needed.- [x] **Step 2: Wire interactions**Global control and presets call `setAll(level)`. Per-display rows call `setDisplay(id, level)`.### Task 4: Verification and commit**Files:**- Verify: `quickshell/nuguland/brightness.test.js`- Verify: `quickshell/nuguland/BrightnessPanel.qml`- [x] **Step 1: Format**Run:```shcd quickshell/nuguland && just fmt```- [x] **Step 2: Run tests**Run:```shcd quickshell/nuguland && node brightness.test.js```- [x] **Step 3: Run lint**Run:```shcd quickshell/nuguland && just lint```- [x] **Step 4: Commit focused changes**Commit only brightness redesign files and this plan, not unrelated dirty `PopoutHost.qml`.+67 / −8 text lines
property Niri niriService property var ddcDisplays: ({}) "level": level, 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"`]); function setLevel(level) { const value = Brightness.clampLevel(level); applyNative(value); liveLevel = value; function setupDdc() { "kind": "set-level", "kind": "setup-ddc" }; Quickshell.execDetached(["pkexec", "sh", "-c", "pacman -S --needed --noconfirm ddcutil && modprobe i2c-dev && udevadm trigger --subsystem-match=i2c-dev"]); return stateJson(); } function setDisplay(id, level) { const value = Brightness.clampLevel(level); if (String(id) === "backlight") { applyNative(value); liveLevel = value; } lastAction = { "kind": "set-display", "id": String(id), function setAll(level) { const value = Brightness.clampLevel(level); const rows = stateObject().displays || []; for (let i = 0; i < rows.length; i++) { if (rows[i].controllable) setDisplay(rows[i].id, value); } lastAction = { "kind": "set-all", "level": Math.round(value * 100) / 100 }; lastOsd = osd(value); return stateJson(); } function setLevel(level) { const value = Brightness.clampLevel(level); return setAll(value); }new file mode 100644+297 / −0 text lines
pragma ComponentBehavior: Boundimport QtQuickimport "Util.js" as UtilColumn { id: root required property Theme theme required property Brightness brightnessService property var panelState: brightnessService ? Util.parseJson(brightnessService.stateJson(), { "displays": [], "global": { "mode": "none", "level": 0, "levels": [] }, "setup": { "needed": false, "available": false } }) : ({ "displays": [], "global": { "mode": "none", "level": 0, "levels": [] }, "setup": { "needed": false, "available": false } }) readonly property var displays: panelState.displays || [] readonly property var global: panelState.global || ({ "mode": "none", "level": 0, "levels": [] }) readonly property var setup: panelState.setup || ({ "needed": false, "available": false }) readonly property bool hasGlobal: global.mode !== "none" function refreshFrom(text) { panelState = Util.parseJson(text, panelState); } function setAllAt(x, width) { if (brightnessService && root.hasGlobal) refreshFrom(brightnessService.setAll(Math.max(0, Math.min(1, x / width)))); } function setDisplayAt(id, x, width) { if (brightnessService) refreshFrom(brightnessService.setDisplay(id, Math.max(0, Math.min(1, x / width)))); } width: parent ? parent.width : 0 spacing: 12 Row { width: parent.width height: root.setup.needed ? 34 : 0 visible: root.setup.needed Item { width: Math.max(1, parent.width - setupButton.width) height: 1 } Rectangle { id: setupButton width: 112 height: 34 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, setupArea.containsMouse ? 0.34 : 0.24) : "transparent" border.width: 1 border.color: root.theme ? root.theme.ui.accent : "white" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: "setup ddc" color: root.theme ? root.theme.content.normal : "white" } MouseArea { id: setupArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: if (root.brightnessService) root.refreshFrom(root.brightnessService.setupDdc()) } } } Rectangle { id: globalTrack width: parent.width height: root.hasGlobal ? 64 : 0 visible: root.hasGlobal radius: 16 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.12) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.42) : "white" clip: true Repeater { model: root.global.mode === "mixed" ? root.global.levels : [root.global.level] delegate: Rectangle { id: globalLine required property int index required property real modelData readonly property int lineCount: root.global.mode === "mixed" ? Math.max(1, root.global.levels.length) : 1 x: 0 y: Math.round(index * globalTrack.height / lineCount) width: globalTrack.width height: Math.ceil(globalTrack.height / lineCount) color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.18) : "transparent" Rectangle { width: Math.round(parent.width * Math.max(0, Math.min(1, globalLine.modelData))) height: parent.height color: root.theme ? root.theme.ui.accent : "white" } } } MouseArea { anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onPressed: mouse => root.setAllAt(mouse.x, width) onPositionChanged: mouse => { if (pressed) root.setAllAt(mouse.x, width); } } } Grid { id: presetGrid width: parent.width height: root.hasGlobal ? 36 : 0 visible: root.hasGlobal columns: 4 columnSpacing: 8 Repeater { model: [0.25, 0.5, 0.75, 1] delegate: Rectangle { id: preset required property real modelData width: Math.floor((presetGrid.width - presetGrid.columnSpacing * (presetGrid.columns - 1)) / presetGrid.columns) height: 36 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, presetArea.containsMouse ? 0.18 : 0.11) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.4) : "white" NuguText { anchors.centerIn: parent theme: root.theme variant: "meta" text: `${Math.round(preset.modelData * 100)}%` color: root.theme ? root.theme.content.normal : "white" } MouseArea { id: presetArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: if (root.brightnessService) root.refreshFrom(root.brightnessService.setAll(preset.modelData)) } } } } Column { width: parent.width spacing: 8 Repeater { model: root.displays delegate: Rectangle { id: displayRow required property var modelData readonly property bool controllable: !!modelData.controllable readonly property string issue: String(modelData.issue || "") readonly property real level: Math.max(0, Math.min(1, Number(modelData.level || 0))) width: root.width height: 38 radius: 12 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, controllable ? 0.1 : 0.07) : "transparent" border.width: 1 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" opacity: controllable ? 1 : 0.74 NuguText { id: displayName anchors.left: parent.left anchors.leftMargin: 10 anchors.verticalCenter: parent.verticalCenter width: 128 theme: root.theme text: String(displayRow.modelData.name || "display") color: root.theme ? root.theme.content.normal : "white" elide: Text.ElideRight } Rectangle { id: displaySlider anchors.left: displayName.right anchors.leftMargin: 10 anchors.right: displayPercent.left anchors.rightMargin: 10 anchors.verticalCenter: parent.verticalCenter height: 18 radius: 9 color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.16) : "transparent" border.width: 1 border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.32) : "white" clip: true Rectangle { width: Math.round(parent.width * displayRow.level) height: parent.height radius: parent.radius color: root.theme ? (displayRow.controllable ? root.theme.ui.accent : root.theme.ui.minor) : "white" } MouseArea { anchors.fill: parent enabled: displayRow.controllable hoverEnabled: true cursorShape: Qt.PointingHandCursor onPressed: mouse => root.setDisplayAt(String(displayRow.modelData.id || ""), mouse.x, width) onPositionChanged: mouse => { if (pressed) root.setDisplayAt(String(displayRow.modelData.id || ""), mouse.x, width); } } } NuguText { id: displayPercent anchors.right: issueBadge.visible ? issueBadge.left : parent.right anchors.rightMargin: issueBadge.visible ? 10 : 10 anchors.verticalCenter: parent.verticalCenter width: 44 theme: root.theme variant: "meta" text: displayRow.controllable ? `${Math.round(displayRow.level * 100)}%` : "—" color: root.theme ? root.theme.content.normal : "white" horizontalAlignment: Text.AlignRight } NuguText { id: issueBadge visible: displayRow.issue.length > 0 anchors.right: parent.right anchors.rightMargin: 10 anchors.verticalCenter: parent.verticalCenter width: 70 theme: root.theme variant: "meta" text: displayRow.issue.toLowerCase() color: root.theme ? root.theme.warning : "white" horizontalAlignment: Text.AlignRight } } } }}+1 / −1 text lines
+67 / −1 text lines
function outputArray(outputs) { if (Array.isArray(outputs)) return outputs; var obj = outputs || {}; return Object.keys(obj).map(function (name) { var row = obj[name] || {}; var copy = {}; Object.keys(row).forEach(function (key) { copy[key] = row[key]; }); copy.name = copy.name || name; return copy; });}function displayName(output) { var name = String(output.name || "display"); var model = String(output.model || ""); return model.length > 0 && model !== "Unknown" ? name + " · " + model : name;}function displayRows(backlight, outputs, ddc) { var rows = []; var b = backlight || {}; if (b.present) { rows.push({ id: "backlight", name: "built-in", kind: "backlight", level: clampLevel(b.level), controllable: true, issue: "" }); } var ddcMap = ddc || {}; outputArray(outputs).forEach(function (output) { var key = String(output.name || ""); if (key.length === 0) return; var state = ddcMap[key] || {}; var ok = !!state.controllable; rows.push({ id: "ddc:" + key, name: displayName(output), kind: "ddc", level: ok ? clampLevel(state.level) : 0, controllable: ok, issue: ok ? "" : "DDC?" }); }); return rows;}function globalState(rows) { var levels = (rows || []).filter(function (row) { return !!row.controllable; }).map(function (row) { return Math.round(clampLevel(row.level) * 100) / 100; }); if (levels.length === 0) return { mode: "none", level: 0, levels: [] }; var first = levels[0]; var mixed = levels.some(function (level) { return level !== first; }); if (!mixed) return { mode: "synced", level: first, levels: levels }; var sum = levels.reduce(function (a, b) { return a + b; }, 0); return { mode: "mixed", level: Math.round(sum / levels.length * 100) / 100, levels: levels };}+26 / −0 text lines
// displayRows: no fake built-in; unresolved external outputs get issue badgesassert.deepStrictEqual(B.displayRows({ present: false, level: 0.55 }, { "DP-1": { model: "27E6QC" }, "DP-2": { model: "27E6QC" }}, {}), [ { id: "ddc:DP-1", name: "DP-1 · 27E6QC", kind: "ddc", level: 0, controllable: false, issue: "DDC?" }, { id: "ddc:DP-2", name: "DP-2 · 27E6QC", kind: "ddc", level: 0, controllable: false, issue: "DDC?" }]);assert.deepStrictEqual(B.displayRows({ present: true, level: 0.55 }, {}, {}), [ { id: "backlight", name: "built-in", kind: "backlight", level: 0.55, controllable: true, issue: "" }]);assert.deepStrictEqual(B.displayRows({ present: true, level: 0.75 }, [ { name: "DP-1", model: "27E6QC" }], { "DP-1": { level: 0.25, controllable: true } }), [ { id: "backlight", name: "built-in", kind: "backlight", level: 0.75, controllable: true, issue: "" }, { id: "ddc:DP-1", name: "DP-1 · 27E6QC", kind: "ddc", level: 0.25, controllable: true, issue: "" }]);// globalState: none/synced/mixed from controllable displays onlyassert.deepStrictEqual(B.globalState([]), { mode: "none", level: 0, levels: [] });assert.deepStrictEqual(B.globalState([{ controllable: false, level: 0.2 }]), { mode: "none", level: 0, levels: [] });assert.deepStrictEqual(B.globalState([{ controllable: true, level: 0.5 }, { controllable: true, level: 0.5 }]), { mode: "synced", level: 0.5, levels: [0.5, 0.5] });assert.deepStrictEqual(B.globalState([{ controllable: true, level: 0.75 }, { controllable: true, level: 0.25 }]), { mode: "mixed", level: 0.5, levels: [0.75, 0.25] });+1 / −0 text lines