Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions home/alice.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ in
fzf
fastfetch
bun
oils-for-unix
sheldon
zsh-abbr
lazygit
Expand Down
126 changes: 126 additions & 0 deletions script/cycle_wallpaper.ysh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env ysh

forward_mode=0
reverse_mode=1
current_paper_path="$HOME/dotfiles/.config/hypr/env/CURRENT_PAPER"
wallpaper_dir="$HOME/Pictures/wallpapers/"
wallvideo_path="$HOME/Pictures/wallvideo/ok_geek_eyes_24.mp4"
mpvpaper_args="--hwdec=auto-safe --vo=gpu"

get_all() {
find "$1" -maxdepth 1 -type f | sort
}

get_first_path() {
get_all "$1" | head -n 1
}

get_next_path() {
local current_path="$1"
local listed_paths="$2"
local rev_mode="$3"
local matched

if (( rev_mode == forward_mode )); then
matched="$(printf '%s\n' "$listed_paths" | grep -Fx "$current_path" -A 1)"
else
matched="$(printf '%s\n' "$listed_paths" | grep -Fx "$current_path" -B 1)"
fi

local matched_lines
matched_lines="$(printf '%s\n' "$matched" | wc -l | tr -d ' ')"

if (( matched_lines != 2 )); then
if (( rev_mode == forward_mode )); then
printf '%s\n' "$listed_paths" | head -n 1
else
printf '%s\n' "$listed_paths" | tail -n 1
fi
else
if (( rev_mode == forward_mode )); then
printf '%s\n' "$matched" | tail -n 1
else
printf '%s\n' "$matched" | head -n 1
fi
fi
}

seq_or_rev() {
local rev_mode="$1"
local wallpaper_dir="$2"
local next

if [[ -s "$current_paper_path" ]]; then
local current_paper
current_paper="$(cat "$current_paper_path")"
if [[ -f "$current_paper" ]]; then
local list
list="$(get_all "$wallpaper_dir")"
next="$(get_next_path "$current_paper" "$list" "$rev_mode")"
else
next="$(get_first_path "$wallpaper_dir")"
fi
else
next="$(get_first_path "$wallpaper_dir")"
fi

printf '%s\n' "$next" >"$current_paper_path"
printf '%s\n' "$next"
}

random_paper() {
local wallpaper_dir="$1"
local randomed_path

randomed_path="$(find "$wallpaper_dir" -type f | shuf -n 1)"
printf '%s\n' "$randomed_path" >"$current_paper_path"
printf '%s\n' "$randomed_path"
}

toggle_systemtimer() {
if systemctl --user is-active --quiet cycle_wallpaper.timer; then
if systemctl --user stop cycle_wallpaper.timer; then
notify-send "Stop slideshow"
else
notify-send "Failed stop slideshow"
fi
else
if systemctl --user start cycle_wallpaper.timer; then
notify-send "Start slideshow"
else
notify-send "Failed start slideshow"
fi
fi
}

toggle_video() {
local v_pid
v_pid="$(pgrep mpvpaper || true)"

if [[ -n "$v_pid" ]]; then
if pkill mpvpaper; then
notify-send "Stop wallvideo"
else
notify-send "Failed stop wallvideo"
fi
else
if mpvpaper '*' "$wallvideo_path" -o "no-audio loop" --fork --mpv-args="$mpvpaper_args"; then
notify-send "Start wallvideo"
else
notify-send "Failed start wallvideo"
fi
fi
}

case "${1:-}" in
seq) wall_path="$(seq_or_rev "$forward_mode" "$wallpaper_dir")" ;;
rev) wall_path="$(seq_or_rev "$reverse_mode" "$wallpaper_dir")" ;;
rnd) wall_path="$(random_paper "$wallpaper_dir")" ;;
vdo) toggle_video && exit 0 || exit 1 ;;
pse) toggle_systemtimer && exit 0 || exit 1 ;;
*) wall_path="${2:-}" ;;
esac

mkdir -p "$HOME/dotfiles/.config/hypr/env"

awww img "$wall_path" --transition-type center --transition-duration 0.5
Loading