From b3fecd0ba7fe6732b47a736e48f6595b39304acb Mon Sep 17 00:00:00 2001 From: hesam-init Date: Wed, 14 Feb 2024 21:39:59 +0330 Subject: [PATCH] feat: random wallpaper switcher --- .../hypr/conf/keybindings/default.conf | 3 ++ hyprland/.config/hypr/hyprland.conf | 1 + hyprland/.config/hypr/scripts/env.sh | 5 +++ hyprland/.config/hypr/scripts/swww-launch.sh | 8 ++--- hyprland/.config/hypr/scripts/swww-random.sh | 33 +++++++++++++++++++ hyprland/.config/rofi/applets/bin/swww.sh | 0 6 files changed, 44 insertions(+), 6 deletions(-) create mode 100755 hyprland/.config/hypr/scripts/swww-random.sh create mode 100644 hyprland/.config/rofi/applets/bin/swww.sh diff --git a/hyprland/.config/hypr/conf/keybindings/default.conf b/hyprland/.config/hypr/conf/keybindings/default.conf index 5e650f0..474df3f 100644 --- a/hyprland/.config/hypr/conf/keybindings/default.conf +++ b/hyprland/.config/hypr/conf/keybindings/default.conf @@ -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 diff --git a/hyprland/.config/hypr/hyprland.conf b/hyprland/.config/hypr/hyprland.conf index 22abfc5..f52577f 100644 --- a/hyprland/.config/hypr/hyprland.conf +++ b/hyprland/.config/hypr/hyprland.conf @@ -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 diff --git a/hyprland/.config/hypr/scripts/env.sh b/hyprland/.config/hypr/scripts/env.sh index 357eccb..40796b9 100755 --- a/hyprland/.config/hypr/scripts/env.sh +++ b/hyprland/.config/hypr/scripts/env.sh @@ -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 diff --git a/hyprland/.config/hypr/scripts/swww-launch.sh b/hyprland/.config/hypr/scripts/swww-launch.sh index 3cf3d82..3051697 100755 --- a/hyprland/.config/hypr/scripts/swww-launch.sh +++ b/hyprland/.config/hypr/scripts/swww-launch.sh @@ -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 diff --git a/hyprland/.config/hypr/scripts/swww-random.sh b/hyprland/.config/hypr/scripts/swww-random.sh new file mode 100755 index 0000000..9bb0918 --- /dev/null +++ b/hyprland/.config/hypr/scripts/swww-random.sh @@ -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 diff --git a/hyprland/.config/rofi/applets/bin/swww.sh b/hyprland/.config/rofi/applets/bin/swww.sh new file mode 100644 index 0000000..e69de29