From e857b06c6b242c5faff99fd70241c35fba67da1f Mon Sep 17 00:00:00 2001 From: seraphim <18ycm9tx@anonaddy.me> Date: Thu, 20 Aug 2026 21:14:06 +0700 Subject: - --- niri/.config/niri/apply-colors.sh | 33 ++++++++++++++++++++++++++++++--- niri/.config/niri/config.kdl | 2 +- niri/.config/niri/theme-switcher.sh | 36 +++++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 17 deletions(-) (limited to 'niri/.config') diff --git a/niri/.config/niri/apply-colors.sh b/niri/.config/niri/apply-colors.sh index d5113c6..339e134 100755 --- a/niri/.config/niri/apply-colors.sh +++ b/niri/.config/niri/apply-colors.sh @@ -8,6 +8,14 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$(realpath "$0")")" && pwd)" IMG="${1:-}" MODE="${2:-auto}" +LOG="${THEME_LOG:-/tmp/theme-switcher.log}" + +log() { + printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >>"$LOG" +} + +# Record the exact failing command + line on any error. +trap 'log "apply-colors FAILED (exit $?) in ${BASH_SOURCE[0]}:$LINENO: $BASH_COMMAND"' ERR if [ -z "$IMG" ] || [ ! -f "$IMG" ]; then echo "usage: $0 [light|dark]" >&2 @@ -15,23 +23,40 @@ if [ -z "$IMG" ] || [ ! -f "$IMG" ]; then fi # wallust: classic 16-color palette (foot, btop, ...) +# fastresize (the config default) is flaky on some images — always use resized. +# A single attempt with honest error handling: the old retry loop swallowed +# failures (case && break defeats set -e) and kept the stale light theme. +log "wallust palette=$MODE $IMG" case "$MODE" in -light) wallust run --palette light "$IMG" ;; -dark) wallust run --palette dark "$IMG" ;; -*) wallust run "$IMG" ;; +light|dark) WALLUST_PALETTE=("--palette" "$MODE") ;; +*) WALLUST_PALETTE=() ;; esac +if ! wallust run -b resized "${WALLUST_PALETTE[@]}" "$IMG"; then + log "wallust FAILED ($IMG, mode=$MODE)" + exit 1 +fi # foot needs bare RRGGBB, not #RRGGBB — strip the leading '#' sed -i 's/#\([0-9a-fA-F]\)/\1/g' ~/.cache/wallust/foot-theme.ini 2>/dev/null || true # matugen: Material You / M3 colors (niri focus ring, ...) # --prefer is required for non-interactive runs (multiple source colors). +log "matugen mode=$MODE $IMG" case "$MODE" in light) matugen image "$IMG" -m "light" --prefer saturation ;; dark) matugen image "$IMG" -m "dark" --prefer saturation ;; *) matugen image "$IMG" --prefer saturation ;; esac +# wait for the awww daemon to be ready (it is spawned next to this script at login) +log "awww img $IMG" +for _ in $(seq 1 10); do + if awww query >/dev/null 2>&1; then + break + fi + sleep 1 +done + # set the wallpaper awww img "$IMG" @@ -42,3 +67,5 @@ awww img "$IMG" killall -SIGUSR2 waybar 2>/dev/null || true killall -USR1 foot 2>/dev/null || true niri msg action load-config-file 2>/dev/null || true + +log "apply-colors OK ($IMG, $MODE)" diff --git a/niri/.config/niri/config.kdl b/niri/.config/niri/config.kdl index f30607a..05b2240 100644 --- a/niri/.config/niri/config.kdl +++ b/niri/.config/niri/config.kdl @@ -1,6 +1,6 @@ // Material You / Material Design 3 colors, generated by matugen (see theme-switcher.sh / apply-colors.sh) include optional=true "/home/seraphim/.cache/matugen/theme.kdl" - +spawn-at-startup "mako" spawn-at-startup "xrdb" "-merge" "/home/seraphim/.Xresources" spawn-at-startup "vicinae" "server" spawn-at-startup "gentoo-pipewire-launcher" diff --git a/niri/.config/niri/theme-switcher.sh b/niri/.config/niri/theme-switcher.sh index 0f9b415..6b3b6e9 100755 --- a/niri/.config/niri/theme-switcher.sh +++ b/niri/.config/niri/theme-switcher.sh @@ -7,9 +7,14 @@ WALLPAPERS="$HOME/Pictures/wallpapers" STATE_FILE="/tmp/current_theme_state" WALLPAPER_STATE_FILE="/tmp/current_wallpaper_state" BACKDROP_STATE_FILE="/tmp/current_backdrop_state" +LOG="/tmp/theme-switcher.log" SCRIPT_DIR="$(cd "$(dirname "$(realpath "$0")")" && pwd)" SET_BACKDROP="$SCRIPT_DIR/set-backdrop.sh" +log() { + printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >>"$LOG" +} + while true; do HOUR=$(date +%H) HOUR=$((10#$HOUR)) @@ -40,22 +45,27 @@ while true; do fi if [ "$CURRENT_WALLPAPER" != "$WALLPAPER" ] || [ "$CURRENT_THEME" != "$TARGET_STATE" ]; then - sh "$SCRIPT_DIR/apply-colors.sh" "$WALLPAPER" "$MODE" - - if [ "$CURRENT_THEME" != "$TARGET_STATE" ]; then - darkman set "$TARGET_STATE" - fi + log "switching to $TARGET_STATE ($WALLPAPER)" + if sh "$SCRIPT_DIR/apply-colors.sh" "$WALLPAPER" "$MODE"; then + if [ "$CURRENT_THEME" != "$TARGET_STATE" ]; then + darkman set "$TARGET_STATE" + fi - ln -sf \ - "theme-${TARGET_STATE}.css" \ - "$HOME/dotfiles-gentoo/waybar/.config/waybar/theme.css" + ln -sf \ + "theme-${TARGET_STATE}.css" \ + "$HOME/dotfiles-gentoo/waybar/.config/waybar/theme.css" - ln -sf \ - "settings-${TARGET_STATE}.ini" \ - "$HOME/dotfiles-gentoo/gtk/.config/gtk-3.0/settings.ini" + ln -sf \ + "settings-${TARGET_STATE}.ini" \ + "$HOME/dotfiles-gentoo/gtk/.config/gtk-3.0/settings.ini" - echo "$TARGET_STATE" >"$STATE_FILE" - echo "$WALLPAPER" >"$WALLPAPER_STATE_FILE" + echo "$TARGET_STATE" >"$STATE_FILE" + echo "$WALLPAPER" >"$WALLPAPER_STATE_FILE" + log "switched to $TARGET_STATE ($WALLPAPER)" + else + # State is intentionally NOT written so the next loop iteration retries. + log "FAILED to apply $TARGET_STATE ($WALLPAPER), will retry" + fi fi sleep 60 -- cgit v1.2.3