feat(wallpaper): add better wallpaper script
This commit is contained in:
@@ -1,91 +1,44 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Configuration
|
# wallpaper.sh — pick a wallpaper from ~/.wallpapers via wofi, apply with hyprpaper
|
||||||
WALLPAPER_DIR="$HOME/.wallpapers" # Change this to your wallpaper directory
|
set -euo pipefail
|
||||||
CACHE_DIR="$HOME/.cache/wallpaper-selector"
|
DIR="${HOME}/.wallpapers"
|
||||||
THUMBNAIL_WIDTH="250" # Size of thumbnails in pixels (16:9)
|
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper-thumbs"
|
||||||
THUMBNAIL_HEIGHT="141"
|
[[ -d "$DIR" ]] || { notify-send "wallpaper.sh" "No $DIR"; exit 1; }
|
||||||
# Create cache directory if it doesn't exist
|
mkdir -p "$CACHE"
|
||||||
mkdir -p "$CACHE_DIR"
|
|
||||||
|
|
||||||
# Function to generate thumbnail
|
mapfile -t files < <(find -L "$DIR" -maxdepth 1 -type f \
|
||||||
generate_thumbnail() {
|
\( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.webp' \) \
|
||||||
local input="$1"
|
-printf '%f\n' | LC_ALL=C sort)
|
||||||
local output="$2"
|
[[ ${#files[@]} -gt 0 ]] || { notify-send "wallpaper.sh" "No images found"; exit 1; }
|
||||||
magick "$input" -thumbnail "${THUMBNAIL_WIDTH}x${THUMBNAIL_HEIGHT}^" -gravity center -extent "${THUMBNAIL_WIDTH}x${THUMBNAIL_HEIGHT}" "$output"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create shuffle icon thumbnail on the fly
|
# Build any missing/stale thumbnails, in parallel.
|
||||||
SHUFFLE_ICON="$CACHE_DIR/shuffle_thumbnail.png"
|
for f in "${files[@]}"; do
|
||||||
# Create a properly sized shuffle icon thumbnail
|
src="${DIR}/${f}"
|
||||||
# magick -size "${THUMBNAIL_WIDTH}x${THUMBNAIL_HEIGHT}" xc:#1e1e2e \
|
thumb="${CACHE}/${f%.*}.png"
|
||||||
# "$HOME/Repos/wallpaper-selector/assets/shuffle.png" -resize "120x120" -gravity center -composite \
|
[[ -f "$thumb" && "$thumb" -nt "$src" ]] && continue
|
||||||
# "$SHUFFLE_ICON"
|
magick "$src" -thumbnail 360x360^ -strip "$thumb" &
|
||||||
magick -size "${THUMBNAIL_WIDTH}x${THUMBNAIL_HEIGHT}" xc:#1e1e2e \
|
done
|
||||||
\( "$HOME/Repos/wallpaper-selector/assets/shuffle.png" -resize "80x80" \) \
|
wait
|
||||||
-gravity center -composite "$SHUFFLE_ICON"
|
|
||||||
|
|
||||||
# Generate thumbnails and create menu items
|
RANDOM_LABEL="🎲 Random"
|
||||||
generate_menu() {
|
menu="img::text:${RANDOM_LABEL}\n"
|
||||||
# Add random/shuffle option with a name that sorts first (using ! prefix)
|
for f in "${files[@]}"; do
|
||||||
echo -en "img:$SHUFFLE_ICON\x00info:!Random Wallpaper\x1fRANDOM\n"
|
menu+="img:${CACHE}/${f%.*}.png:text:${f}\n"
|
||||||
|
done
|
||||||
# Then add all wallpapers
|
|
||||||
for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do
|
|
||||||
# Skip if no matches found
|
|
||||||
[[ -f "$img" ]] || continue
|
|
||||||
|
|
||||||
# Generate thumbnail filename
|
|
||||||
thumbnail="$CACHE_DIR/$(basename "${img%.*}").png"
|
|
||||||
|
|
||||||
# Generate thumbnail if it doesn't exist or is older than source
|
|
||||||
if [[ ! -f "$thumbnail" ]] || [[ "$img" -nt "$thumbnail" ]]; then
|
|
||||||
generate_thumbnail "$img" "$thumbnail"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Output menu item (filename and path)
|
|
||||||
echo -en "img:$thumbnail\x00info:$(basename "$img")\x1f$img\n"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use wofi to display grid of wallpapers - IMPORTANT: added --sort-order=default
|
line=$(echo -en "$menu" | wofi \
|
||||||
selected=$(generate_menu | wofi --show dmenu \
|
--dmenu --show dmenu --allow-images --insensitive \
|
||||||
--cache-file /dev/null \
|
--define image_size=180 --columns 4 --prompt "Wallpaper" \
|
||||||
--define "image-size=${THUMBNAIL_WIDTH}x${THUMBNAIL_HEIGHT}" \
|
--define sort_order=default --cache-file /dev/null \
|
||||||
--columns 3 \
|
--style "${HOME}/.config/wofi/wallpaper.css" \
|
||||||
--allow-images \
|
--width 900 --height 620 --define halign=fill --define content_halign=fill)
|
||||||
--insensitive \
|
[[ -n "$line" ]] || exit 0
|
||||||
--sort-order=default \
|
|
||||||
--prompt "Select Wallpaper" \
|
|
||||||
--conf ~/.config/wofi/wallpaper.conf \
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set wallpaper if one was selected
|
if [[ "$line" == *"$RANDOM_LABEL"* ]]; then
|
||||||
if [ -n "$selected" ]; then
|
WALL="${DIR}/${files[RANDOM % ${#files[@]}]}"
|
||||||
# Remove the img: prefix to get the cached thumbnail path
|
else
|
||||||
thumbnail_path="${selected#img:}"
|
choice="${line##*:text:}"
|
||||||
|
WALL="${DIR}/${choice}"
|
||||||
# Check if random wallpaper was selected
|
|
||||||
if [[ "$thumbnail_path" == "$SHUFFLE_ICON" ]]; then
|
|
||||||
# Select a random wallpaper from the directory
|
|
||||||
original_path=$(find "$WALLPAPER_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) | shuf -n 1)
|
|
||||||
else
|
|
||||||
# Get the original filename from the thumbnail path
|
|
||||||
original_filename=$(basename "${thumbnail_path%.*}")
|
|
||||||
|
|
||||||
# Find the corresponding original file in the wallpaper directory
|
|
||||||
original_path=$(find "$WALLPAPER_DIR" -type f -name "${original_filename}.*" | head -n1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ensure a valid wallpaper was found before proceeding
|
|
||||||
if [ -n "$original_path" ]; then
|
|
||||||
hyprctl hyprpaper wallpaper ",$original_path"
|
|
||||||
|
|
||||||
# Save the selection for persistence
|
|
||||||
echo "$original_path" > "$HOME/.cache/current_wallpaper"
|
|
||||||
|
|
||||||
# Optional: Notify user
|
|
||||||
notify-send "Wallpaper" "Wallpaper has been updated" -i "$original_path"
|
|
||||||
else
|
|
||||||
notify-send "Wallpaper Error" "Could not find the original wallpaper file."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
hyprctl hyprpaper wallpaper ",${WALL}"
|
||||||
|
|||||||
@@ -1,47 +1,61 @@
|
|||||||
|
/* wallpaper.sh picker — dark glass, cyan accent */
|
||||||
|
|
||||||
window {
|
window {
|
||||||
background-color: #1e1e2e;
|
background-color: rgba(16, 18, 27, 0.88);
|
||||||
border-radius: 8px;
|
border: 1px solid rgba(122, 162, 247, 0.35);
|
||||||
border: 2px solid #313244;
|
border-radius: 16px;
|
||||||
|
font-family: "JetBrainsMono Nerd Font", monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
#input {
|
#input {
|
||||||
margin: 2px;
|
margin: 12px;
|
||||||
padding: 4px;
|
padding: 10px 14px;
|
||||||
border-radius: 4px;
|
border: 1px solid rgba(122, 162, 247, 0.25);
|
||||||
border: none;
|
border-radius: 10px;
|
||||||
background-color: #313244;
|
background-color: rgba(26, 29, 42, 0.9);
|
||||||
color: #cdd6f4;
|
color: #c0caf5;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#input:focus {
|
||||||
|
border-color: rgba(125, 207, 255, 0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#inner-box {
|
#inner-box {
|
||||||
margin: 0px;
|
margin: 6px 12px 12px 12px;
|
||||||
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#outer-box {
|
#outer-box {
|
||||||
margin: 0px;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#scroll {
|
#scroll {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
}
|
|
||||||
|
|
||||||
#text {
|
|
||||||
margin: 2px;
|
|
||||||
color: #cdd6f4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#entry {
|
#entry {
|
||||||
padding: 2px;
|
margin: 6px;
|
||||||
margin: 0px;
|
padding: 6px;
|
||||||
border-radius: 4px;
|
border: 2px solid transparent;
|
||||||
|
border-radius: 12px;
|
||||||
|
background-color: rgba(36, 40, 59, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#entry:selected {
|
#entry:selected {
|
||||||
background-color: #313244;
|
border-color: #7dcfff;
|
||||||
|
background-color: rgba(125, 207, 255, 0.15);
|
||||||
}
|
}
|
||||||
|
|
||||||
#img {
|
#entry image {
|
||||||
margin: 2px;
|
border-radius: 8px;
|
||||||
padding-left: 4px;
|
}
|
||||||
border-radius: 4px;
|
|
||||||
|
#text {
|
||||||
|
color: #c0caf5;
|
||||||
|
margin: 0px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#entry:selected #text {
|
||||||
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user