diff options
Diffstat (limited to 'config/hypr/UserScripts')
| -rwxr-xr-x | config/hypr/UserScripts/RofiBeats.sh | 37 | ||||
| -rwxr-xr-x | config/hypr/UserScripts/WallpaperEffects.sh | 5 | ||||
| -rwxr-xr-x | config/hypr/UserScripts/WallpaperSelect.sh | 259 | ||||
| -rwxr-xr-x | config/hypr/UserScripts/ZshChangeTheme.sh | 4 |
4 files changed, 195 insertions, 110 deletions
diff --git a/config/hypr/UserScripts/RofiBeats.sh b/config/hypr/UserScripts/RofiBeats.sh index b134c8a2..781e9f64 100755 --- a/config/hypr/UserScripts/RofiBeats.sh +++ b/config/hypr/UserScripts/RofiBeats.sh @@ -1,6 +1,6 @@ #!/bin/bash # /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ## -# For Rofi Beats to play online Music or Locally save media files +# For Rofi Beats to play online Music or Locally saved media files # Variables mDIR="$HOME/Music/" @@ -41,7 +41,7 @@ populate_local_music() { # Function for displaying notifications notification() { - notify-send -u normal -i "$iDIR/music.png" " Now Playing:" " $@" + notify-send -u normal -i "$iDIR/music.png" "Now Playing:" "$@" } # Main function for playing local music @@ -60,8 +60,6 @@ play_local_music() { if [ "${filenames[$i]}" = "$choice" ]; then notification "$choice" - - # Play the selected local music file using mpv mpv --playlist-start="$i" --loop-playlist --vid=no "${local_music[@]}" break @@ -95,18 +93,30 @@ play_online_music() { mpv --shuffle --vid=no "$link" } +# Function to stop music and kill mpv processes +stop_music() { + mpv_pids=$(pgrep -x mpv) -# Check if an online music process is running and send a notification, otherwise run the main function -pkill mpv && notify-send -u low -i "$iDIR/music.png" "Music stopped" || { + if [ -n "$mpv_pids" ]; then + # Get the PID of the mpv process used by mpvpaper (using the unique argument added) + mpvpaper_pid=$(ps aux | grep -- 'unique-wallpaper-process' | grep -v 'grep' | awk '{print $2}') -# Check if rofi is already running -if pidof rofi > /dev/null; then - pkill rofi -fi + for pid in $mpv_pids; do + if ! echo "$mpvpaper_pid" | grep -q "$pid"; then + kill -9 $pid || true + fi + done + notify-send -u low -i "$iDIR/music.png" "Music stopped" || true + fi +} +# Check if music is already playing +if pgrep -x "mpv" > /dev/null; then + stop_music +else + user_choice=$(printf "Play from Online Stations\nPlay from Music directory\nShuffle Play from Music directory" | rofi -dmenu -config $rofi_theme_1) -# Prompt the user to choose between local and online music -user_choice=$(printf "Play from Online Stations\nPlay from Music directory\nShuffle Play from Music directory" | rofi -dmenu -config $rofi_theme_1) + echo "User choice: $user_choice" case "$user_choice" in "Play from Music directory") @@ -119,7 +129,6 @@ user_choice=$(printf "Play from Online Stations\nPlay from Music directory\nShuf shuffle_local_music ;; *) - echo "Invalid choice" ;; esac -} +fi
\ No newline at end of file diff --git a/config/hypr/UserScripts/WallpaperEffects.sh b/config/hypr/UserScripts/WallpaperEffects.sh index 7b1cf00b..b1d1a4b1 100755 --- a/config/hypr/UserScripts/WallpaperEffects.sh +++ b/config/hypr/UserScripts/WallpaperEffects.sh @@ -76,6 +76,11 @@ main() { # Apply selected effect notify-send -u normal -i "$iDIR/ja.png" "Applying:" "$choice effects" eval "${effects[$choice]}" + + # intial kill process + for pid in swaybg mpvpaper; do + killall -SIGUSR1 "$pid" + done sleep 1 swww img -o "$focused_monitor" "$wallpaper_output" $SWWW_PARAMS & diff --git a/config/hypr/UserScripts/WallpaperSelect.sh b/config/hypr/UserScripts/WallpaperSelect.sh index cf677f9c..b5943586 100755 --- a/config/hypr/UserScripts/WallpaperSelect.sh +++ b/config/hypr/UserScripts/WallpaperSelect.sh @@ -1,5 +1,5 @@ #!/bin/bash -# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ +# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ # This script for selecting wallpapers (SUPER W) # WALLPAPERS PATH @@ -12,42 +12,57 @@ wallpaper_current="$HOME/.config/hypr/wallpaper_effects/.wallpaper_current" iDIR="$HOME/.config/swaync/images" iDIRi="$HOME/.config/swaync/icons" +# swww transition config +FPS=60 +TYPE="any" +DURATION=2 +BEZIER=".43,1.19,1,.4" +SWWW_PARAMS="--transition-fps $FPS --transition-type $TYPE --transition-duration $DURATION --transition-bezier $BEZIER" + # Check if package bc exists if ! command -v bc &>/dev/null; then -notify-send -i "$iDIR/ja.png" "bc missing" "Install package bc first" -exit 1 + notify-send -i "$iDIR/error.png" "bc missing" "Install package bc first" + exit 1 fi -# variables +# Variables rofi_theme="$HOME/.config/rofi/config-wallpaper.rasi" focused_monitor=$(hyprctl monitors -j | jq -r '.[] | select(.focused) | .name') +# Ensure focused_monitor is detected +if [[ -z "$focused_monitor" ]]; then + notify-send -i "$iDIR/error.png" "E-R-R-O-R" "Could not detect focused monitor" + exit 1 +fi + # Monitor details scale_factor=$(hyprctl monitors -j | jq -r --arg mon "$focused_monitor" '.[] | select(.name == $mon) | .scale') monitor_height=$(hyprctl monitors -j | jq -r --arg mon "$focused_monitor" '.[] | select(.name == $mon) | .height') icon_size=$(echo "scale=1; ($monitor_height * 3) / ($scale_factor * 150)" | bc) - -# Apply limit adjusted_icon_size=$(echo "$icon_size" | awk '{if ($1 < 15) $1 = 20; if ($1 > 25) $1 = 25; print $1}') - -# Setting the rofi override with the adjusted icon size rofi_override="element-icon{size:${adjusted_icon_size}%;}" -# swww transition config -FPS=60 -TYPE="any" -DURATION=2 -BEZIER=".43,1.19,1,.4" -SWWW_PARAMS="--transition-fps $FPS --transition-type $TYPE --transition-duration $DURATION --transition-bezier $BEZIER" +# Kill existing wallpaper daemons for video +kill_wallpaper_for_video() { + swww kill 2>/dev/null + pkill mpvpaper 2>/dev/null + pkill swaybg 2>/dev/null + pkill hyprpaper 2>/dev/null +} -# Check if swaybg is running -if pidof swaybg > /dev/null; then - pkill swaybg -fi +# Kill existing wallpaper daemons for image +kill_wallpaper_for_image() { + pkill mpvpaper 2>/dev/null + pkill swaybg 2>/dev/null + pkill hyprpaper 2>/dev/null +} -# Retrieve image files using null delimiter to handle spaces in filenames -mapfile -d '' PICS < <(find -L "${wallDIR}" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.pnm" -o -iname "*.tga" -o -iname "*.tiff" -o -iname "*.webp" -o -iname "*.bmp" -o -iname "*.farbfeld" -o -iname "*.png" -o -iname "*.gif" \) -print0) +# Retrieve wallpapers (both images & videos) +mapfile -d '' PICS < <(find -L "${wallDIR}" -type f \( \ + -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o \ + -iname "*.bmp" -o -iname "*.tiff" -o -iname "*.webp" -o \ + -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \) -print0) RANDOM_PIC="${PICS[$((RANDOM % ${#PICS[@]}))]}" RANDOM_PIC_NAME=". random" @@ -57,112 +72,168 @@ rofi_command="rofi -i -show -dmenu -config $rofi_theme -theme-str $rofi_override # Sorting Wallpapers menu() { - # Sort the PICS array IFS=$'\n' sorted_options=($(sort <<<"${PICS[*]}")) - - # Place ". random" at the beginning with the random picture as an icon + printf "%s\x00icon\x1f%s\n" "$RANDOM_PIC_NAME" "$RANDOM_PIC" - + for pic_path in "${sorted_options[@]}"; do pic_name=$(basename "$pic_path") - - # Displaying .gif to indicate animated images - if [[ ! "$pic_name" =~ \.gif$ ]]; then - printf "%s\x00icon\x1f%s\n" "$(echo "$pic_name" | cut -d. -f1)" "$pic_path" + if [[ "$pic_name" =~ \.gif$ ]]; then + cache_gif_image="$HOME/.cache/gif_preview/${pic_name}.png" + if [[ ! -f "$cache_gif_image" ]]; then + mkdir -p "$HOME/.cache/gif_preview" + magick "$pic_path[0]" -resize 1920x1080 "$cache_gif_image" + fi + printf "%s\x00icon\x1f%s\n" "$pic_name" "$cache_gif_image" + elif [[ "$pic_name" =~ \.(mp4|mkv|mov|webm|MP4|MKV|MOV|WEBM)$ ]]; then + cache_preview_image="$HOME/.cache/video_preview/${pic_name}.png" + if [[ ! -f "$cache_preview_image" ]]; then + mkdir -p "$HOME/.cache/video_preview" + ffmpeg -v error -y -i "$pic_path" -ss 00:00:01.000 -vframes 1 "$cache_preview_image" + fi + printf "%s\x00icon\x1f%s\n" "$pic_name" "$cache_preview_image" else - printf "%s\n" "$pic_name" + printf "%s\x00icon\x1f%s\n" "$(echo "$pic_name" | cut -d. -f1)" "$pic_path" fi done } -# initiate swww if not running -swww query || swww-daemon --format xrgb +# Offer SDDM Sequioa Wallpaper Option (only for non-video wallpapers) +set_sddm_wallpaper() { + sleep 1 + sddm_sequoia="/usr/share/sddm/themes/sequoia_2" + + if [ -d "$sddm_sequoia" ]; then + + # Check if yad is running to avoid multiple notifications + if pidof yad >/dev/null; then + killall yad + fi + + if yad --info --text="Set current wallpaper as SDDM background?\n\nNOTE: This only applies to SEQUOIA SDDM Theme" \ + --text-align=left \ + --title="SDDM Background" \ + --timeout=5 \ + --timeout-indicator=right \ + --button="yes:0" \ + --button="no:1"; then + + # Check if terminal exists + if ! command -v "$terminal" &>/dev/null; then + notify-send -i "$iDIR/error.png" "Missing $terminal" "Install $terminal to enable setting of wallpaper background" + exit 1 + fi + + # Open terminal to enter password + $terminal -e bash -c "echo 'Enter your password to set wallpaper as SDDM Background'; \ + sudo cp -r $wallpaper_current '$sddm_sequoia/backgrounds/default' && \ + notify-send -i '$iDIR/ja.png' 'SDDM' 'Background SET'" + fi + fi +} + +modify_startup_config() { + local selected_file="$1" + local startup_config="$HOME/.config/hypr/UserConfigs/Startup_Apps.conf" + + # Check if it's a live wallpaper (video) + if [[ "$selected_file" =~ \.(mp4|mkv|mov|webm)$ ]]; then + # For video wallpapers: + sed -i '/^\s*exec-once\s*=\s*swww-daemon\s*--format\s*xrgb\s*$/s/^/\#/' "$startup_config" + sed -i '/^\s*#\s*exec-once\s*=\s*mpvpaper\s*.*$/s/^#\s*//;' "$startup_config" + + # Update the livewallpaper variable with the selected video path (using $HOME) + selected_file="${selected_file/#$HOME/\$HOME}" # Replace /home/user with $HOME + sed -i "s|^\$livewallpaper=.*|\$livewallpaper=\"$selected_file\"|" "$startup_config" -# Choice of wallpapers + echo "Configured for live wallpaper (video)." + else + # For image wallpapers: + sed -i '/^\s*#\s*exec-once\s*=\s*swww-daemon\s*--format\s*xrgb\s*$/s/^\s*#\s*//;' "$startup_config" + + sed -i '/^\s*exec-once\s*=\s*mpvpaper\s*.*$/s/^/\#/' "$startup_config" + + echo "Configured for static wallpaper (image)." + fi +} + +# Apply Image Wallpaper +apply_image_wallpaper() { + local image_path="$1" + + kill_wallpaper_for_image + + if ! pgrep -x "swww-daemon" >/dev/null; then + echo "Starting swww-daemon..." + swww-daemon --format xrgb & + fi + + swww img -o "$focused_monitor" "$image_path" $SWWW_PARAMS + + # Run additional scripts + "$SCRIPTSDIR/WallustSwww.sh" + sleep 2 + "$SCRIPTSDIR/Refresh.sh" + sleep 1 + + set_sddm_wallpaper +} + +apply_video_wallpaper() { + local video_path="$1" + + # Check if mpvpaper is installed + if ! command -v mpvpaper &>/dev/null; then + notify-send -i "$iDIR/error.png" "E-R-R-O-R" "mpvpaper not found" + return 1 + fi + kill_wallpaper_for_video + + # Apply video wallpaper using mpvpaper + mpvpaper '*' -o "load-scripts=no no-audio --loop" "$video_path" & +} + +# Main function main() { choice=$(menu | $rofi_command) - choice=$(echo "$choice" | xargs) RANDOM_PIC_NAME=$(echo "$RANDOM_PIC_NAME" | xargs) - # No choice case if [[ -z "$choice" ]]; then echo "No choice selected. Exiting." exit 0 fi - # Random choice case + # Handle random selection correctly if [[ "$choice" == "$RANDOM_PIC_NAME" ]]; then - swww img -o "$focused_monitor" "$RANDOM_PIC" $SWWW_PARAMS; - sleep 2 - "$SCRIPTSDIR/WallustSwww.sh" - sleep 0.5 - "$SCRIPTSDIR/Refresh.sh" - exit 0 + choice=$(basename "$RANDOM_PIC") fi - pic_index=-1 - for i in "${!PICS[@]}"; do - filename=$(basename "${PICS[$i]}") - if [[ "$filename" == "$choice"* ]]; then - pic_index=$i - break - fi - done + choice_basename=$(basename "$choice" | sed 's/\(.*\)\.[^.]*$/\1/') - if [[ $pic_index -ne -1 ]]; then - swww img -o "$focused_monitor" "${PICS[$pic_index]}" $SWWW_PARAMS - else - echo "Image not found." + # Search for the selected file in the wallpapers directory, including subdirectories + selected_file=$(find "$wallDIR" -iname "$choice_basename.*" -print -quit) + + if [[ -z "$selected_file" ]]; then + echo "File not found. Selected choice: $choice" exit 1 fi + # Modify the Startup_Apps.conf file based on wallpaper type + modify_startup_config "$selected_file" + + # **CHECK FIRST** if it's a video or an image **before calling any function** + if [[ "$selected_file" =~ \.(mp4|mkv|mov|webm|MP4|MKV|MOV|WEBM)$ ]]; then + apply_video_wallpaper "$selected_file" + else + apply_image_wallpaper "$selected_file" + fi } # Check if rofi is already running -if pidof rofi > /dev/null; then +if pidof rofi >/dev/null; then pkill rofi fi main -wait $! -"$SCRIPTSDIR/WallustSwww.sh" && - -wait $! -sleep 2 -"$SCRIPTSDIR/Refresh.sh" - -sleep 1 -# Check if user selected a wallpaper -if [[ -n "$choice" ]]; then - sddm_sequoia="/usr/share/sddm/themes/sequoia_2" - if [ -d "$sddm_sequoia" ]; then - - # Check if yad is running to avoid multiple yad notification - if pidof yad > /dev/null; then - killall yad - fi - - if yad --info --text="Set current wallpaper as SDDM background?\n\nNOTE: This only applies to SEQUOIA SDDM Theme" \ - --text-align=left \ - --title="SDDM Background" \ - --timeout=5 \ - --timeout-indicator=right \ - --button="yad-yes:0" \ - --button="yad-no:1" \ - ; then - - # Check if terminal exists - if ! command -v "$terminal" &>/dev/null; then - notify-send -i "$iDIR/ja.png" "Missing $terminal" "Install $terminal to enable setting of wallpaper background" - exit 1 - fi - - # Open terminal to enter password - $terminal -e bash -c "echo 'Enter your password to set wallpaper as SDDM Background'; \ - sudo cp -r $wallpaper_current '$sddm_sequoia/backgrounds/default' && \ - notify-send -i '$iDIR/ja.png' 'SDDM' 'Background SET'" - fi - fi -fi
\ No newline at end of file diff --git a/config/hypr/UserScripts/ZshChangeTheme.sh b/config/hypr/UserScripts/ZshChangeTheme.sh index 4919a890..cffaf5cb 100755 --- a/config/hypr/UserScripts/ZshChangeTheme.sh +++ b/config/hypr/UserScripts/ZshChangeTheme.sh @@ -10,7 +10,7 @@ iDIR="$HOME/.config/swaync/images" rofi_theme="$HOME/.config/rofi/config-zsh-theme.rasi" if [ -n "$(grep -i nixos < /etc/os-release)" ]; then - notify-send -i "$iDIR/ja.png" "NOT Supported" "Sorry NixOS does not support this KooL feature" + notify-send -i "$iDIR/note.png" "NOT Supported" "Sorry NixOS does not support this KooL feature" exit 1 fi @@ -57,7 +57,7 @@ main() { sed -i "s/^$var_name=.*/$var_name=\"$theme_to_set\"/" "$zsh_path" notify-send -i "$iDIR/ja.png" "OMZ theme" "applied. restart your terminal" else - notify-send -i "$iDIR/ja.png" "Error:" "~.zshrc file not found!" + notify-send -i "$iDIR/error.png" "E-R-R-O-R" "~.zshrc file not found!" fi } |
