diff options
Diffstat (limited to 'config/hypr/scripts/Kitty_themes.sh')
| -rwxr-xr-x | config/hypr/scripts/Kitty_themes.sh | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/config/hypr/scripts/Kitty_themes.sh b/config/hypr/scripts/Kitty_themes.sh index 3183b20b..24a4ae11 100755 --- a/config/hypr/scripts/Kitty_themes.sh +++ b/config/hypr/scripts/Kitty_themes.sh @@ -12,22 +12,55 @@ kitty_themes_DiR="$HOME/.config/kitty/kitty-themes" # Kitty Themes Directory kitty_config="$HOME/.config/kitty/kitty.conf" iDIR="$HOME/.config/swaync/images" # For notifications rofi_theme_for_this_script="$HOME/.config/rofi/config-kitty-theme.rasi" +wallust_refresh_script="$HOME/.config/hypr/scripts/WallustSwww.sh" +debug_log="${XDG_CACHE_HOME:-$HOME/.cache}/kooldots-kitty-themes.log" # --- Helper Functions --- notify_user() { notify-send -u low -i "$1" "$2" "$3" } +log_debug() { + mkdir -p "$(dirname "$debug_log")" 2>/dev/null || true + printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >>"$debug_log" 2>/dev/null || true +} + +resolve_theme_selection() { + local rofi_output="$1" + local idx + + rofi_output="${rofi_output//$'\r'/}" + rofi_output="${rofi_output//$'\n'/}" + + if [[ "$rofi_output" =~ ^[0-9]+$ ]] && [ "$rofi_output" -lt "${#available_theme_names[@]}" ]; then + current_selection_index="$rofi_output" + theme_to_preview_now="${available_theme_names[$current_selection_index]}" + return 0 + fi + + for idx in "${!available_theme_names[@]}"; do + if [[ "${available_theme_names[$idx]}" == "$rofi_output" ]]; then + current_selection_index="$idx" + theme_to_preview_now="${available_theme_names[$current_selection_index]}" + return 0 + fi + done + + return 1 +} + # Function to apply the selected kitty theme apply_kitty_theme_to_config() { local theme_name_to_apply="$1" local apply_mode="${2:-preview}" + local is_wallpaper_mode=0 if [ -z "$theme_name_to_apply" ]; then echo "Error: No theme name provided to apply_kitty_theme_to_config." >&2 return 1 fi local theme_file_path_to_apply if [ "$theme_name_to_apply" = "Set by wallpaper" ]; then + is_wallpaper_mode=1 theme_file_path_to_apply="$kitty_themes_DiR/01-Wallust.conf" elif [ "$theme_name_to_apply" = "Default no color" ]; then theme_file_path_to_apply="$kitty_themes_DiR/00-Default.conf" @@ -58,10 +91,20 @@ apply_kitty_theme_to_config() { cp "$temp_kitty_config_file" "$kitty_config" rm "$temp_kitty_config_file" + local trigger_wallust_refresh=0 + if [ "$theme_name_to_apply" = "Set by wallpaper" ] && [ -x "$wallust_refresh_script" ]; then + trigger_wallust_refresh=1 + fi + if [ "$trigger_wallust_refresh" -eq 1 ]; then + "$wallust_refresh_script" >/dev/null 2>&1 & + log_debug "wallust_refresh_background_started" + fi if pidof kitty >/dev/null 2>&1; then - if [ "$apply_mode" = "apply" ] && command -v kitty >/dev/null 2>&1; then - kitty @ load-config >/dev/null 2>&1 - kitty @ set-colors --all --configured "$theme_file_path_to_apply" >/dev/null 2>&1 + if [ "$apply_mode" = "apply" ] && [ "$is_wallpaper_mode" -eq 0 ] && command -v kitty >/dev/null 2>&1; then + ( + kitty @ load-config >/dev/null 2>&1 || true + kitty @ set-colors --all --configured "$theme_file_path_to_apply" >/dev/null 2>&1 || true + ) & fi for pid_kitty in $(pidof kitty); do if [ -n "$pid_kitty" ]; then @@ -110,6 +153,7 @@ if [ -n "$current_active_theme_name" ]; then fi done fi +theme_to_preview_now="${available_theme_names[$current_selection_index]}" while true; do @@ -119,21 +163,22 @@ while true; do done rofi_input_list_trimmed="${rofi_input_list%\\n}" - chosen_index_from_rofi=$(echo -e "$rofi_input_list_trimmed" | + chosen_selection_from_rofi=$(echo -e "$rofi_input_list_trimmed" | rofi -dmenu -i \ + -no-custom \ -format 'i' \ -p "Kitty Theme" \ - -mesg "Enter: Preview | Ctrl+S: Apply & Exit | Esc: Cancel" \ + -mesg "Enter: Preview | Ctrl+S (or Alt+1): Apply & Exit | Esc: Cancel" \ -config "$rofi_theme_for_this_script" \ -selected-row "$current_selection_index" \ - -kb-custom-1 "Control+s") + -kb-custom-1 "Control+s,Control+S,Alt+1") rofi_exit_code=$? + log_debug "rofi_exit=$rofi_exit_code rofi_output='${chosen_selection_from_rofi}' current_index=$current_selection_index current_theme='${available_theme_names[$current_selection_index]}'" if [ $rofi_exit_code -eq 0 ]; then - if [[ "$chosen_index_from_rofi" =~ ^[0-9]+$ ]] && [ "$chosen_index_from_rofi" -lt "${#available_theme_names[@]}" ]; then - current_selection_index="$chosen_index_from_rofi" - theme_to_preview_now="${available_theme_names[$current_selection_index]}" + if resolve_theme_selection "$chosen_selection_from_rofi"; then + log_debug "resolved_enter index=$current_selection_index theme='${theme_to_preview_now}'" if ! apply_kitty_theme_to_config "$theme_to_preview_now" "preview"; then echo "$original_kitty_config_content_backup" >"$kitty_config" for pid_kitty in $(pidof kitty); do if [ -n "$pid_kitty" ]; then kill -SIGUSR1 "$pid_kitty"; fi; done @@ -149,7 +194,9 @@ while true; do echo "$original_kitty_config_content_backup" >"$kitty_config" for pid_kitty in $(pidof kitty); do if [ -n "$pid_kitty" ]; then kill -SIGUSR1 "$pid_kitty"; fi; done break - elif [ $rofi_exit_code -eq 10 ]; then # This is the exit code for -kb-custom-1 + elif [ $rofi_exit_code -ge 10 ] && [ $rofi_exit_code -le 28 ]; then # custom keybindings + resolve_theme_selection "$chosen_selection_from_rofi" || true + log_debug "resolved_custom index=$current_selection_index theme='${theme_to_preview_now}' exit=$rofi_exit_code" apply_kitty_theme_to_config "$theme_to_preview_now" "apply" notify_user "$iDIR/ja.png" "Kitty Theme Applied" "$theme_to_preview_now" break |
