Sounds actually audible: unmute the event stream, Konsole bell via notifications, chime for every app notification

- The WirePlumber 'Notification' role stream was saved muted, silencing every
  theme sound except Plasma's volume tick; dot sounds build/test/notify now
  unmutes it at 100% (ensure_event_stream).
- Konsole profiles: BellMode=1 (notification) — the default system beep is silent on Wayland.
- notification-sounds: user service watching Notify calls via dbus-monitor; plays
  message-new-instant for notifications without their own sound (skips
  KNotification events, sound hints, and apps with in-app sounds: Telegram, Vesktop).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013UzjWUxheYfqqjWGH7Ktmc
This commit is contained in:
Ziad ArafatandClaude Opus 5.5 committed 2026-10-30 15:21:56 -06:00
1 parent 3c0fd6d632
commit 195d9d6c6f
7 files changed
+178 -3

No files matched your search

+32 -1
View File
@@ -420,6 +420,34 @@ sound_output_info() {
wpctl status 2>/dev/null | sed -n '/Sinks:/,/Sources:/p' | grep -E "MUTED|vol: 0\.00" | sed 's/^[ │*]*/ muted sink: /'
}
# All theme/notification sounds share one "event"/Notification role stream whose
# mute + volume WirePlumber remembers. Plasma's mixer can mute it ("Notification
# Sounds"), which silences everything except the volume tick. Unmute it at 100%.
ensure_event_stream() {
have pactl || return 0
local state="$HOME/.local/state/wireplumber/stream-properties"
if [ -f "$state" ] && ! grep -q 'media.role:Notification=.*"mute":true' "$state" \
&& ! grep -qE 'media.role:Notification=.*"volume":0\.[0-8]' "$state"; then
return 0
fi
local f; f="$(ls "$HOME"/.local/share/sounds/portal2/stereo/bell.* 2>/dev/null | head -1)"
[ -n "$f" ] || return 0
paplay --property=media.role=event --property=application.name=dot-sounds "$f" & local p=$!
local id=""
for _ in $(seq 20); do
id="$(pactl -f json list sink-inputs 2>/dev/null | jq -r '.[] | select(.properties["application.name"] == "dot-sounds") | .index' | head -1)"
[ -n "$id" ] && break; sleep 0.1
done
if [ -n "$id" ]; then
pactl set-sink-input-mute "$id" 0
pactl set-sink-input-volume "$id" 100%
ok "notification sounds stream unmuted at 100%"
else
warn "couldn't catch the event stream to unmute it; unmute 'Notification Sounds' in the volume applet"
fi
wait $p 2>/dev/null || true
}
play_event() { # freedesktop sound name
if have canberra-gtk-play; then
canberra-gtk-play -i "$1" -d "dot sounds test" 2>/dev/null
@@ -433,16 +461,19 @@ cmd_sounds() {
case "${1:-build}" in
build)
have build-sound-theme || die "build-sound-theme missing (full profile)"
shift || true; build-sound-theme "$@" ;;
shift || true; build-sound-theme "$@"
ensure_event_stream ;;
test)
# dot sounds test [event...] — plays each theme sound with its name
sound_output_info
ensure_event_stream
local events=("${@:2}")
[ ${#events[@]} -gt 0 ] || mapfile -t events < <(ls "$HOME/.local/share/sounds/portal2/stereo" | sed 's/\.[^.]*$//' | sort)
for e in "${events[@]}"; do printf ' ♪ %s\n' "$e"; play_event "$e"; sleep 0.4; done ;;
notify)
# A real desktop notification, the same path Chrome/Telegram/etc. take.
sound_output_info
ensure_event_stream
notify-send -a "dot sounds" "Aperture Science" "This was a triumph. (If you heard a ding, app notifications have sound.)" ;;
*) die "usage: dot sounds [build|test [event...]|notify]" ;;
esac
+3
View File
@@ -7,3 +7,6 @@ Command=zsh
Environment=TERM=xterm-256color,COLORTERM=truecolor
Name=Dark
Parent=FALLBACK/
[Terminal Features]
BellMode=1
+3
View File
@@ -7,3 +7,6 @@ Command=zsh
Environment=TERM=xterm-256color,COLORTERM=truecolor
Name=Light
Parent=FALLBACK/
[Terminal Features]
BellMode=1
+3
View File
@@ -7,3 +7,6 @@ Environment=TERM=xterm-256color,COLORTERM=truecolor
InheritContainerContext=true
Name=etv
Parent=FALLBACK/
[Terminal Features]
BellMode=1
+3
View File
@@ -7,3 +7,6 @@ Environment=TERM=xterm-256color,COLORTERM=truecolor
InheritContainerContext=false
Name=general
Parent=FALLBACK/
[Terminal Features]
BellMode=1
+30 -2
View File
@@ -1,5 +1,8 @@
{ config, lib, ... }:
{ config, lib, pkgs, ... }:
let
notification-sounds = pkgs.writeShellScriptBin "notification-sounds" ''
exec ${pkgs.python3}/bin/python -u ${../../scripts/notification-sounds.py} "$@"
'';
# KNotification reads per-user overrides from ~/.config/<app>.notifyrc. Groups are
# literally "[Event/<id>]"; plasma-manager treats "/" as nesting, hence "Event\\/".
# Sound names resolve through the active theme (portal2, see `dot sounds`),
@@ -9,6 +12,31 @@ let
sound = event "Sound";
in
lib.mkIf config.dotfiles.gui {
home.packages = [ notification-sounds ];
# Sounds for app notifications that don't bring their own (see scripts/notification-sounds.py).
systemd.user.services.notification-sounds = {
Unit = {
Description = "Play a sound for desktop notifications without one";
After = [ "graphical-session.target" ];
PartOf = [ "graphical-session.target" ];
};
Service = {
ExecStart = "${notification-sounds}/bin/notification-sounds";
Restart = "on-failure";
RestartSec = 5;
Environment = "PATH=/usr/bin:/bin:${config.home.profileDirectory}/bin";
};
Install.WantedBy = [ "graphical-session.target" ];
};
xdg.configFile."autostart/notification-sounds.desktop".text = ''
[Desktop Entry]
Type=Application
Name=notification-sounds
Exec=sh -c '[ -d /run/systemd/system ] || exec ${notification-sounds}/bin/notification-sounds'
NoDisplay=true
'';
programs.plasma.configFile = {
kdeglobals.Sounds.Theme = "portal2";
@@ -16,7 +44,7 @@ lib.mkIf config.dotfiles.gui {
plasmaparc.General.AudioFeedback = true;
"plasma_workspace.notifyrc" = {
# Every app notification that has no notifyrc of its own (Chrome, Telegram, Vesktop, notify-send...).
# KDE-internal generic event; other apps' notifications are covered by notification-sounds.
"Event\\/notification" = popupSound "message-new-instant";
"Event\\/startkde" = sound "desktop-login";
"Event\\/exitkde" = sound "desktop-logout";
+104
View File
@@ -0,0 +1,104 @@
"""Give every desktop notification a sound.
Plasma only plays a sound for a freedesktop notification when the sender asks
for one, so most apps (Chrome PWAs, notify-send, Electron apps) are silent.
This watches org.freedesktop.Notifications.Notify calls via `dbus-monitor`
(read-only) and plays the theme's message-new-instant sound unless:
* the sender is a KNotification (x-kde-eventId hint) - KDE plays those itself,
* the notification carries sound-file / sound-name / suppress-sound,
* the app plays its own sound (SKIP_APPS, override with NOTIFICATION_SOUNDS_SKIP).
"""
import os
import re
import select
import subprocess
import time
from pathlib import Path
SKIP_APPS = {
a.strip().lower()
for a in os.environ.get("NOTIFICATION_SOUNDS_SKIP", "Telegram Desktop,Telegram,vesktop,Vesktop,discord").split(",")
if a.strip()
}
SOUND = os.environ.get("NOTIFICATION_SOUNDS_EVENT", "message-new-instant")
OWN_SOUND_HINTS = ('"x-kde-eventId"', '"sound-file"', '"sound-name"', '"suppress-sound"')
MIN_GAP = 0.4 # seconds; a burst of notifications gets one sound
last = 0.0
def sound_file() -> str | None:
theme = subprocess.run(
["kreadconfig6", "--file", "kdeglobals", "--group", "Sounds", "--key", "Theme", "--default", "ocean"],
capture_output=True, text=True,
).stdout.strip()
for base in (Path.home() / ".local/share/sounds", Path("/usr/share/sounds")):
for t in (theme, "ocean", "freedesktop"):
hits = sorted((base / t / "stereo").glob(f"{SOUND}.*"))
if hits:
return str(hits[0])
return None
def play() -> None:
global last
now = time.monotonic()
if now - last < MIN_GAP:
return
last = now
f = sound_file()
if f:
# Same "event" role stream as KDE's own sounds, so the Notification Sounds slider applies.
subprocess.Popen(["paplay", "--property=media.role=event", "--property=application.name=notification-sounds", f])
def judge(block: list[str]) -> None:
"""block = dbus-monitor lines of one Notify call: header, app_name, ..., hints dict."""
strings = [m.group(1) for line in block if (m := re.match(r'\s*string "(.*)"$', line))]
if not strings:
return
app = strings[0]
text = "\n".join(block)
# suppress-sound may be present but false; only treat true as "has its own sound".
suppressed = re.search(r'"suppress-sound"\s*\n\s*variant\s+boolean true', text)
own = any(h in text for h in OWN_SOUND_HINTS[:3]) or suppressed
if not own and app.lower() not in SKIP_APPS:
print(f"ding for {app!r}", flush=True)
play()
def main() -> None:
mon = subprocess.Popen(
["dbus-monitor", "--session", "type='method_call',interface='org.freedesktop.Notifications',member='Notify'"],
stdout=subprocess.PIPE,
)
fd = mon.stdout.fileno()
print(f"listening; skipping {sorted(SKIP_APPS)}", flush=True)
pending = b""
block: list[str] = []
while True:
# Raw fd + select (no buffered readline, which would hide lines from select).
ready, _, _ = select.select([fd], [], [], 0.15)
if not ready:
if block: # quiet for 150 ms: the call is complete
judge(block)
block = []
continue
chunk = os.read(fd, 65536)
if not chunk:
raise SystemExit(f"dbus-monitor exited ({mon.wait()})")
pending += chunk
*lines, pending = pending.split(b"\n")
for raw in lines:
line = raw.decode(errors="replace")
if line.startswith(("method call", "signal", "method return", "error")):
if block:
judge(block)
block = [line] if "member=Notify" in line else []
elif block:
block.append(line)
if __name__ == "__main__":
main()