From fbdfcd4e2d54dbc3f8767ba3ef97667802a7949b Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 19 Oct 2026 09:53:45 +0200 Subject: desktop: notification sounds on the settings page A sound per urgency chosen with the widget file dialog, previewed with pw-play, and the sound theme for apps' sound-name hints. Save writes the theme to gsettings as well, and the page reads gsettings back on every open so a change made elsewhere is shown, with a button to adopt it, rather than overwritten. Co-Authored-By: Claude Opus 5.5 --- .../modules/notifications/NotificationsModule.qml | 48 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'desktop/modules/notifications/NotificationsModule.qml') diff --git a/desktop/modules/notifications/NotificationsModule.qml b/desktop/modules/notifications/NotificationsModule.qml index 01eea18..7a113df 100644 --- a/desktop/modules/notifications/NotificationsModule.qml +++ b/desktop/modules/notifications/NotificationsModule.qml @@ -27,6 +27,11 @@ Module { property var draft: Notify.config property string notice: "" + // The installed sound themes (directories with an index.theme), and the + // system theme as gsettings has it, "" when unreadable. Both reread on + // every refresh, so a change made outside the page shows. + property var themes: [] + property string systemTheme: "" dirty: JSON.stringify(nm.draft) !== JSON.stringify(Notify.config) readonly property bool valid: [nm.draft.liveCap, nm.draft.historyCap].every(v => v >= 1 && v <= 100) @@ -35,14 +40,18 @@ Module { // edited. The window calls refresh() on every open, which covers the // value a save leaves behind. Not over unsaved edits. function follow() { nm.draft = Qt.binding(() => Notify.config); } - function refresh() { if (!nm.dirty) nm.follow(); } + function refresh() { + if (!nm.dirty) nm.follow(); + nm.themeLister.running = false; nm.themeLister.running = true; + nm.gsGet.running = false; nm.gsGet.running = true; + } function discard() { nm.follow(); nm.notice = ""; } function edit(patch) { nm.draft = Object.assign({}, nm.draft, patch); } // Unknown keys in the file survive, including inside timeouts and // balloons, which are merged one level down. The text goes on stdin to // cat (the notes pattern: the exit code is the outcome); 1 is the write, - // 2 the reload, so a stopped daemon reads as saved-but-not-applied. + // 3 the gsettings theme, 2 the reload, so a stopped daemon reads as saved-but-not-applied. // Written in onStarted, then stdinEnabled cleared to give cat its EOF: // the sequence notes' bodyWriter uses (NotesModule.qml). function save() { @@ -52,7 +61,9 @@ Module { const out = Object.assign({}, raw, nm.draft, { timeouts: Object.assign({}, obj(raw.timeouts), nm.draft.timeouts), balloons: Object.assign({}, obj(raw.balloons), nm.draft.balloons), + sounds: Object.assign({}, obj(raw.sounds), nm.draft.sounds), }); + nm.saver.theme = nm.draft.soundTheme; nm.saver.data = JSON.stringify(out, null, 2) + "\n"; nm.saver.stdinEnabled = true; nm.saver.running = false; @@ -60,15 +71,38 @@ Module { } property Process saver: Process { property string data: "" - command: ["sh", "-c", 'mkdir -p "$(dirname "$1")" && cat > "$1" || exit 1; notifyctl reload || exit 2', - "sh", Notify.configPath] + property string theme: "" + command: ["sh", "-c", + 'mkdir -p "$(dirname "$1")" && cat > "$1" || exit 1; ' + + 'gsettings set org.gnome.desktop.sound theme-name "$2" || g=3; ' + + 'notifyctl reload || exit 2; exit ${g:-0}', + "sh", Notify.configPath, nm.saver.theme] onStarted: { nm.saver.write(nm.saver.data); nm.saver.stdinEnabled = false; } - onExited: code => nm.notice = code === 0 ? "saved" - : code === 2 ? "saved; notifyd not reachable, it reads the file at its next start" - : "could not write " + Notify.configPath + onExited: code => { + nm.notice = code === 0 ? "saved" + : code === 2 ? "saved; notifyd not reachable, it reads the file at its next start" + : code === 3 ? "saved; the system sound theme could not be set" + : "could not write " + Notify.configPath; + nm.gsGet.running = false; nm.gsGet.running = true; + } + } + property Process themeLister: Process { + command: ["sh", "-c", 'find "$HOME/.local/share/sounds" /usr/share/sounds -mindepth 2 -maxdepth 2 -name index.theme 2>/dev/null'] + stdout: StdioCollector { + onStreamFinished: nm.themes = [...new Set(text.split("\n").filter(l => l) + .map(l => l.split("/").slice(-2)[0]))].sort() + } + } + // gsettings prints the string quoted: 'freedesktop'. + property Process gsGet: Process { + command: ["gsettings", "get", "org.gnome.desktop.sound", "theme-name"] + stdout: StdioCollector { + onStreamFinished: nm.systemTheme = text.trim().replace(/^'(.*)'$/, "$1") + } + onExited: code => { if (code !== 0) nm.systemTheme = ""; } } page: Component { -- cgit v1.2.3