From 4a8131b166c4ba2512d075dcf5cc930ca1652bd8 Mon Sep 17 00:00:00 2001 From: Don Williams Date: Sat, 20 Sep 2025 12:20:28 -0400 Subject: fix(wallust): make theme regeneration deterministic on wallpaper change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Accept explicit image path in WallustSwww.sh; retry swww cache briefly if not provided - Pass selected image path from WallpaperSelect.sh to WallustSwww.sh - Run WallustSwww.sh synchronously in RefreshNoWaybar.sh to ensure colors are ready before reload - Update WallpaperAutoChange.sh to call WallustSwww.sh with each rotated image This eliminates races against swww’s cache and ensures Wallust updates waybar/rofi/kitty/hypr colors immediately after changing wallpapers. Test plan: - Select a wallpaper (SUPER+W): observe updated files in ~/.config/{waybar,rofi,kitty}/ and immediate border color changes; waybar reloads with new palette - Enable auto-rotate (WallpaperAutoChange.sh): colors now update on each rotation without manual intervention Tested-by: KalebNH --- config/hypr/scripts/RefreshNoWaybar.sh | 5 ++- config/hypr/scripts/WallustSwww.sh | 79 +++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 32 deletions(-) (limited to 'config/hypr/scripts') diff --git a/config/hypr/scripts/RefreshNoWaybar.sh b/config/hypr/scripts/RefreshNoWaybar.sh index f950db51..8454124e 100755 --- a/config/hypr/scripts/RefreshNoWaybar.sh +++ b/config/hypr/scripts/RefreshNoWaybar.sh @@ -31,8 +31,9 @@ done # quit quickshell & relaunch quickshell #pkill qs && qs & -# Wallust refresh -${SCRIPTSDIR}/WallustSwww.sh & +# Wallust refresh (synchronous to ensure colors are ready) +${SCRIPTSDIR}/WallustSwww.sh +sleep 0.2 # reload swaync swaync-client --reload-config diff --git a/config/hypr/scripts/WallustSwww.sh b/config/hypr/scripts/WallustSwww.sh index 62dde375..5a0bc491 100755 --- a/config/hypr/scripts/WallustSwww.sh +++ b/config/hypr/scripts/WallustSwww.sh @@ -1,39 +1,58 @@ #!/bin/bash # /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ## -# Wallust Colors for current wallpaper +# Wallust: derive colors from the current wallpaper and update templates +# Usage: WallustSwww.sh [absolute_path_to_wallpaper] -# Define the path to the swww cache directory +set -euo pipefail + +# Inputs and paths +passed_path="${1:-}" cache_dir="$HOME/.cache/swww/" +rofi_link="$HOME/.config/rofi/.current_wallpaper" +wallpaper_current="$HOME/.config/hypr/wallpaper_effects/.wallpaper_current" + +# Helper: get focused monitor name (prefer JSON) +get_focused_monitor() { + if command -v jq >/dev/null 2>&1; then + hyprctl monitors -j | jq -r '.[] | select(.focused) | .name' + else + hyprctl monitors | awk '/^Monitor/{name=$2} /focused: yes/{print name}' + fi +} + +# Determine wallpaper_path +wallpaper_path="" +if [[ -n "$passed_path" && -f "$passed_path" ]]; then + wallpaper_path="$passed_path" +else + # Try to read from swww cache for the focused monitor, with a short retry loop + current_monitor="$(get_focused_monitor)" + cache_file="$cache_dir$current_monitor" -# Get a list of monitor outputs -monitor_outputs=($(ls "$cache_dir")) - -# Initialize a flag to determine if the ln command was executed -ln_success=false - -# Get current focused monitor -current_monitor=$(hyprctl monitors | awk '/^Monitor/{name=$2} /focused: yes/{print name}') -echo $current_monitor -# Construct the full path to the cache file -cache_file="$cache_dir$current_monitor" -echo $cache_file -# Check if the cache file exists for the current monitor output -if [ -f "$cache_file" ]; then - # Get the wallpaper path from the cache file - wallpaper_path=$(grep -v 'Lanczos3' "$cache_file" | head -n 1) - echo $wallpaper_path - # symlink the wallpaper to the location Rofi can access - if ln -sf "$wallpaper_path" "$HOME/.config/rofi/.current_wallpaper"; then - ln_success=true # Set the flag to true upon successful execution + # Wait briefly for swww to write its cache after an image change + for i in {1..10}; do + if [[ -f "$cache_file" ]]; then + break fi - # copy the wallpaper for wallpaper effects - cp -r "$wallpaper_path" "$HOME/.config/hypr/wallpaper_effects/.wallpaper_current" + sleep 0.1 + done + + if [[ -f "$cache_file" ]]; then + # The first non-filter line is the original wallpaper path + wallpaper_path="$(grep -v 'Lanczos3' "$cache_file" | head -n 1)" + fi fi -# Check the flag before executing further commands -if [ "$ln_success" = true ]; then - # execute wallust - echo 'about to execute wallust' - # execute wallust skipping tty and terminal changes - wallust run "$wallpaper_path" -s & +if [[ -z "${wallpaper_path:-}" || ! -f "$wallpaper_path" ]]; then + # Nothing to do; avoid failing loudly so callers can continue + exit 0 fi + +# Update helpers that depend on the path +ln -sf "$wallpaper_path" "$rofi_link" || true +mkdir -p "$(dirname "$wallpaper_current")" +cp -f "$wallpaper_path" "$wallpaper_current" || true + +# Run wallust (silent) to regenerate templates defined in ~/.config/wallust/wallust.toml +# -s is used in this repo to keep things quiet and avoid extra prompts +wallust run -s "$wallpaper_path" || true -- cgit v1.2.3