From 39e03203eae20204c29ad2cb4fa07541bc238e03 Mon Sep 17 00:00:00 2001 From: hesam-init Date: Mon, 26 Feb 2024 21:26:26 +0330 Subject: [PATCH] feat: rofi video menu select --- .../.config/hypr/scripts/mpvpaper-random.sh | 2 +- .../rofi/wallpaper/type-1/wallpaper.sh | 42 ++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/hyprland/.config/hypr/scripts/mpvpaper-random.sh b/hyprland/.config/hypr/scripts/mpvpaper-random.sh index dfdc9d3..f3838ce 100755 --- a/hyprland/.config/hypr/scripts/mpvpaper-random.sh +++ b/hyprland/.config/hypr/scripts/mpvpaper-random.sh @@ -24,7 +24,7 @@ fi random_video=${video_files[$RANDOM % ${#video_files[@]}]} if [[ $(pidof mpvpaper) ]]; then - pkill -f mpvpaper + pkill mpvpaper fi mpvpaper -o "loop-file" "*" $random_video diff --git a/hyprland/.config/rofi/wallpaper/type-1/wallpaper.sh b/hyprland/.config/rofi/wallpaper/type-1/wallpaper.sh index 35f1e4b..a64b7ee 100755 --- a/hyprland/.config/rofi/wallpaper/type-1/wallpaper.sh +++ b/hyprland/.config/rofi/wallpaper/type-1/wallpaper.sh @@ -4,26 +4,24 @@ source $HOME/.config/environments/env.sh dir="$HOME/.config/rofi/wallpaper/type-1" theme='style-8' +thumbnail_dir="$LIVE_WALLPAPERS_DIR/thumbs" rofi_cmd() { rofi -dmenu -theme "${dir}/${theme}.rasi" } show_image_preview() { - find "$WALLPAPERS_DIR" -maxdepth 1 -type f \( -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png -o -iname \*.gif \) -exec basename {} \; | while read -r A; do - echo -en "$A\x00icon\x1f$WALLPAPERS_DIR/$A\n" - done -} - -show_video_preview() { - find "$LIVE_WALLPAPERS_DIR" -maxdepth 1 -type f \( -iname \*.mp4 \) -exec basename {} \; | while read -r A; do - echo -en "$A\x00icon\x1f$LIVE_WALLPAPERS_DIR/$A\n" + for image in "$WALLPAPERS_DIR"/*.{jpg,jpeg,png,gif}; do + [[ -e $image ]] || continue + filename=$(basename "$image") + echo -en "$filename\x00icon\x1f$WALLPAPERS_DIR/$filename\n" done } set_wallpaper() { if [ $WALLPAPER_DAEMON == "mpvpaper" ]; then - local wallpaper="$LIVE_WALLPAPERS_DIR/$1" + local base_name=$(basename "$1" .png) + local wallpaper="$LIVE_WALLPAPERS_DIR/$base_name.mp4" else local wallpaper="$WALLPAPERS_DIR/$1" fi @@ -72,14 +70,38 @@ set_wallpaper() { fi } +generate_video_thumbnails() { + mkdir -p "$thumbnail_dir" + total_files=$(find "$LIVE_WALLPAPERS_DIR" -maxdepth 1 -type f \( -iname \*.mp4 \) | wc -l) + processed_files=0 + + shopt -s nullglob + for video in "$LIVE_WALLPAPERS_DIR"/*.mp4; do + thumbnail="$LIVE_WALLPAPERS_DIR/thumbs/$(basename "$video" .mp4).png" + + if [ ! -f "$thumbnail" ]; then + dunstify -u low -t 1000 "Thumbnail Generation" + sleep 1 && ffmpeg -ss 00:00:02 -i "$video" -frames:v 1 "$thumbnail" + fi + done +} + +show_video_preview() { + for image in "$thumbnail_dir"/*.{jpg,jpeg,png,gif}; do + [[ -e $image ]] || continue + filename=$(basename "$image") + echo -en "$filename\x00icon\x1f$thumbnail_dir/$filename\n" + done +} + if [ $WALLPAPER_DAEMON == "mpvpaper" ]; then + generate_video_thumbnails choice=$(show_video_preview | rofi_cmd) else choice=$(show_image_preview | rofi_cmd) fi if [ -n "$choice" ]; then - echo $choice set_wallpaper "$choice" else echo "No wallpaper selected."