diff options
Diffstat (limited to 'desktop')
25 files changed, 603 insertions, 69 deletions
diff --git a/desktop/Page.qml b/desktop/Page.qml index eb1c5c0..02b2da8 100644 --- a/desktop/Page.qml +++ b/desktop/Page.qml @@ -138,6 +138,27 @@ Item { anchors.topMargin: 12 clip: true contentWidth: availableWidth + // Faster wheel scrolling than Qt's defaults (2500, 1500); the + // sidebar and the landing page in Settings.qml use the same pair. + Component.onCompleted: { + scroll.contentItem.maximumFlickVelocity = 8000; + scroll.contentItem.flickDeceleration = 4000; + } + + // Page Up/Down, Home/End scroll the page. Reached when the page + // itself has focus (a click on empty space, below) or bubbling up + // from a field, which keeps Home/End for its cursor. + Keys.onPressed: e => { + const f = scroll.contentItem, max = Math.max(0, f.contentHeight - f.height); + const to = e.key === Qt.Key_PageUp ? f.contentY - f.height * 0.9 + : e.key === Qt.Key_PageDown ? f.contentY + f.height * 0.9 + : e.key === Qt.Key_Home ? 0 + : e.key === Qt.Key_End ? max : null; + if (to === null) return; + f.cancelFlick(); + f.contentY = Math.max(0, Math.min(to, max)); + e.accepted = true; + } Item { id: holder @@ -146,6 +167,16 @@ Item { } } + // A click on empty page space focuses the page, for the keys above. + // Beneath the content, so fields and buttons keep their clicks; it takes + // no wheel (no onWheel) and the Flickable still steals drags from it. + MouseArea { + parent: holder + z: -1 + anchors.fill: parent + onPressed: scroll.forceActiveFocus() + } + // The reveal highlight, over the row and in holder's coordinates. // Declared out here, not in the ScrollView, which sizes from a single // child; parent puts it in holder all the same. diff --git a/desktop/Settings.qml b/desktop/Settings.qml index 6b81586..2e151a9 100644 --- a/desktop/Settings.qml +++ b/desktop/Settings.qml @@ -228,6 +228,9 @@ Scope { // Without it a scrolled list draws over the search box. clip: true model: root.found + // Faster wheel scrolling, as Page.qml. + maximumFlickVelocity: 8000 + flickDeceleration: 4000 // A group's heading above its first entry, then the entry. delegate: Column { @@ -449,6 +452,9 @@ Scope { contentHeight: about.height clip: true boundsBehavior: Flickable.StopAtBounds + // Faster wheel scrolling, as Page.qml. + maximumFlickVelocity: 8000 + flickDeceleration: 4000 ScrollBar.vertical: ScrollBar {} Column { diff --git a/desktop/assistant/Assistant.qml b/desktop/assistant/Assistant.qml index d6863a0..7d299eb 100644 --- a/desktop/assistant/Assistant.qml +++ b/desktop/assistant/Assistant.qml @@ -49,7 +49,7 @@ Scope { property int opChars: 0 property var opOut: [] property string opError: "" - // Results folder: $(xdg-user-dir DOCUMENTS)/Assistant, read once. + // Results folder: the daemon's out_dir, from hello; this until then. property string outDir: (Quickshell.env("HOME") || "") + "/Documents/Assistant" readonly property string fileops: decodeURIComponent(Qt.resolvedUrl("fileops").toString().replace(/^file:\/\//, "")) @@ -281,18 +281,6 @@ Scope { } } - Process { - running: true - command: ["xdg-user-dir", "DOCUMENTS"] - stdout: StdioCollector { - // With no documents folder set, xdg-user-dir answers $HOME itself. - onStreamFinished: { - const d = text.trim(); - if (d.startsWith("/") && d !== Quickshell.env("HOME")) root.outDir = d + "/Assistant"; - } - } - } - // deck-it's Assistant tab look, from its config's [assistant] keys: the // backdrop picture, the user's avatar, and where the assistant's face is // in the backdrop ([centre x, centre y, size] in its pixels). Empty: no @@ -442,6 +430,7 @@ print(json.dumps({"bg": os.path.expanduser(a.get("background") or ""), root.runningTool = e.state === "tool" ? e.tool : ""; root.model = e.model ?? ""; root.chatModel = e.chat_model ?? ""; + if (e.out_dir) root.outDir = e.out_dir; root.ctxUsed = e.ctx_used; root.ctxMax = e.ctx_max; root.load(e.id, e.turns, e.pending); diff --git a/desktop/assistant/Files.js b/desktop/assistant/Files.js index bcbd9bc..bea1841 100644 --- a/desktop/assistant/Files.js +++ b/desktop/assistant/Files.js @@ -28,8 +28,9 @@ const IMAGE = [".png", ".jpg", ".jpeg", ".gif", ".webp"]; const VIDEO = [".mp4", ".mkv", ".webm", ".mov", ".avi", ".m4v"]; const ARCHIVE = [".zip", ".tar", ".gz", ".tgz", ".xz", ".txz", ".bz2", ".zst", ".7z", ".rar"]; -// Kinds chat takes; the rest only get local actions. -const CHAT = ["text", "code", "image", "pdf"]; +// Kinds chat takes; the rest only get local actions. A video goes as its +// path only, for the video tool. +const CHAT = ["text", "code", "image", "pdf", "video"]; function name(path) { return path.slice(path.lastIndexOf("/") + 1); } diff --git a/desktop/assistant/test_files.js b/desktop/assistant/test_files.js index f2a65ca..f6ed058 100644 --- a/desktop/assistant/test_files.js +++ b/desktop/assistant/test_files.js @@ -29,8 +29,8 @@ const cases = { }; for (const [p, k] of Object.entries(cases)) assert.strictEqual(F.kind(p), k, p); -assert.ok(F.chats("pdf") && F.chats("image") && F.chats("text") && F.chats("code")); -assert.ok(!F.chats("video") && !F.chats("archive") && !F.chats("other")); +assert.ok(F.chats("pdf") && F.chats("image") && F.chats("text") && F.chats("code") && F.chats("video")); +assert.ok(!F.chats("archive") && !F.chats("other")); assert.strictEqual(F.fromUrl("file:///home/you/My%20Docs/caf%C3%A9.pdf"), "/home/you/My Docs/café.pdf"); assert.strictEqual(F.fromUrl("file:///tmp/a.txt"), "/tmp/a.txt"); diff --git a/desktop/modules/appearance/README.md b/desktop/modules/appearance/README.md index 2c9a6ad..f6f0356 100644 --- a/desktop/modules/appearance/README.md +++ b/desktop/modules/appearance/README.md @@ -84,7 +84,10 @@ where there is not, and the hovered thumbnail on the targeted screen while the pointer is over it. The thumbnails are grouped by folder, each a header that opens and closes -it, closed to begin with and remembered while the shell runs. The local +it, closed to begin with and remembered while the shell runs; opening one +folds whichever was open, so only one is open at a time. A colour filter +that leaves the open folder empty folds it and opens the first folder with +matches instead. The local groups are the top-level folders of `~/Pictures/wallpapers`, with the images loose in it as a group of its own; after them come the distribution's, `/usr/share/wallpapers`, as `system` for its loose images and `Plasma` for @@ -105,6 +108,20 @@ how far it enlarges: not at all is green, up to 1.33x yellow, past that red. Under the mock screens a note in the same colour says why, for the hovered image or else the staged one. The staged image keeps the accent border. +The row of colour circles under the mock screens filters the list: a click +shows only the wallpapers that carry that colour, folders left empty drop +out, and a second click shows them all again. Each image is quantized to six +colours by `magick` on a 64 px copy, run in parallel, and each colour lands +in a hue bucket, or dark or light when it has little saturation +(`WallColors.js`, tested by `node test_wallcolors.js`). Each image is filed +under one bucket, its dominant one: the largest colour bucket when it covers a +quarter of the image, else the larger of dark and light. A first version +matched any bucket over a fifth, and a blue sky with a red sunset showed +under both. The raw colours are cached by path in +`~/.cache/keystone/wallcolors.tsv`, so only new files are analysed: the first +run over 843 images filled it in about 20 seconds. Saturation is HSV's, not +HSL's: HSL reads a pale lavender like `#cad3f5` as strongly coloured. + "Open wallhaven-dl" under the mock screens launches the wallhaven-dl app, which searches wallhaven.cc and finds larger copies of low-res wallpapers, and closes the settings window, as a successful Apply does, so the desk diff --git a/desktop/modules/appearance/WallColors.js b/desktop/modules/appearance/WallColors.js new file mode 100644 index 0000000..749f5cb --- /dev/null +++ b/desktop/modules/appearance/WallColors.js @@ -0,0 +1,70 @@ +.pragma library +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// The wallpaper page's colour filter, tested by test_wallcolors.js under node. +// Each image is quantized to six colours by magick (Wallpapers.qml), and each +// colour falls in one bucket here. An image matches one bucket only, its +// dominant one: the largest colour bucket when it covers a quarter of the +// image, else the larger of dark and light. Matching any bucket over a share +// mixed a red sunset into blue for its sky. +// ponytail: six colours and fixed hue cuts; tune the cuts and MIN if the +// matches feel off. + +var BUCKETS = ["red", "peach", "yellow", "green", "teal", "blue", "mauve", "dark", "light"]; +var MIN = 0.25; + +// "#RRGGBB" -> a bucket name, or "" for a mid grey. +function bucket(hex) { + const r = parseInt(hex.slice(1, 3), 16) / 255, + g = parseInt(hex.slice(3, 5), 16) / 255, + b = parseInt(hex.slice(5, 7), 16) / 255; + const max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min; + const l = (max + min) / 2; + // HSV saturation: HSL reads a pale lavender like #cad3f5 as strongly + // coloured, which is the "light" the swatch means. + const s = max === 0 ? 0 : d / max; + if (l < 0.15) return "dark"; + if (s < 0.2) return l < 0.35 ? "dark" : l > 0.65 ? "light" : ""; + let h = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4; + h = (h * 60 + 360) % 360; + return h < 15 || h >= 335 ? "red" : h < 40 ? "peach" : h < 70 ? "yellow" + : h < 160 ? "green" : h < 200 ? "teal" : h < 255 ? "blue" : "mauve"; +} + +// "#RRGGBB:count,..." -> { bucket: fraction of the image }. +function parse(line) { + const out = {}; + let total = 0; + for (const part of line.split(",")) { + const i = part.indexOf(":"); + if (i < 0) continue; + const n = +part.slice(i + 1), k = bucket(part.slice(0, i)); + total += n; + if (k) out[k] = (out[k] || 0) + n; + } + for (const k in out) out[k] /= total; + return out; +} + +// The bucket an image is filed under, "" for none (mostly mid grey). +function dominant(fractions) { + let best = "", bestF = 0; + for (const k in fractions) + if (k !== "dark" && k !== "light" && fractions[k] > bestF) { best = k; bestF = fractions[k]; } + if (bestF >= MIN) return best; + const d = fractions.dark || 0, l = fractions.light || 0; + return d === 0 && l === 0 ? "" : d >= l ? "dark" : "light"; +} + +function matches(fractions, key) { + return !!fractions && dominant(fractions) === key; +} diff --git a/desktop/modules/appearance/WallpaperTab.qml b/desktop/modules/appearance/WallpaperTab.qml index 136b24d..cf41a4d 100644 --- a/desktop/modules/appearance/WallpaperTab.qml +++ b/desktop/modules/appearance/WallpaperTab.qml @@ -205,9 +205,59 @@ Column { } } + // The colour filter: a click shows only the wallpapers that carry the + // colour (Wallpapers.colors), a second click shows them all again. + Row { + id: colorRow + spacing: 8 + Text { + anchors.verticalCenter: parent.verticalCenter + text: "Colour" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 } + color: Theme.subtext + } + Repeater { + // Fixed colours, not the theme's: they name WallColors.js's hue + // buckets, which do not move with the scheme, and a scheme can + // reuse one colour under several names (one had peach = yellow, + // blue = lavender, mauve = pink, three pairs of twin circles). + model: [ + { key: "red", color: "#ed8796" }, { key: "peach", color: "#f5a97f" }, + { key: "yellow", color: "#eed49f" }, { key: "green", color: "#a6da95" }, + { key: "teal", color: "#8bd5ca" }, { key: "blue", color: "#8aadf4" }, + { key: "mauve", color: "#c6a0f6" }, { key: "dark", color: "#181926" }, + { key: "light", color: "#cad3f5" }, + ] + delegate: Rectangle { + required property var modelData + readonly property bool on: Wallpapers.colorFilter === modelData.key + anchors.verticalCenter: parent.verticalCenter + width: 22 + height: 22 + radius: width / 2 + color: modelData.color + border.width: on ? 3 : swatchHover.hovered ? 2 : 1 + border.color: on ? Theme.accent : Qt.alpha(Theme.text, swatchHover.hovered ? 0.6 : 0.2) + HoverHandler { id: swatchHover } + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: Wallpapers.colorFilter = parent.on ? "" : modelData.key + } + } + } + Text { + anchors.verticalCenter: parent.verticalCenter + visible: Wallpapers.analysing + text: "analysing colours…" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } + color: Theme.overlay + } + } + Column { width: parent.width - height: parent.height - mockPane.height - parent.spacing + height: parent.height - mockPane.height - colorRow.height - parent.spacing * 2 spacing: 12 Row { @@ -232,6 +282,8 @@ Column { anchors.verticalCenter: parent.verticalCenter text: Wallpapers.scanning ? "scanning…" : Wallpapers.applying ? "applying…" + : Wallpapers.colorFilter !== "" + ? Wallpapers.groups.reduce((n, g) => n + g.files.length, 0) + " of " + Wallpapers.files.length + " wallpapers" : Wallpapers.files.length + " wallpapers" font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } color: Theme.overlay @@ -268,18 +320,50 @@ Column { return out; } function rebuild() { + // An open folder the colour filter hid is folded for real, + // not just hidden, and unless another is open the first + // folder left opens in its place. Left open, it came back + // beside the next one opened once the filter was cleared. + // Not while the list is empty, before the first scan. + const keys = Wallpapers.groups.map(g => g.key); + const hidden = Object.keys(Wallpapers.expanded) + .filter(k => Wallpapers.expanded[k] && keys.indexOf(k) < 0); + if (keys.length > 0 && hidden.length > 0) { + hidden.forEach(k => Wallpapers.toggle(k)); + if (!keys.some(k => Wallpapers.expanded[k])) Wallpapers.toggle(keys[0]); + } rows.clear(); for (const g of Wallpapers.groups) { rows.append({ key: g.key, start: -1 }); if (Wallpapers.expanded[g.key]) rows.append(rowsOf(g)); } } + // One folder open at a time: opening one first folds any other, + // from the bottom up so the indexes above stay put, then scrolls + // to the new one's header, which a fold above it would move. function toggle(index) { const g = group(rows.get(index).key); const body = rowsOf(g); - if (Wallpapers.expanded[g.key]) rows.remove(index + 1, body.length); - else body.forEach((r, i) => rows.insert(index + 1 + i, r)); + if (Wallpapers.expanded[g.key]) { + rows.remove(index + 1, body.length); + Wallpapers.toggle(g.key); + return; + } + let folded = false; + for (let i = rows.count - 1; i >= 0; i--) { + const r = rows.get(i); + if (r.start >= 0 || r.key === g.key || !Wallpapers.expanded[r.key]) continue; + rows.remove(i + 1, rowsOf(group(r.key)).length); + Wallpapers.toggle(r.key); + if (i < index) folded = true; + } + if (folded) { + index = 0; + while (rows.get(index).key !== g.key) index++; + } + body.forEach((r, i) => rows.insert(index + 1 + i, r)); Wallpapers.toggle(g.key); + if (folded) positionViewAtIndex(index, ListView.Beginning); } // The width settles after creation, and a new column count diff --git a/desktop/modules/appearance/Wallpapers.qml b/desktop/modules/appearance/Wallpapers.qml index 2b8faf7..f24aca4 100644 --- a/desktop/modules/appearance/Wallpapers.qml +++ b/desktop/modules/appearance/Wallpapers.qml @@ -15,6 +15,7 @@ import Quickshell import Quickshell.Io import QtQuick import "../.." +import "WallColors.js" as WallColors // The wallpaper side. Setting one is `wallp`'s job: it knows about the two // outputs, the saved state and the accent run, and none of that is worth @@ -93,6 +94,70 @@ Singleton { sizeProc.running = false; sizeProc.command = ["sh", "-c", 'printf "%s\\0" "$@" | xargs -0 -r file -N -0', "sh"].concat(root.files); sizeProc.running = true; + root.analyse(); + } + } + } + + // Each image's six main colours, for the page's colour filter + // (WallColors.js), as fractions by bucket. magick quantizes a 64 px copy, + // decoded small with jpeg:size, in parallel; each child prints its line + // in one write, so lines do not interleave on the pipe. The raw lines are + // cached by path in colorCache: only new files are analysed. An upscale + // rewrites a file in place but keeps its colours, so the path is the key. + property var colors: ({}) + property var colorLines: ({}) + property string colorFilter: "" + readonly property bool analysing: colorProc.running + readonly property string colorCache: + (Quickshell.env("XDG_CACHE_HOME") || home + "/.cache") + "/keystone/wallcolors.tsv" + + function analyse() { + if (!colorViewReady) return; // the cache read calls again + const missing = files.filter(f => !(f in colorLines)); + if (missing.length === 0 || colorProc.running) return; + colorProc.command = ["sh", "-c", + `printf '%s\\0' "$@" | xargs -0 -r -P"$(nproc)" -n1 sh -c '` + + `c=$(magick -define jpeg:size=256x256 "$1[0]" -alpha off -resize 64x64 -colors 6 ` + + `-format %c histogram:info: 2>/dev/null | sort -rn | ` + + `awk "{sub(\\":\\",\\"\\",\\$1); printf \\"%s%s:%s\\", s, substr(\\$3,1,7), \\$1; s=\\",\\"}"); ` + + `printf "%s\\t%s\\n" "$1" "$c"' sh`, "sh"].concat(missing); + colorProc.running = true; + } + + // Raw cache lines to colorLines and colors, reassigned whole so bindings + // see the change. + function takeColors(text) { + const lines = Object.assign({}, colorLines), cols = Object.assign({}, colors); + for (const line of text.split("\n")) { + const t = line.indexOf("\t"); + if (t < 0) continue; + const p = line.slice(0, t), c = line.slice(t + 1); + lines[p] = c; + cols[p] = WallColors.parse(c); + } + colorLines = lines; + colors = cols; + } + + FileView { + id: colorView + path: root.colorCache + printErrors: false // absent until the first analysis + onLoaded: { root.takeColors(text()); root.colorViewReady = true; root.analyse(); } + onLoadFailed: { root.colorViewReady = true; root.analyse(); } + } + property bool colorViewReady: false + + Process { + id: colorProc + stdout: StdioCollector { + onStreamFinished: { + root.takeColors(text); + let out = ""; + for (const p in root.colorLines) out += `${p}\t${root.colorLines[p]}\n`; + // Never empty: analyse ran only with files to add. + colorView.setText(out); } } } @@ -249,7 +314,11 @@ Singleton { // `expanded` is indexed by, so a local folder named "system" stays apart. readonly property var groups: { const local = {}, system = [], plasma = {}; - for (const f of files) { + // With a colour picked, only the images it dominates; one not yet + // analysed is left out until it is. + const shownFiles = colorFilter === "" ? files + : files.filter(f => WallColors.matches(colors[f], colorFilter)); + for (const f of shownFiles) { if (f.startsWith(dir + "/")) { const rel = f.slice(dir.length + 1); const key = rel.includes("/") ? rel.slice(0, rel.indexOf("/")) : ""; diff --git a/desktop/modules/appearance/test_wallcolors.js b/desktop/modules/appearance/test_wallcolors.js new file mode 100644 index 0000000..aa05b61 --- /dev/null +++ b/desktop/modules/appearance/test_wallcolors.js @@ -0,0 +1,47 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Run: node desktop/modules/appearance/test_wallcolors.js +// WallColors.js is a QML library, so its .pragma line is stripped before node +// evaluates it. + +const fs = require("fs"); +const assert = require("assert"); + +const src = fs.readFileSync(__dirname + "/WallColors.js", "utf8").replace(/^\.pragma library$/m, ""); +const C = new Function(src + "\nreturn { bucket, parse, matches, dominant };")(); + +assert.strictEqual(C.bucket("#ed8796"), "red"); +assert.strictEqual(C.bucket("#f5a97f"), "peach"); +assert.strictEqual(C.bucket("#eed49f"), "yellow"); +assert.strictEqual(C.bucket("#a6da95"), "green"); +assert.strictEqual(C.bucket("#8bd5ca"), "teal"); +assert.strictEqual(C.bucket("#8aadf4"), "blue"); +assert.strictEqual(C.bucket("#2a3a6a"), "blue"); // navy, dark but coloured +assert.strictEqual(C.bucket("#c6a0f6"), "mauve"); +assert.strictEqual(C.bucket("#181926"), "dark"); +assert.strictEqual(C.bucket("#cad3f5"), "light"); +assert.strictEqual(C.bucket("#808080"), ""); // mid grey: no bucket + +const f = C.parse("#8aadf4:30,#181926:60,#808080:10"); +assert.ok(Math.abs(f.blue - 0.3) < 1e-9 && Math.abs(f.dark - 0.6) < 1e-9); +// One bucket per image: blue covers over a quarter, so it wins over the +// larger dark. +assert.ok(C.matches(f, "blue") && !C.matches(f, "dark")); +assert.ok(!C.matches(f, "red") && !C.matches(undefined, "blue")); +// Two colours: the larger wins, the smaller does not match. +const sunset = C.parse("#8aadf4:60,#ed8796:30,#181926:10"); +assert.ok(C.matches(sunset, "blue") && !C.matches(sunset, "red")); +// No colour covers a quarter: dark or light decides. +assert.strictEqual(C.dominant(C.parse("#ed8796:10,#181926:60,#cad3f5:30")), "dark"); +assert.strictEqual(C.dominant(C.parse("#808080:1")), ""); + +console.log("ok"); diff --git a/desktop/modules/assistant/AssistantModule.qml b/desktop/modules/assistant/AssistantModule.qml index 9e8adbc..6aefb1f 100644 --- a/desktop/modules/assistant/AssistantModule.qml +++ b/desktop/modules/assistant/AssistantModule.qml @@ -27,7 +27,8 @@ Module { settings: true group: "Assistant" keywords: ["llm", "model", "llama", "server", "prompt", "temperature", "thinking", - "rounds", "tools", "environment", "daemon", "restart", "cloud", "provider"] + "rounds", "tools", "environment", "daemon", "restart", "cloud", "provider", + "folder", "output", "documents"] readonly property string home: Quickshell.env("HOME") readonly property string daemonDir: home + "/Programming/GIT/desktop-assistant" @@ -38,9 +39,10 @@ Module { // The system interpreter, as for calctl: python3 on PATH is a pyenv shim. readonly property string python: "/usr/bin/python3" - readonly property var keys: ["llm", "system", "tool_rounds", "temperature", "thinking"] + readonly property var keys: ["llm", "system", "tool_rounds", "temperature", "thinking", "out_dir"] readonly property var labels: ({ llm: "Server", system: "System prompt", tool_rounds: "Tool rounds", - temperature: "Temperature", thinking: "Thinking" }) + temperature: "Temperature", thinking: "Thinking", + out_dir: "Output folder" }) // config.toml as last read or written; "" when there is none. The page // edits draft, which save() writes; base is the file the draft began diff --git a/desktop/modules/assistant/AssistantPage.qml b/desktop/modules/assistant/AssistantPage.qml index b25b33b..0875a5d 100644 --- a/desktop/modules/assistant/AssistantPage.qml +++ b/desktop/modules/assistant/AssistantPage.qml @@ -359,6 +359,25 @@ Column { } } + Labelled { + objectName: "key:out_dir" + label: "Output folder" + Field { + anchors.fill: parent + value: page.v.out_dir ?? "" + placeholder: page.d.out_dir ?? "" + bad: page.asst.invalid["key:out_dir"] ?? false + // Where the canvas and tools write files; the daemon refuses + // anything but an absolute or ~ path, so a bad one never saves. + onEdited: t => { + const s = t.trim(); + const ok = s === "" || s.startsWith("/") || s === "~" || s.startsWith("~/"); + page.asst.markInvalid("key:out_dir", !ok); + if (ok) page.asst.setKey("out_dir", s ? page.asst.quote(s) : null); + } + } + } + // The prompt is long and multi-line, so it gets its own box and an // explicit Save rather than Enter. Column { @@ -680,15 +699,39 @@ Column { id: toolText anchors { left: toolSw.right; leftMargin: 10; right: cloudMark.left; rightMargin: 10 verticalCenter: parent.verticalCenter } - Text { - text: toolRow.modelData.name - color: page.asst.toolOn(toolRow.modelData) ? Theme.text : Theme.subtext - font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true } + // A description ending "Read-only." shows it as a chip by + // the name instead. The toml keeps the sentence: the model + // reads the description too. + readonly property var ro: /\s*Read-only\.\s*$/.exec(toolRow.modelData.description ?? "") + Row { + spacing: 8 + Text { + anchors.verticalCenter: parent.verticalCenter + text: toolRow.modelData.name + color: page.asst.toolOn(toolRow.modelData) ? Theme.text : Theme.subtext + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true } + } + Rectangle { + anchors.verticalCenter: parent.verticalCenter + visible: toolText.ro !== null + width: roText.implicitWidth + 12 + height: roText.implicitHeight + 4 + radius: height / 2 + color: Qt.alpha(Theme.overlay, 0.35) + Text { + id: roText + anchors.centerIn: parent + text: "read only" + color: Theme.subtext + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 5 } + } + } } Small { width: parent.width wrapMode: Text.Wrap - text: toolRow.modelData.description + text: toolText.ro ? toolRow.modelData.description.slice(0, toolText.ro.index) + : toolRow.modelData.description } } } diff --git a/desktop/modules/deckit/DeckItServicesPage.qml b/desktop/modules/deckit/DeckItServicesPage.qml index e02cf16..5ef0273 100644 --- a/desktop/modules/deckit/DeckItServicesPage.qml +++ b/desktop/modules/deckit/DeckItServicesPage.qml @@ -32,6 +32,8 @@ Column { placeholder: col.st.placeholder("llm", "url") } Setting { store: col.st; section: "k1c"; key: "url"; label: "K1C Moonraker" placeholder: "http://ip:7125"; hint: "The printer's Moonraker address, for the K1C tab. Empty: no printer." } + Setting { store: col.st; section: "xbox"; key: "client_id"; label: "Xbox client id" + placeholder: "Azure app client id"; hint: "Your Azure app registration, for the Xbox tab. Sign in on the tab." } Setting { store: col.st; section: "sbbuilder"; key: "host"; label: "Build VM host" placeholder: col.st.placeholder("sbbuilder", "host"); hint: "ssh host alias; runs sbb-remote jobs there." } } diff --git a/desktop/modules/deckit/Modules.js b/desktop/modules/deckit/Modules.js index 7bfbdbc..7c345cf 100644 --- a/desktop/modules/deckit/Modules.js +++ b/desktop/modules/deckit/Modules.js @@ -14,10 +14,10 @@ // deck-it's [modules] split for the pages: the ones with a tab of their own, // and the rest, which only feed the Dashboard. A module deck-it adds later // lands with the Dashboard ones until it is listed here. -var TABS = ["windows", "obs", "k1c", "assistant"]; +var TABS = ["windows", "obs", "k1c", "assistant", "vm", "xbox"]; var NAMES = { stats: "System", music: "Music", llm: "LLM usage", tablet: "Tablet", sbbuilder: "Build VM", actions: "Action icons", windows: "Windows", - obs: "OBS", k1c: "K1C printer", assistant: "Assistant" }; + obs: "OBS", k1c: "K1C printer", assistant: "Assistant", vm: "VMs", xbox: "Xbox" }; function tabs(all) { return all.filter(m => TABS.includes(m)); } function parts(all) { return all.filter(m => !TABS.includes(m)); } diff --git a/desktop/modules/fonts/Fonts.js b/desktop/modules/fonts/Fonts.js index 5b7d303..d42c784 100644 --- a/desktop/modules/fonts/Fonts.js +++ b/desktop/modules/fonts/Fonts.js @@ -12,9 +12,10 @@ // Pure helpers for the fonts page, tested by test_fonts.js under node. // -// The model is fonts.json: {base, override}. base is one pixel size for the -// whole desktop; override maps a system ("qt") or one entry of a section -// ("rofi:kf-launcher-entry") to its own pixel size. Everything is stored in +// The model is fonts.json: {base, override, family}. base is one pixel size +// for the whole desktop; override maps a system ("qt") or one entry of a +// section ("rofi:kf-launcher-entry") to its own pixel size; family maps a +// font slot no other config holds (FAMILIES) to an installed family. Everything is stored in // px and converted where a system wants points: at scale 1 Wayland's logical // DPI is 96 (gtk-xft-dpi reads 98304, 96 * 1024), so px = pt * 96 / 72. @@ -30,6 +31,14 @@ const SYSTEMS = [ { id: "gtk", label: "GTK", unit: "pt", where: "gtk-3.0 and gtk-4.0 settings.ini, .gtkrc-2.0, gsettings", when: "at once for GTK 3 and 4" }, { id: "kitty", label: "kitty", unit: "pt", where: "kitty.conf, through an include", when: "at once" }, { id: "groupbar", label: "Hyprland groupbar", unit: "px", where: "keystone.lua, group:groupbar:font_size", when: "at once" }, + { id: "deckit", label: "deck-it", unit: "px", where: "deck-it's theme.css, from fonts.json", when: "on the tablet within 5 s" }, +]; + +// deck-it's dim cover clock, sized from deck-it's text as deck.css designs +// it (8rem, 1.6rem); an override is "deckit:clock" or "deckit:date". +const DECKIT_CLOCK = [ + { id: "clock", label: "Clock time", ratio: 8 }, + { id: "date", label: "Clock date", ratio: 1.6 }, ]; // A section is a set of designed sizes that scale together: rofi's fonts, @@ -40,6 +49,12 @@ const SECTIONS = [ { id: "hyprlock", label: "hyprlock", unit: "pt", when: "next lock" }, ]; +// Font families set here, read by their program from fonts.json itself. +const FAMILIES = [ + { id: "deckit-clock", label: "deck-it clock", where: "the time on the tablet's dim cover" }, + { id: "deckit-date", label: "deck-it date", where: "the date under it" }, +]; + // A system's or a section's size in px. function size(m, id) { const o = m.override[id]; @@ -62,13 +77,21 @@ function withOverride(m, id, px) { const o = {}; for (const k in m.override) if (k !== id) o[k] = m.override[k]; if (px !== null) o[id] = px; - return { base: m.base, override: o }; + return { base: m.base, override: o, family: m.family }; +} + +// The model with family id set to name, or unset when name is empty. +function withFamily(m, id, name) { + const f = {}; + for (const k in m.family) if (k !== id) f[k] = m.family[k]; + if (name.trim() !== "") f[id] = name.trim(); + return { base: m.base, override: m.override, family: f }; } function parseModel(text) { try { const j = JSON.parse(text); - if (typeof j.base === "number") return { base: j.base, override: j.override || {} }; + if (typeof j.base === "number") return { base: j.base, override: j.override || {}, family: j.family || {} }; } catch (e) {} return null; } @@ -78,7 +101,7 @@ function parseModel(text) { // from it is an override at its current size. Kept to 0.01px: at 0.1, an // 11pt body stored as 14.7px scaled rofi's 72pt glyph to 72.2. function seed(now) { - const m = { base: 16, override: {} }; + const m = { base: 16, override: {}, family: {} }; for (const id in now) if (now[id] !== null && Math.abs(now[id] - 16) > 0.05) m.override[id] = Math.round(now[id] * 100) / 100; return m; } diff --git a/desktop/modules/fonts/FontsModule.qml b/desktop/modules/fonts/FontsModule.qml index 016d85d..76f6ae9 100644 --- a/desktop/modules/fonts/FontsModule.qml +++ b/desktop/modules/fonts/FontsModule.qml @@ -33,7 +33,7 @@ Module { settings: true group: "Appearance" dirty: fm.touched - keywords: ["font", "size", "text", "px", "pt", "qt6ct", "gtk", "kitty", "rofi", "hyprlock", "groupbar", "scale"] + keywords: ["font", "size", "text", "px", "pt", "qt6ct", "gtk", "kitty", "rofi", "hyprlock", "groupbar", "scale", "family", "deck-it", "clock", "date", "tablet"] readonly property string home: Quickshell.env("HOME") readonly property string config: Quickshell.env("XDG_CONFIG_HOME") || fm.home + "/.config" @@ -76,7 +76,7 @@ Module { } readonly property var saved: { fm.version; return F.parseModel(fm.texts.model ?? "") ?? F.seed(fm.now()); } - property var draft: ({ base: 16, override: {} }) + property var draft: ({ base: 16, override: {}, family: {} }) // A reload replaces the draft only while it holds no edits. onSavedChanged: if (!fm.touched) fm.draft = fm.saved property bool touched: false @@ -85,6 +85,7 @@ Module { function setBase(px) { fm.touched = true; fm.draft = { base: px, override: fm.draft.override }; } function setOverride(id, px) { fm.touched = true; fm.draft = F.withOverride(fm.draft, id, px); } + function setFamily(id, name) { fm.touched = true; fm.draft = F.withFamily(fm.draft, id, name); } function discard() { fm.touched = false; fm.draft = fm.saved; fm.error = ""; } function refresh() { diff --git a/desktop/modules/fonts/FontsPage.qml b/desktop/modules/fonts/FontsPage.qml index fd2e672..1a58b11 100644 --- a/desktop/modules/fonts/FontsPage.qml +++ b/desktop/modules/fonts/FontsPage.qml @@ -11,6 +11,7 @@ import QtQuick import "../.." +import "../appearance" as A import "Fonts.js" as F // The base size, then a row per system and per section entry: what it is, @@ -27,9 +28,9 @@ Column { spacing: 8 - function clamp(px) { return Math.max(page.minPx, Math.min(page.maxPx, px)); } + function clamp(px, max) { return Math.max(page.minPx, Math.min(max, px)); } // A step of 1 in the row's own unit, so a pt row moves by whole points. - function step(px, unit, d) { return page.clamp(unit === "pt" ? F.toPx(Math.round(F.toPt(px)) + d) : Math.round(px) + d); } + function step(px, unit, d, max) { return page.clamp(unit === "pt" ? F.toPx(Math.round(F.toPt(px)) + d) : Math.round(px) + d, max); } component Small: Text { color: Theme.subtext @@ -60,13 +61,14 @@ Column { property real px: 16 property string unit: "px" property bool enabled: true + property real max: page.maxPx signal changed(real px) spacing: 6 opacity: st.enabled ? 1 : 0.45 - Button { text: "−"; enabled: st.enabled; onClicked: st.changed(page.step(st.px, st.unit, -1)) } + Button { text: "−"; enabled: st.enabled; onClicked: st.changed(page.step(st.px, st.unit, -1, st.max)) } Unit { text: F.round(st.px) + " px"; own: st.unit === "px" } Unit { text: F.round(F.toPt(st.px)) + " pt"; own: st.unit === "pt" } - Button { text: "+"; enabled: st.enabled; onClicked: st.changed(page.step(st.px, st.unit, 1)) } + Button { text: "+"; enabled: st.enabled; onClicked: st.changed(page.step(st.px, st.unit, 1, st.max)) } } // A system or a section entry. id is its override key; inherited is the @@ -79,6 +81,7 @@ Column { property string unit: "px" required property real inherited property string follows: "base" + property real max: page.maxPx readonly property bool own: page.m.override[sr.key] !== undefined readonly property real px: sr.own ? page.m.override[sr.key] : sr.inherited objectName: "font:" + sr.key @@ -116,6 +119,7 @@ Column { anchors.verticalCenter: parent.verticalCenter px: sr.px unit: sr.unit + max: sr.max enabled: sr.own onChanged: px => page.fonts.setOverride(sr.key, px) } @@ -147,7 +151,7 @@ Column { Heading { text: "Systems" } Repeater { - model: F.SYSTEMS.filter(s => s.id !== "groupbar") + model: F.SYSTEMS.filter(s => s.id !== "groupbar" && s.id !== "deckit") SizeRow { required property var modelData key: modelData.id @@ -166,6 +170,26 @@ Column { inherited: page.m.base } + Heading { text: "deck-it" } + SizeRow { + key: "deckit" + title: "deck-it text" + detail: "The tablet page's rem. deck-it reads fonts.json itself; seen on the tablet within 5 s." + inherited: page.m.base + } + Repeater { + model: F.DECKIT_CLOCK + SizeRow { + required property var modelData + key: "deckit:" + modelData.id + title: modelData.label + detail: "On the dim cover, designed at " + modelData.ratio + "× deck-it's text." + follows: "deck-it" + max: 400 + inherited: F.size(page.m, "deckit") * modelData.ratio + } + } + // rofi and hyprlock: the section's size, which is its body text, then // each entry at its designed ratio to the body. Repeater { @@ -209,4 +233,41 @@ Column { } } } + + // Families no other config holds; the program reads fonts.json itself. + Heading { text: "Families" } + Small { + x: 8 + width: parent.width - 16 + text: "A family installed on this PC, as fc-list names it. Empty keeps the program's own font." + } + Repeater { + model: F.FAMILIES + Item { + id: fr + required property var modelData + objectName: "font:" + fr.modelData.id + width: page.width + height: 48 + Column { + anchors { left: parent.left; leftMargin: 8; right: field.left; rightMargin: 12; verticalCenter: parent.verticalCenter } + Text { + text: fr.modelData.label + color: Theme.text + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 } + } + Small { width: parent.width; text: fr.modelData.where } + } + A.Field { + id: field + anchors { right: parent.right; rightMargin: 8; verticalCenter: parent.verticalCenter } + width: 240 + value: page.m.family[fr.modelData.id] ?? "" + placeholder: "program's font" + // Every keystroke, not editingFinished: a click on Save takes no + // focus, so a name typed and saved would never reach the draft. + onValueChanged: if (value.trim() !== (page.m.family[fr.modelData.id] ?? "")) page.fonts.setFamily(fr.modelData.id, value) + } + } + } } diff --git a/desktop/modules/fonts/README.md b/desktop/modules/fonts/README.md index b887060..c3e2232 100644 --- a/desktop/modules/fonts/README.md +++ b/desktop/modules/fonts/README.md @@ -4,7 +4,8 @@ One pixel size for the desktop, in the settings window under Appearance > Fonts, and an override wherever a system needs its own. Saved as `~/.config/keystone/fonts.json`: - { "base": 16, "override": { "qt": 18.67, "rofi:kf-launcher-entry": 22 } } + { "base": 16, "override": { "qt": 18.67, "rofi:kf-launcher-entry": 22 }, + "family": { "deckit-clock": "Some Font" } } Everything is stored in px. At scale 1 Wayland's logical DPI is 96 (`gtk-xft-dpi` reads 98304, 96 * 1024), so a point is 4/3 of a pixel and @@ -17,6 +18,7 @@ Everything is stored in px. At scale 1 Wayland's logical DPI is 96 | GTK | gtk-3.0 and gtk-4.0 `settings.ini`, `.gtkrc-2.0`, gsettings `font-name` | pt | at once for GTK 3 and 4 | | kitty | `~/.config/keystone/kitty-fonts.conf`, included last by `kitty.conf`; SIGUSR1 reloads | pt | at once | | Hyprland groupbar | `group:groupbar:font_size` line in `keystone.lua` | px | at once | +| deck-it | reads `fonts.json` itself into its `theme.css`: `deckit`, and the dim cover's `deckit:clock` and `deckit:date` (8 and 1.6 times `deckit` unless set) | px | on the tablet within 5 s | | rofi | `~/.config/keystone/rofi-fonts.rasi`, imported by udt's `common.rasi` | pt | next open | | hyprlock | `~/.config/keystone/hyprlock-fonts.conf`, sourced by `hyprlock.conf` | pt | next lock | @@ -39,7 +41,11 @@ With no `fonts.json`, the page starts from what the files say: base 16 px, and an override for every system at its current size, so the first save changes nothing. -Not handled: font families; the hard-coded `pixelSize` values in the shells +`family` names a font for a slot no other config holds, read by its +program from `fonts.json` itself: `deckit-clock` and `deckit-date`, the +time and the date on deck-it's dim cover. Empty leaves the program's own. + +Not handled: the families of the systems above; the hard-coded `pixelSize` values in the shells (21 of them), which do not follow `Theme.fontSize`; and a `keystone.lua` save from this page and the Options page at the same moment, which can drop one line. diff --git a/desktop/modules/fonts/test_fonts.js b/desktop/modules/fonts/test_fonts.js index 947bd42..773da64 100644 --- a/desktop/modules/fonts/test_fonts.js +++ b/desktop/modules/fonts/test_fonts.js @@ -17,7 +17,7 @@ const fs = require("fs"); const assert = require("assert"); const src = fs.readFileSync(__dirname + "/Fonts.js", "utf8").replace(/^\.pragma library$/m, ""); -const F = new Function(src + "\nreturn { size, entryPx, withOverride, parseModel, seed, qtPt, gtkPt, kittyPt, " +const F = new Function(src + "\nreturn { DECKIT_CLOCK, size, entryPx, withOverride, withFamily, parseModel, seed, qtPt, gtkPt, kittyPt, " + "rofiEntries, hyprlockEntries, setQt, setGtk, gtkFamily, kittyFile, rofiFile, hyprlockFile };")(); const qt = '[Fonts]\nfixed="Inconsolata Nerd Font Mono,14,-1,5,400"\ngeneral="Noto Sans,14,-1,5,400,Regular"\n'; @@ -36,11 +36,16 @@ assert.strictEqual(F.setGtk(gtk2, 12), 'gtk-font-name="Noto Sans, 12"\n'); // The first save changes nothing: what differs from 16px is an override. const m = F.seed({ quickshell: 16, qt: 14 * 4 / 3, gtk: 10 * 4 / 3, kitty: 20 }); -assert.deepStrictEqual(m, { base: 16, override: { qt: 18.67, gtk: 13.33, kitty: 20 } }); +assert.deepStrictEqual(m, { base: 16, override: { qt: 18.67, gtk: 13.33, kitty: 20 }, family: {} }); assert.strictEqual(F.size(m, "quickshell"), 16); assert.strictEqual(F.size(F.withOverride(m, "qt", null), "qt"), 16); assert.strictEqual(F.parseModel("nope"), null); assert.deepStrictEqual(F.parseModel(JSON.stringify(m)), m); +// A family survives a size edit; an empty one is dropped. +const fm = F.withOverride(F.withFamily(m, "deckit-date", " Sedgwick Ave "), "qt", 20); +assert.deepStrictEqual(fm.family, { "deckit-date": "Sedgwick Ave" }); +assert.deepStrictEqual(F.withFamily(fm, "deckit-date", "").family, {}); +assert.deepStrictEqual(F.parseModel('{"base": 16}').family, {}); const rasi = ['* { font: var(kf-common-font, "Noto Sans 11"); }', 'entry { font: var(kf-launcher-entry, "Noto Sans Bold 15"); }', @@ -64,4 +69,8 @@ const sr = F.seed({ rofi: 11 * 4 / 3 }); assert.ok(F.rofiFile(sr, [{ name: "kf-a", family: "M", pt: 11 }, { name: "kf-b", family: "M", pt: 72 }]).includes('kf-b: "M 72"')); assert.strictEqual(F.kittyFile(m).split("\n")[1], "font_size 15"); +// The clock follows deck-it's text at its designed ratio. +const d = { base: 16, override: { deckit: 20 }, family: {} }; +assert.strictEqual(F.size(d, "deckit") * F.DECKIT_CLOCK[0].ratio, 160); + console.log("ok"); diff --git a/desktop/modules/status/README.md b/desktop/modules/status/README.md index ea069d6..15bb122 100644 --- a/desktop/modules/status/README.md +++ b/desktop/modules/status/README.md @@ -1,9 +1,10 @@ # status -Desktop modes as state: `dnd`, `presentation`, `nolock` and `quiet`, owned by -the `Status` singleton and stored as files under `$XDG_RUNTIME_DIR`. A fifth, -`status.gaming`, is written only by the shell's game detector; it is not a -mode `statusctl` exposes. +Desktop modes as state: `dnd`, `presentation`, `nolock`, `quiet` and `nolamp`, owned by +the `Status` singleton and stored as files under `$XDG_RUNTIME_DIR`. Two more, +`status.gaming`, written only by the shell's game detector, and `status.xbox`, +written only by deck-it while the Xbox runs a game, are not modes `statusctl` +exposes; either one turns presentation on. ## The files are the interface @@ -11,7 +12,9 @@ mode `statusctl` exposes. $XDG_RUNTIME_DIR/status.presentation $XDG_RUNTIME_DIR/status.nolock $XDG_RUNTIME_DIR/status.quiet + $XDG_RUNTIME_DIR/status.nolamp $XDG_RUNTIME_DIR/status.gaming + $XDG_RUNTIME_DIR/status.xbox Each holds `0` or `1`; a missing file means off. That directory is tmpfs, so a reboot resets every mode and there is no cleanup code. A shell restart does @@ -63,7 +66,7 @@ asks `statusctl quiet get` and plays nothing on a 1. `~/bin/notify-sound` is a symlink to the repo copy, like `statusctl`. notify-sound claude Claude Code's Notification hook - notify-sound <event> opencode-notifier's command hook + notify-sound <event> <session> opencode-notifier's command hook The opencode notifier runs its command for every event, `session_started` and `user_message` included, so an argument with no sound plays nothing; only @@ -71,6 +74,12 @@ The opencode notifier runs its command for every event, `session_started` and are off in `opencode-notifier.json`, and it rereads that file on every event, so neither change needs an opencode restart. +`nolamp` keeps the agent lamp (the sibling agent-lamp repo) dark. The shell +does nothing with it: agent-lamp's renderer reads the file each second and +restores the bulb while it is 1, keeping the agents' states for when it +turns off. `notify-sound` forwards the opencode notifier's two arguments +(`<event> <session>`) to `agent-lamp`, before the quiet check. + ## Game detection Presentation is set automatically while a game runs, so a fullscreen game does @@ -110,8 +119,9 @@ without touching the manual half, so a bar widget would otherwise read class with its own icon, and `toggle` is refused while it holds: the detector reasserts the file within its poll, so the write would not stick. `set` is still allowed, since the manual half is worth setting for when the game exits. -The watch therefore follows `status.gaming` as well as its own file, and emits -only on a real change so an unchanged rewrite draws nothing. +The watch therefore follows `status.gaming` and `status.xbox` as well as its +own file, and emits only on a real change so an unchanged rewrite draws +nothing. `status.xbox` counts as gaming in all of this. ## The checks diff --git a/desktop/modules/status/StatusPage.qml b/desktop/modules/status/StatusPage.qml index 4741bcc..5a00ded 100644 --- a/desktop/modules/status/StatusPage.qml +++ b/desktop/modules/status/StatusPage.qml @@ -61,6 +61,20 @@ Column { color: Qt.alpha(Theme.text, 0.08) } + StatusRow { + width: page.width + mode: "nolamp" + label: "No lamp" + description: "Keeps the agent lamp dark, for a film. Agents still notify on screen." + value: Status.nolamp + } + + Rectangle { + width: page.width + height: 1 + color: Qt.alpha(Theme.text, 0.08) + } + LockRow { width: page.width } diff --git a/desktop/modules/status/notify-sound b/desktop/modules/status/notify-sound index c028b3e..36efaaa 100755 --- a/desktop/modules/status/notify-sound +++ b/desktop/modules/status/notify-sound @@ -15,7 +15,7 @@ # silence both. Their popups do not come through here and are unaffected. # # notify-sound claude Claude Code's Notification hook -# notify-sound <opencode-notifier event> the notifier's command hook +# notify-sound <event> <session> the opencode notifier's command hook # # An argument with no sound plays nothing. That is deliberate: the opencode # notifier runs its command for every event, session_started and @@ -24,6 +24,14 @@ set -u here="$(dirname "$(readlink -f "$0")")" + +# opencode's notifier passes its event and session id: forward them to the +# agent lamp, before the quiet check, since quiet mutes sound and not light. +# Claude Code passes one argument and has hooks of its own for the lamp. +if [[ $# -eq 2 ]] && command -v agent-lamp >/dev/null; then + agent-lamp "$1" "$2" </dev/null >/dev/null 2>&1 & +fi + [[ "$("$here/statusctl" quiet get)" == "1" ]] && exit 0 dir="${NOTIFY_SOUND_DIR:-$HOME/Music/notify}" diff --git a/desktop/modules/status/statusctl b/desktop/modules/status/statusctl index 718ee39..69dc5a1 100755 --- a/desktop/modules/status/statusctl +++ b/desktop/modules/status/statusctl @@ -25,7 +25,7 @@ set -u -MODES="dnd presentation nolock quiet" +MODES="dnd presentation nolock quiet nolamp" DIR="${XDG_RUNTIME_DIR:-/tmp}" usage() { @@ -83,17 +83,22 @@ tooltip() { case "$1" in activated) printf '%s: on' "$mode" ;; deactivated) printf '%s: off' "$mode" ;; - gaming) printf '%s: on (auto: game or call)' "$mode" ;; + gaming) printf '%s: on (auto: game, call or Xbox)' "$mode" ;; esac } -# The shell's game detector owns status.gaming and presentation is the OR of -# the two, so the CLI has to read it to agree with the shell. It is not a mode -# in MODES: nothing here may write it, and only presentation is affected. +# The shell's game detector owns status.gaming, deck-it owns status.xbox (a +# game on the Xbox), and presentation is the OR of them and its own file, so +# the CLI has to read both to agree with the shell. Neither is a mode in +# MODES: nothing here may write them, and only presentation is affected. gaming_on() { - local v="" - [[ -e "$DIR/status.gaming" ]] && v="$(tr -d '[:space:]' < "$DIR/status.gaming" 2>/dev/null)" - [[ "$v" == "1" ]] + local f v + for f in status.gaming status.xbox; do + v="" + [[ -e "$DIR/$f" ]] && v="$(tr -d '[:space:]' < "$DIR/$f" 2>/dev/null)" + [[ "$v" == "1" ]] && return 0 + done + return 1 } # A missing file is the off state, not a distinct condition: read_mode already @@ -158,14 +163,14 @@ case "$action" in exec 3< <(inotifywait -q -m -e create,close_write,moved_to,delete --format '%f' "$DIR" 2>/dev/null) watcher=$! trap 'kill "$watcher" 2>/dev/null' EXIT TERM INT - # Presentation also follows status.gaming, so a game starting or - # ending redraws the widget. Emitting only on a real change keeps a + # Presentation also follows status.gaming and status.xbox, so a game + # starting or ending redraws the widget. Emitting only on a real change keeps a # write of an unchanged value from firing a duplicate line. last="$(state_now)" while read -r changed <&3; do case "$changed" in "status.$mode") ;; - status.gaming) [[ "$mode" == "presentation" ]] || continue ;; + status.gaming|status.xbox) [[ "$mode" == "presentation" ]] || continue ;; *) continue ;; esac now="$(state_now)" diff --git a/desktop/modules/status/test-notify-sound.sh b/desktop/modules/status/test-notify-sound.sh index 9571d4c..d70893f 100755 --- a/desktop/modules/status/test-notify-sound.sh +++ b/desktop/modules/status/test-notify-sound.sh @@ -13,7 +13,8 @@ # # The one runnable check for notify-sound. A fake paplay first on PATH # records what it was asked to play, and XDG_RUNTIME_DIR is a temporary -# directory, so no sound plays and the live quiet mode is untouched. +# directory, so no sound plays and the live quiet mode is untouched. A fake +# agent-lamp records its arguments, so the real lamp is never driven. # # Usage: ./test-notify-sound.sh (exit 0 = all passed) @@ -27,6 +28,8 @@ export NOTIFY_SOUND_DIR="/sounds" mkdir "$tmp/bin" printf '#!/bin/sh\nprintf "%%s\\n" "$1" >> "%s/played"\n' "$tmp" > "$tmp/bin/paplay" chmod +x "$tmp/bin/paplay" +printf '#!/bin/sh\nprintf "%%s %%s\\n" "$1" "$2" >> "%s/lamp"\n' "$tmp" > "$tmp/bin/agent-lamp" +chmod +x "$tmp/bin/agent-lamp" export PATH="$tmp/bin:$PATH" pass=0 @@ -64,5 +67,15 @@ check "quiet mutes permission" "" "$(play permission)" "$here/statusctl" quiet set 0 check "quiet off plays again" "/sounds/claude-attention.opus" "$(play claude)" +# Two arguments (opencode's event and session) are forwarded to agent-lamp, +# even in quiet mode; Claude's single argument never is. +rm -f "$tmp/lamp" +"$here/notify-sound" claude +"$here/notify-sound" permission ses1 +"$here/statusctl" quiet set 1 +"$here/notify-sound" complete ses2 +sleep 0.2 +check "lamp forward" "permission ses1|complete ses2" "$(paste -sd'|' "$tmp/lamp" 2>/dev/null)" + printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]] diff --git a/desktop/modules/status/test-statusctl.sh b/desktop/modules/status/test-statusctl.sh index 170101c..0c51968 100755 --- a/desktop/modules/status/test-statusctl.sh +++ b/desktop/modules/status/test-statusctl.sh @@ -149,11 +149,34 @@ kill "$watcher5" 2>/dev/null wait "$watcher5" 2>/dev/null check "first write, created by link, redraws" "1" "$(grep -c '"class": *"gaming"' "$out5")" +# deck-it writes status.xbox while the Xbox runs a game; it holds +# presentation on the same way, so the watch follows it too. +rm -f "$tmp/status.gaming" "$tmp/status.presentation" +out6="$tmp/watch6.out" +"$ctl" presentation watch > "$out6" 2>/dev/null & +watcher6=$! +sleep 0.3 +printf '1\n' > "$tmp/status.xbox.tmp" +mv -f "$tmp/status.xbox.tmp" "$tmp/status.xbox" +sleep 0.5 +kill "$watcher6" 2>/dev/null +wait "$watcher6" 2>/dev/null +check "xbox game redraws as gaming" "1" "$(grep -c '"class": *"gaming"' "$out6")" +"$ctl" presentation toggle 2>/dev/null +check "toggle refused while the xbox plays" "1" "$?" +rm -f "$tmp/status.xbox" + # quiet is a plain mode like dnd. "$ctl" quiet set 1 check "quiet set 1" "1" "$("$ctl" quiet get)" "$ctl" quiet toggle check "quiet toggle from 1" "0" "$("$ctl" quiet get)" +# nolamp keeps agent-lamp's bulb dark; a plain mode like quiet. +"$ctl" nolamp set 1 +check "nolamp set 1" "1" "$("$ctl" nolamp get)" +"$ctl" nolamp toggle +check "nolamp toggle from 1" "0" "$("$ctl" nolamp get)" + printf '\n%d passed, %d failed\n' "$pass" "$fail" [[ "$fail" -eq 0 ]] |
