diff options
Diffstat (limited to 'config/hypr/scripts/WallpaperDaemon.sh')
| -rwxr-xr-x | config/hypr/scripts/WallpaperDaemon.sh | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/config/hypr/scripts/WallpaperDaemon.sh b/config/hypr/scripts/WallpaperDaemon.sh index aeb6c397..4725bc6b 100755 --- a/config/hypr/scripts/WallpaperDaemon.sh +++ b/config/hypr/scripts/WallpaperDaemon.sh @@ -38,6 +38,32 @@ get_monitors() { fi } +wait_for_monitors() { + local monitors="" + for _ in {1..120}; do + monitors="$(get_monitors 2>/dev/null | awk 'NF')" + if [ -n "$monitors" ]; then + printf '%s\n' "$monitors" + return 0 + fi + sleep 0.1 + done + return 1 +} + +default_wallpaper_path() { + local pictures_dir wall_dir + pictures_dir="$(xdg-user-dir PICTURES 2>/dev/null || echo "$HOME/Pictures")" + wall_dir="$pictures_dir/wallpapers" + + [ -d "$wall_dir" ] || return 1 + + find -L "$wall_dir" -type f \( \ + -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.bmp" -o \ + -iname "*.gif" -o -iname "*.webp" -o -iname "*.tiff" \ + \) -print | LC_ALL=C sort | awk 'NR == 1 {print; exit}' +} + apply_wallpaper_for_monitor() { local monitor="$1" local per_monitor_link="${XDG_CONFIG_HOME:-$HOME/.config}/rofi/.current_wallpaper_${monitor}" @@ -91,6 +117,11 @@ apply_wallpaper_for_monitor() { fi fi + # Final fallback: use the first available wallpaper from the wallpapers directory. + if [ -z "$wallpaper_path" ]; then + wallpaper_path="$(default_wallpaper_path 2>/dev/null || true)" + fi + if [ -n "$wallpaper_path" ] && [ -f "$wallpaper_path" ]; then local resize_mode resize_mode="$(wallpaper_resize_mode "$wallpaper_path" "$monitor")" @@ -98,10 +129,25 @@ apply_wallpaper_for_monitor() { sleep 0.3 "$WWW_CMD" img -o "$monitor" --resize "$resize_mode" "$wallpaper_path" >/dev/null 2>&1 & fi + printf '%s\n' "$wallpaper_path" + return 0 fi + + return 1 } +applied_wallpaper="" while read -r monitor; do [ -n "$monitor" ] || continue - apply_wallpaper_for_monitor "$monitor" -done < <(get_monitors) + applied_path="$(apply_wallpaper_for_monitor "$monitor" || true)" + if [ -z "$applied_wallpaper" ] && [ -n "$applied_path" ] && [ -f "$applied_path" ]; then + applied_wallpaper="$applied_path" + fi +done < <(wait_for_monitors || true) + +"$SCRIPTSDIR/RofiFocusedWallpaperLink.sh" >/dev/null 2>&1 || true + +waybar_colors="${XDG_CONFIG_HOME:-$HOME/.config}/waybar/wallust/colors-waybar.css" +if [ ! -s "$waybar_colors" ] && [ -n "$applied_wallpaper" ] && [ -x "$SCRIPTSDIR/WallustSwww.sh" ]; then + "$SCRIPTSDIR/WallustSwww.sh" "$applied_wallpaper" >/dev/null 2>&1 || true +fi |
