diff options
| author | seraphim <18ycm9tx@anonaddy.me> | 2026-08-25 12:40:31 +0700 |
|---|---|---|
| committer | seraphim <18ycm9tx@anonaddy.me> | 2026-08-25 12:40:31 +0700 |
| commit | cc7b61a1496d25a100f012300c1121835a9f8177 (patch) | |
| tree | e683f7c5fdd604e0a1a4b59df1ca79386c805f81 /.config/niri/theme-switcher.sh | |
| parent | 9d11eefc53441e1f5688545b4b827f7c8dd5090d (diff) | |
new cursors
Diffstat (limited to '.config/niri/theme-switcher.sh')
| -rwxr-xr-x | .config/niri/theme-switcher.sh | 178 |
1 files changed, 43 insertions, 135 deletions
diff --git a/.config/niri/theme-switcher.sh b/.config/niri/theme-switcher.sh index 01786d8..af9035f 100755 --- a/.config/niri/theme-switcher.sh +++ b/.config/niri/theme-switcher.sh @@ -1,143 +1,51 @@ -#!/bin/bash - -# Manual theme switcher + wallpaper/color applier. -# No time-based switching: you pick the wallpaper and mode explicitly. +#!/bin/sh +# Set a new wallpaper everywhere: main layer, blurred backdrop, wallust colors. # -# Usage: -# ./theme-switcher.sh <image> <day|night> apply <image> in light/dark mode, remember it -# ./theme-switcher.sh --last apply the last manually-set wallpaper+mode -# ./theme-switcher.sh -h | --help show this help - -WALLPAPERS="$HOME/Pictures/wallpapers" -STATE_FILE="/tmp/current_theme_state" -WALLPAPER_STATE_FILE="/tmp/current_wallpaper_state" -BACKDROP_STATE_FILE="/tmp/current_backdrop_state" -LAST_FILE="${XDG_STATE_HOME:-$HOME/.local/state}/theme-switcher/last" -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" -} - -# Persist the last manually-chosen wallpaper + mode so --last survives reboots. -save_last() { - mkdir -p "$(dirname "$LAST_FILE")" - printf '%s\n%s\n' "$WALLPAPER" "$MODE" >"$LAST_FILE" -} - -# Load the last chosen wallpaper + mode. Falls back to the old default so a -# fresh boot (nothing saved yet) never lands on a blank wallpaper. -load_last() { - if [ -f "$LAST_FILE" ]; then - WALLPAPER=$(sed -n '1p' "$LAST_FILE") - MODE=$(sed -n '2p' "$LAST_FILE") - case "$MODE" in - light) TARGET_STATE="light" ;; - *) TARGET_STATE="dark"; MODE="dark" ;; +# Usage: theme-switcher.sh <wallpaper|path> [--palette P] [--threshold T] +# [--saturation S] [--colorspace C] +# +# The chosen palette/threshold are persisted to ~/.cache/wallust_runtime so +# that apply-colors.sh reproduces them after a reboot. The main wallpaper is +# cached by awww itself, so it is also restored on the next boot. + +set -eu +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" +STATE="$CACHE/wallust_runtime" +WP=""; palette=""; threshold=""; sat=""; cs="" + +while [ $# -gt 0 ]; do + case "$1" in + --palette|-p) palette="$2"; shift 2 ;; + --threshold|-t) threshold="$2"; shift 2 ;; + --saturation) sat="$2"; shift 2 ;; + --colorspace|-c) cs="$2"; shift 2 ;; + *) WP="${WP:-$1}"; shift ;; esac - else - WALLPAPER="$WALLPAPERS/night.jpg" - TARGET_STATE="dark" - MODE="dark" - fi -} - -# Resolve TARGET_STATE / MODE from an explicit mode argument. -resolve_explicit() { - local mode="$1" - case "$mode" in - day | light) TARGET_STATE="light"; MODE="light" ;; - night | dark) TARGET_STATE="dark"; MODE="dark" ;; - *) - echo "mode must be day|night (got: $mode)" >&2 - exit 1 - ;; - esac -} +done -# Apply the resolved target once. Returns 0 on success. -apply_target() { - if [ ! -f "$WALLPAPER" ]; then - log "wallpaper missing: $WALLPAPER" - return 1 - fi - - local CURRENT_THEME CURRENT_WALLPAPER EXPECTED_BACKDROP ACTUAL_BACKDROP - - CURRENT_THEME=$(cat "$STATE_FILE" 2>/dev/null || true) - CURRENT_WALLPAPER=$(cat "$WALLPAPER_STATE_FILE" 2>/dev/null || true) - - # Self-heal the Overview backdrop if it drifted from the expected image. - EXPECTED_BACKDROP=$(cat "$BACKDROP_STATE_FILE" 2>/dev/null || true) - ACTUAL_BACKDROP=$(awww query -n backdrop -j 2>/dev/null | jq -r '.["backdrop"][0].displaying.image // empty') - if [ -n "$EXPECTED_BACKDROP" ] && [ "$ACTUAL_BACKDROP" != "$EXPECTED_BACKDROP" ]; then - "$SET_BACKDROP" "$WALLPAPER" - fi - - # Already in this exact theme AND wallpaper: skip the heavy color work. - if [ "$CURRENT_THEME" = "$TARGET_STATE" ] && [ "$CURRENT_WALLPAPER" = "$WALLPAPER" ]; then - return 0 - 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 +[ -n "$WP" ] || { echo "usage: $0 <wallpaper> [--palette P] [--threshold T]" >&2; exit 1; } +case "$WP" in + /*) ;; + *) WP="$HOME/Pictures/wallpapers/$WP" ;; +esac +[ -f "$WP" ] || { echo "no such wallpaper: $WP" >&2; exit 1; } - ln -sf \ - "theme-${TARGET_STATE}.css" \ - "$HOME/dotfiles-gentoo/.config/waybar/theme.css" +# Remember the last used wallpaper so apply-colors.sh reproduces it on reboot. +echo "$WP" > "$CACHE/current_wallpaper" - ln -sf \ - "settings-${TARGET_STATE}.ini" \ - "$HOME/dotfiles-gentoo/.config/gtk-3.0/settings.ini" +# Persist palette/threshold for the next boot. +: > "$STATE" +[ -n "$palette" ] && echo "palette=$palette" >> "$STATE" +[ -n "$threshold" ] && echo "threshold=$threshold" >> "$STATE" +[ -n "$sat" ] && echo "saturation=$sat" >> "$STATE" +[ -n "$cs" ] && echo "colorspace=$cs" >> "$STATE" - echo "$TARGET_STATE" >"$STATE_FILE" - echo "$WALLPAPER" >"$WALLPAPER_STATE_FILE" - save_last - log "switched to $TARGET_STATE ($WALLPAPER)" - return 0 - else - log "FAILED to apply $TARGET_STATE ($WALLPAPER)" - return 1 - fi -} +# Main wallpaper (awww caches it -> restored automatically on next boot). +awww img "$WP" -usage() { - cat >&2 <<EOF -usage: $0 <image> <day|night> | --last - <image> <day|night> apply <image> in light/dark mode and remember it - --last apply the last manually-set wallpaper + mode -EOF -} +# Regenerate colors, sync backdrop, reload live apps. +"$HOME/.config/niri/apply-colors.sh" -case "${1:-}" in - --last) - load_last - apply_target - exit $? - ;; - -h | --help) - usage - exit 0 - ;; - "") - usage - exit 1 - ;; - *) - WALLPAPER="${1:-}" - MODEARG="${2:-}" - if [ -z "$MODEARG" ]; then - echo "missing mode (day|night)" >&2 - usage - exit 1 - fi - resolve_explicit "$MODEARG" - apply_target - exit $? - ;; -esac +# Refresh niri's own theme (focus ring, etc.) live. +matugen image "$WP" 2>/dev/null || true +niri msg action reload-config 2>/dev/null || true |
