#!/usr/bin/env bash # We watch the wallpaper state directory; Serpantinum writes monitor-specific # files like current_DP-2 or current_eDP-1. STATE_DIR="$HOME/.cache/serpantinum/wallpaper/" reload_foot_live_colors() { local colors_file="$HOME/.cache/matugen/foot-colors.ini" local -A colors local -A seen_tty local key local value local tty_path local pid local seq="" [ -r "$colors_file" ] || return 0 while IFS='=' read -r key value; do # Skip section headers and malformed lines. [[ "$key" == "["* || -z "$key" || -z "$value" ]] && continue key="${key//[[:space:]]/}" value="${value%% *}" value="${value//[[:space:]]/}" [[ "$value" =~ ^[0-9A-Fa-f]{6}$ ]] || continue colors["$key"]="#$value" done < "$colors_file" [ -n "${colors[foreground]}" ] && seq+="\e]10;${colors[foreground]}\a" [ -n "${colors[background]}" ] && seq+="\e]11;${colors[background]}\a" [ -n "${colors[cursor]}" ] && seq+="\e]12;${colors[cursor]}\a" for i in 0 1 2 3 4 5 6 7; do [ -n "${colors[regular$i]}" ] && seq+="\e]4;$i;${colors[regular$i]}\a" [ -n "${colors[bright$i]}" ] && seq+="\e]4;$((i + 8));${colors[bright$i]}\a" done [ -n "$seq" ] || return 0 for pid in $(pgrep -x foot 2>/dev/null) $(pgrep -x footclient 2>/dev/null); do tty_path=$(readlink "/proc/$pid/fd/0" 2>/dev/null) || continue [[ "$tty_path" == /dev/pts/* ]] || continue [ -n "${seen_tty[$tty_path]}" ] && continue printf '%b' "$seq" > "$tty_path" 2>/dev/null || true seen_tty["$tty_path"]=1 done } inotifywait -m -e close_write "$STATE_DIR" | while read -r directory events filename; do # Only react to monitor pointer files like current_DP-2, current_eDP-1, # current_HDMI-A-1. Ignore binary/image/json side files. if [[ "$filename" =~ ^current_[[:alnum:]]+-[[:alnum:]-]+$ ]]; then # Give Serpantinum a split second to finish its operations sleep 0.5 # Read one line from the monitor pointer file. IFS= read -r WP_PATH < "$STATE_DIR$filename" # Skip empty, non-absolute, or missing paths. [[ -n "$WP_PATH" && "$WP_PATH" = /* && -f "$WP_PATH" ]] || continue # 1. Run Matugen against the ORIGINAL valid image file matugen image "$WP_PATH" # 2. Reload Hyprland hyprctl reload # 3. Live-apply colors in running Foot terminals. reload_foot_live_colors fi done