diff options
| author | seraphim <18ycm9tx@anonaddy.me> | 2026-08-23 19:31:22 +0700 |
|---|---|---|
| committer | seraphim <18ycm9tx@anonaddy.me> | 2026-08-23 19:31:22 +0700 |
| commit | 9d11eefc53441e1f5688545b4b827f7c8dd5090d (patch) | |
| tree | 5e695b58b7403a9ac82c700d6ca11fdf5328abef /.config/niri | |
| parent | ed3e8f6ec6929327ab19e512ffb0d8ece12ed5a8 (diff) | |
reorganize directories, so everything in .config
Diffstat (limited to '.config/niri')
| -rwxr-xr-x | .config/niri/apply-colors.sh | 1 | ||||
| -rw-r--r-- | .config/niri/config.kdl | 4 | ||||
| -rwxr-xr-x | .config/niri/mako-start.sh | 20 | ||||
| -rwxr-xr-x | .config/niri/theme-switcher.sh | 144 |
4 files changed, 99 insertions, 70 deletions
diff --git a/.config/niri/apply-colors.sh b/.config/niri/apply-colors.sh index 505578c..aebf509 100755 --- a/.config/niri/apply-colors.sh +++ b/.config/niri/apply-colors.sh @@ -80,5 +80,6 @@ esac || log "matugen FAILED ($IMG, mode=$MODE) — continuing without matugen co killall -SIGUSR2 waybar 2>/dev/null || true killall -USR1 foot 2>/dev/null || true niri msg action load-config-file 2>/dev/null || true +makoctl reload 2>/dev/null || true log "apply-colors OK ($IMG, $MODE)" diff --git a/.config/niri/config.kdl b/.config/niri/config.kdl index 9d7db14..b71b8ed 100644 --- a/.config/niri/config.kdl +++ b/.config/niri/config.kdl @@ -1,5 +1,5 @@ include optional=true "/home/seraphim/.cache/matugen/theme.kdl" -spawn-at-startup "mako" +spawn-at-startup "/home/seraphim/dotfiles-gentoo/niri/.config/niri/mako-start.sh" spawn-at-startup "xrdb" "-merge" "/home/seraphim/.Xresources" spawn-at-startup "vicinae" "server" spawn-at-startup "gentoo-pipewire-launcher" @@ -10,7 +10,7 @@ spawn-at-startup "awww-daemon" "--namespace" "backdrop" spawn-at-startup "/usr/libexec/hyprpolkitagent" spawn-at-startup "dbus-update-activation-environment" "WAYLAND_DISPLAY" "DISPLAY" "XDG_CURRENT_DESKTOP" spawn-at-startup "darkman" "run" -spawn-at-startup "/home/seraphim/dotfiles-gentoo/niri/.config/niri/theme-switcher.sh" "night" +spawn-at-startup "/home/seraphim/dotfiles-gentoo/.config/niri/theme-switcher.sh" "--last" spawn-at-startup "sh" "-c" "NO_AT_BRIDGE=1 waybar" spawn-at-startup "/usr/bin/Throne" spawn-at-startup "mpd" diff --git a/.config/niri/mako-start.sh b/.config/niri/mako-start.sh new file mode 100755 index 0000000..aceaa3b --- /dev/null +++ b/.config/niri/mako-start.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Start mako after making sure the wallust-generated color file exists. +# mako's config uses `include=~/.cache/wallust/mako`; if that file is missing +# (e.g. on first login before wallust has run) mako would fail to start, so we +# seed a neutral default here. apply-colors.sh regenerates it and runs +# `makoctl reload` once the real palette is ready. +set -e + +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/wallust/mako" +if [ ! -f "$CACHE" ]; then + mkdir -p "$(dirname "$CACHE")" + cat > "$CACHE" <<'EOF' +background-color=#1e1e1e +text-color=#e0e0e0 +border-color=#3a3a3a +progress-color=over #4f4f4f +EOF +fi + +exec mako "$@" diff --git a/.config/niri/theme-switcher.sh b/.config/niri/theme-switcher.sh index 6d1f548..01786d8 100755 --- a/.config/niri/theme-switcher.sh +++ b/.config/niri/theme-switcher.sh @@ -1,19 +1,18 @@ #!/bin/bash -# Day/night theme switcher + wallpaper/color applier. -# Two wallpapers: day.jpg (9:00-18:00) and night.jpg (18:00-9:00). +# Manual theme switcher + wallpaper/color applier. +# No time-based switching: you pick the wallpaper and mode explicitly. # # Usage: -# ./theme-switcher.sh one-shot: apply based on current time, then exit -# ./theme-switcher.sh day|light force light theme, then exit -# ./theme-switcher.sh night|dark force dark theme, then exit -# ./theme-switcher.sh --daemon continuous time-based loop (used at login) +# ./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" -PID_FILE="/tmp/theme-switcher.daemon.pid" +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" @@ -22,33 +21,42 @@ log() { printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >>"$LOG" } -# Resolve TARGET_STATE / MODE / WALLPAPER. Optional $1 forces day|night. -resolve_target() { - local force="${1:-}" - if [ "$force" = "day" ] || [ "$force" = "light" ]; then - TARGET_STATE="light" - MODE="light" - WALLPAPER="$WALLPAPERS/day.jpg" - elif [ "$force" = "night" ] || [ "$force" = "dark" ]; then +# 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" ;; + esac + else + WALLPAPER="$WALLPAPERS/night.jpg" TARGET_STATE="dark" MODE="dark" - WALLPAPER="$WALLPAPERS/night.jpg" - else - local HOUR - HOUR=$(date +%H) - HOUR=$((10#$HOUR)) - if [ "$HOUR" -ge 9 ] && [ "$HOUR" -lt 18 ]; then - TARGET_STATE="light" - MODE="light" - WALLPAPER="$WALLPAPERS/day.jpg" - else - TARGET_STATE="dark" - MODE="dark" - WALLPAPER="$WALLPAPERS/night.jpg" - fi 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 +} + # Apply the resolved target once. Returns 0 on success. apply_target() { if [ ! -f "$WALLPAPER" ]; then @@ -59,16 +67,6 @@ apply_target() { local CURRENT_THEME CURRENT_WALLPAPER EXPECTED_BACKDROP ACTUAL_BACKDROP CURRENT_THEME=$(cat "$STATE_FILE" 2>/dev/null || true) - # Already in the correct theme: don't re-run wallust/matugen every loop tick. - # Still self-heal a drifted backdrop below, then bail out. - if [ "$CURRENT_THEME" = "$TARGET_STATE" ]; then - 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 - return 0 - fi CURRENT_WALLPAPER=$(cat "$WALLPAPER_STATE_FILE" 2>/dev/null || true) # Self-heal the Overview backdrop if it drifted from the expected image. @@ -78,6 +76,11 @@ apply_target() { "$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 @@ -86,14 +89,15 @@ apply_target() { ln -sf \ "theme-${TARGET_STATE}.css" \ - "$HOME/dotfiles-gentoo/waybar/.config/waybar/theme.css" + "$HOME/dotfiles-gentoo/.config/waybar/theme.css" ln -sf \ "settings-${TARGET_STATE}.ini" \ - "$HOME/dotfiles-gentoo/gtk/.config/gtk-3.0/settings.ini" + "$HOME/dotfiles-gentoo/.config/gtk-3.0/settings.ini" echo "$TARGET_STATE" >"$STATE_FILE" echo "$WALLPAPER" >"$WALLPAPER_STATE_FILE" + save_last log "switched to $TARGET_STATE ($WALLPAPER)" return 0 else @@ -102,34 +106,38 @@ apply_target() { fi } -daemon_loop() { - # Refuse to run a second daemon instance (e.g. manual run while one is alive). - if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE" 2>/dev/null)" 2>/dev/null; then - log "daemon already running (pid $(cat "$PID_FILE")), exiting" - exit 0 - fi - echo $$ >"$PID_FILE" - - while true; do - resolve_target - apply_target || true # failure is retried on the next loop, state is left untouched - sleep 60 - done +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 } case "${1:-}" in ---daemon | -d) daemon_loop ;; -"" | day | light | night | dark) - resolve_target "${1:-}" - apply_target - exit $? - ;; --h | --help) - echo "usage: $0 [day|night|--daemon]" >&2 - exit 0 - ;; -*) - echo "usage: $0 [day|night|--daemon]" >&2 - exit 1 - ;; + --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 |
