summaryrefslogtreecommitdiffstats
path: root/roles/hyprtheme/files/scripts/wallpaper.sh
blob: 35654b94d40dab993a10f2f5ea3dbd901337ae7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

show_wallpapers() {
  local wallpapers_path="$HOME/.config/hyprtheme/current/wallpapers"
  local wallpapers=$(ls -1p "$wallpapers_path" 2>/dev/null)

  if [[ -z $wallpapers ]]; then
    notify-send -e \
        -h string:x-canonical-private-synchronous:wallpapers \
        -u normal \
        "Wallpapers" \
        "No wallpapers found for current theme"
    pkill -x swaybg
    setsid uwsm-app -- swaybg --color '#000000' >/dev/null 2>&1 &
    exit 0
  fi

  local selected_wallpaper=$(printf "$wallpapers" | tofi \
    --prompt-text "Select: " \
    --placeholder-text "Wallpaper"
  )
  if [[ -n $selected_wallpaper ]]; then
    select_wallpaper "$wallpapers_path/$selected_wallpaper"
  fi
}

select_wallpaper() {
  local selected_wallpaper="$1"
  if [[ ! -f "$selected_wallpaper" ]]; then
    notify-send -e \
        -h string:x-canonical-private-synchronous:wallpapers \
        -u critical \
        "Wallpapers" \
        "Wallpaper '$selected_wallpaper' doesn't exist"
    pkill -x swaybg
    setsid uwsm-app -- swaybg --color '#000000' >/dev/null 2>&1 &
    exit 0
  fi

  pkill -x swaybg
  setsid uwsm-app -- swaybg -i "$selected_wallpaper" -m fill >/dev/null 2>&1 &
}

if [[ -z "$1" ]]; then
  show_wallpapers
else
  select_wallpaper "$1"
fi