From 121235db5ca23e53e0dad3a402c521dc7a940fbc Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 17 Sep 2026 08:07:00 +0200 Subject: feat(icons): read the icon theme from gsettings The icon theme name was hardcoded in three places (bin/wb-icon, modules/extras/taskbar.jsonc and install.sh), so switching themes in the appearance drawer was silently reverted as far as this bar was concerned. wb-icon now reads org.gnome.desktop.interface icon-theme and gains two modes for install.sh: --path NAME prints one icon's absolute path, --theme prints the resolved theme name. Icons are resolved per name rather than by substituting a directory prefix, because themes disagree about both subdirectory and file extension: the Suru themes keep web-browser at categories/22/*.svg, elementary-xfce at apps/22/*.png. Only a real GTK lookup knows the path. styles/modules.css therefore carries @ICON:name@ placeholders and modules/extras/taskbar.jsonc carries @ICON_THEME@, both filled at install time. taskbar.jsonc is generated rather than symlinked for that reason, and install.sh removes the old symlink first so the redirect cannot overwrite the committed source. A theme missing one of the twenty names fails the install at the --selftest step rather than drawing empty pills. Co-Authored-By: Claude Opus 5 --- install.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'install.sh') diff --git a/install.sh b/install.sh index 42bc50a..775e318 100755 --- a/install.sh +++ b/install.sh @@ -15,7 +15,6 @@ set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" target="$HOME/.config/waybar-udt" udt="$(cd "$repo/../unified-desktop-theme" 2>/dev/null && pwd || true)" -icons="$HOME/.local/share/icons/Material-Black-Plum-Suru" mkdir -p "$target/modules/hyprland" "$target/modules/custom" \ "$target/modules/extras" "$target/modules/image" \ @@ -96,7 +95,7 @@ for f in modules/clock.jsonc \ modules/custom/vmdot.jsonc modules/custom/privacy_dots.jsonc \ modules/custom/presentation.jsonc modules/custom/mail.jsonc \ modules/custom/launcher.jsonc \ - modules/extras/taskbar.jsonc modules/extras/tray.jsonc \ + modules/extras/tray.jsonc \ modules/image/volume.jsonc modules/image/language.jsonc; do ln -sfn "$repo/$f" "$target/$f" done @@ -105,11 +104,37 @@ for f in style.css fonts.css global.css pills.css; do ln -sfn "$repo/styles/$f" "$target/styles/$f" done -# modules.css is generated rather than linked: it carries the icon theme's -# absolute path, which cannot be committed, and the accent-tinted launcher. -sed -e "s|@ICONS@|$icons|g" -e "s|@CONFIG@|$target|g" \ +# modules.css is generated rather than linked: it carries absolute icon paths, +# which cannot be committed, and the accent-tinted launcher. +# +# Each @ICON:name@ is resolved by wb-icon, which reads the desktop's icon theme +# from gsettings. Resolving per name rather than substituting one directory is +# what makes a theme switch work at all: themes disagree about both the +# subdirectory and the file extension (Suru keeps web-browser at +# categories/22/*.svg, elementary-xfce at apps/22/*.png), so only a real icon +# lookup knows the path. An unresolved name is left as-is and reported; the +# selftest below is what turns that into a failed install. +sed -e "s|@CONFIG@|$target|g" \ "$repo/styles/modules.css" > "$target/styles/modules.css" +for name in $(grep -o '@ICON:[a-z0-9-]*@' "$target/styles/modules.css" \ + | sed 's/@ICON:\(.*\)@/\1/' | sort -u); do + if path="$("$repo/bin/wb-icon" --path "$name")"; then + sed -i "s|@ICON:$name@|$path|g" "$target/styles/modules.css" + else + echo "warning: no icon named '$name' in the current icon theme" >&2 + fi +done + +# taskbar.jsonc names the icon theme, which is gsettings' to say, so it is +# generated for the same reason modules.css is. Every other module is a symlink. +# An earlier install symlinked this file into the repo. Writing through that +# link would overwrite the committed source with a generated copy, so the link +# is removed first; the redirect below then creates a real file. +rm -f "$target/modules/extras/taskbar.jsonc" +sed "s|@ICON_THEME@|$("$repo/bin/wb-icon" --theme)|g" \ + "$repo/modules/extras/taskbar.jsonc" > "$target/modules/extras/taskbar.jsonc" + # The launcher module carries no generated path any more: its mark is a CSS # background, so modules.css owns the paths and the module file is a plain # symlink like every other. @@ -149,7 +174,9 @@ ln -sfn "$repo/bin/wb-lang" "$HOME/bin/wb-lang" # ----------------------------------------------------------------- checks -- # A missing icon renders as an empty pill and nothing says why, so the names -# are checked here, while someone is watching. +# are checked here, while someone is watching. The theme is whatever gsettings +# says, so this also catches a switch to a theme that lacks one of these names. +echo "icon theme: $("$repo/bin/wb-icon" --theme)" "$repo/bin/wb-icon" --selftest echo -- cgit v1.2.3