feat: random wallpaper switcher

This commit is contained in:
hesam-init 2024-02-14 21:39:59 +03:30
parent 2ed8d68ade
commit b3fecd0ba7
6 changed files with 44 additions and 6 deletions

View file

@ -25,6 +25,9 @@ bind = $mainMod ALT, down, movewindow, d
bind = $mainMod, PRINT, exec, $screenshot -m window
bind = , PRINT, exec, $screenshot -m output
# Wallpaper
bind = $mainMod, Y, exec, $swww_random
# Audio control
binde=,XF86AudioRaiseVolume,exec, $volume_control u
binde=,XF86AudioLowerVolume,exec, $volume_control d

View file

@ -17,6 +17,7 @@ $mainMod = SUPER
$terminal = alacritty
$fileManager = dolphin
$screenshot = $scr_path/hyprshot.sh
$swww_random = $scr_path/swww-random.sh
$waybar_toggle = $scr_path/waybar-toggle.sh
$volume_control = $scr_path/volume-control.sh
$rofi_menu = $scr_path/rofi-launch.sh d

View file

@ -10,3 +10,8 @@ export waybar_theme="river"
export waybar_dir="$HOME/.config/waybar/$waybar_theme"
export waybar_launcher="waybar -c $waybar_dir/config.jsonc -s $waybar_dir/style.css"
export inotify_events="-e close_write,move,create"
# swww env :
export wallpapers_dir="$HOME/Wallpapers"
export swww_fps=75
export swww_duration=2

View file

@ -1,10 +1,6 @@
#!/usr/bin/env bash
FPS=75
DIR=$HOME/Wallpapers/
PICS=($(ls ${DIR}))
RANDOMPICS=${PICS[$RANDOM % ${#PICS[@]}]}
source $HOME/.config/hypr/scripts/env.sh
if [[ $(pidof swaybg) ]]; then
pkill swaybg
@ -12,4 +8,4 @@ fi
swww query || swww init
swww img ${DIR}/${RANDOMPICS} --transition-fps $FPS --transition-type any --transition-duration 3
swww img $wallpapers_dir/macos.jpg --transition-fps $swww_fps --transition-type any --transition-duration $swww_duration

View file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
source $HOME/.config/hypr/scripts/env.sh
# Get only files from the directory
files=($(find "${wallpapers_dir}" -type f))
# Check if there are any files
if [ ${#files[@]} -eq 0 ]; then
echo "No files found in the directory: ${wallpapers_dir}"
exit 1
fi
# Filter files to include only those identified as images by the 'file' command
image_files=()
for file in "${files[@]}"; do
if file -b --mime-type "$file" | grep -q "^image/"; then
image_files+=("$file")
fi
done
# Check if there are any image files
if [ ${#image_files[@]} -eq 0 ]; then
echo "No image files found in the directory: ${wallpapers_dir}"
exit 1
fi
# Get a random image from the array
random_pic=${image_files[$RANDOM % ${#image_files[@]}]}
echo $random_pic
swww img "$random_pic" --transition-fps $swww_fps --transition-type any --transition-duration $swww_duration