diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-07-10 11:21:24 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-07-10 11:21:24 -0700 |
| commit | 24de2a31a52d17b6f7214197bdbfeab7428742dd (patch) | |
| tree | f7736c4712d5a394525a3da2f2b4294e81ba9540 /config/hypr/scripts/DarkLight.sh | |
| parent | 861bf5be200bfcf2440fec4cda911d29ec18493f (diff) | |
| parent | bca86bbec4757cec1f6f5bdea2ed210542f10fae (diff) | |
Merge remote-tracking branch 'upstream'
Diffstat (limited to 'config/hypr/scripts/DarkLight.sh')
| -rwxr-xr-x | config/hypr/scripts/DarkLight.sh | 138 |
1 files changed, 100 insertions, 38 deletions
diff --git a/config/hypr/scripts/DarkLight.sh b/config/hypr/scripts/DarkLight.sh index 5b1cc3e7..16f1a4ef 100755 --- a/config/hypr/scripts/DarkLight.sh +++ b/config/hypr/scripts/DarkLight.sh @@ -13,24 +13,79 @@ PICTURES_DIR="$(xdg-user-dir PICTURES 2>/dev/null || echo "$HOME/Pictures")" wallpaper_base_path="$PICTURES_DIR/wallpapers/Dynamic-Wallpapers" dark_wallpapers="$wallpaper_base_path/Dark" light_wallpapers="$wallpaper_base_path/Light" -hypr_config_path="$HOME/.config/hypr" -swaync_style="$HOME/.config/swaync/style.css" -ags_style="$HOME/.config/ags/user/style.css" -SCRIPTSDIR="$HOME/.config/hypr/scripts" +hypr_config_path="${XDG_CONFIG_HOME:-$HOME/.config}/hypr" +swaync_style="${XDG_CONFIG_HOME:-$HOME/.config}/swaync/style.css" +ags_style="${XDG_CONFIG_HOME:-$HOME/.config}/ags/user/style.css" +SCRIPTSDIR="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/scripts" # shellcheck source=/dev/null . "$SCRIPTSDIR/WallpaperCmd.sh" -notif="$HOME/.config/swaync/images/bell.png" -wallust_rofi="$HOME/.config/wallust/templates/colors-rofi.rasi" +notif="${XDG_CONFIG_HOME:-$HOME/.config}/swaync/images/bell.png" +wallust_rofi="${XDG_CONFIG_HOME:-$HOME/.config}/wallust/templates/colors-rofi.rasi" +theme_state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/hypr" +theme_state_file="$theme_state_dir/theme_mode" +legacy_theme_state_file="$HOME/.cache/.theme_mode" -kitty_conf="$HOME/.config/kitty/kitty.conf" +kitty_conf="${XDG_CONFIG_HOME:-$HOME/.config}/kitty/kitty.conf" -wallust_config="$HOME/.config/wallust/wallust.toml" +wallust_config="${XDG_CONFIG_HOME:-$HOME/.config}/wallust/wallust.toml" pallete_dark="dark16" pallete_light="light16" -qt5ct_dark="$HOME/.config/qt5ct/colors/Catppuccin-Mocha.conf" -qt5ct_light="$HOME/.config/qt5ct/colors/Catppuccin-Latte.conf" -qt6ct_dark="$HOME/.config/qt6ct/colors/Catppuccin-Mocha.conf" -qt6ct_light="$HOME/.config/qt6ct/colors/Catppuccin-Latte.conf" +qt5ct_dark="${XDG_CONFIG_HOME:-$HOME/.config}/qt5ct/colors/Catppuccin-Mocha.conf" +qt5ct_light="${XDG_CONFIG_HOME:-$HOME/.config}/qt5ct/colors/Catppuccin-Latte.conf" +qt6ct_dark="${XDG_CONFIG_HOME:-$HOME/.config}/qt6ct/colors/Catppuccin-Mocha.conf" +qt6ct_light="${XDG_CONFIG_HOME:-$HOME/.config}/qt6ct/colors/Catppuccin-Latte.conf" +apply_saved_mode=0 +notify_enabled=1 +preserve_wallpaper=0 +forced_mode="" + +normalize_mode() { + case "$1" in + Dark|Light) printf '%s' "$1" ;; + *) printf '' ;; + esac +} + +read_saved_mode() { + local mode="" + if [ -f "$theme_state_file" ]; then + mode="$(normalize_mode "$(tr -d '\r\n' < "$theme_state_file")")" + fi + if [ -z "$mode" ] && [ -f "$legacy_theme_state_file" ]; then + mode="$(normalize_mode "$(tr -d '\r\n' < "$legacy_theme_state_file")")" + fi + [ -n "$mode" ] && printf '%s' "$mode" || printf 'Dark' +} + +while [ $# -gt 0 ]; do + case "$1" in + --apply-current) + apply_saved_mode=1 + ;; + --mode) + shift + forced_mode="$(normalize_mode "${1:-}")" + ;; + --no-notify) + notify_enabled=0 + ;; + --preserve-wallpaper) + preserve_wallpaper=1 + ;; + --help) + cat <<'EOF' +Usage: DarkLight.sh [--apply-current] [--mode Dark|Light] [--no-notify] [--preserve-wallpaper] + (no args) Toggle between Dark and Light and persist selection + --apply-current Re-apply saved mode (defaults to Dark when unset) + --mode <mode> Force target mode to Dark or Light + --no-notify Suppress notifications + --preserve-wallpaper Keep current wallpaper instead of choosing random Dynamic-Wallpapers image +EOF + exit 0 + ;; + esac + shift +done # intial kill process for pid in waybar rofi swaync ags swaybg; do @@ -45,28 +100,33 @@ done swww="$WWW_CMD img" effect="--transition-bezier .43,1.19,1,.4 --transition-fps 60 --transition-type grow --transition-pos 0.925,0.977 --transition-duration 2" -# Determine current theme mode -if [ "$(cat $HOME/.cache/.theme_mode)" = "Light" ]; then +# Determine target theme mode +saved_mode="$(read_saved_mode)" +if [ -n "$forced_mode" ]; then + next_mode="$forced_mode" +elif [ "$apply_saved_mode" -eq 1 ]; then + next_mode="$saved_mode" +elif [ "$saved_mode" = "Light" ]; then next_mode="Dark" - # Logic for Dark mode - wallpaper_path="$dark_wallpapers" else next_mode="Light" - # Logic for Light mode - wallpaper_path="$light_wallpapers" fi # Select Qt color scheme templates for the upcoming mode if [ "$next_mode" = "Dark" ]; then + wallpaper_path="$dark_wallpapers" qt5ct_color_scheme="$qt5ct_dark" qt6ct_color_scheme="$qt6ct_dark" else + wallpaper_path="$light_wallpapers" qt5ct_color_scheme="$qt5ct_light" qt6ct_color_scheme="$qt6ct_light" fi # Function to update theme mode for the next cycle update_theme_mode() { - echo "$next_mode" > "$HOME/.cache/.theme_mode" + mkdir -p "$theme_state_dir" "$HOME/.cache" + echo "$next_mode" > "$theme_state_file" + echo "$next_mode" > "$legacy_theme_state_file" } # Function to notify user @@ -84,8 +144,8 @@ fi # Function to set Waybar style set_waybar_style() { theme="$1" - waybar_styles="$HOME/.config/waybar/style" - waybar_style_link="$HOME/.config/waybar/style.css" + waybar_styles="${XDG_CONFIG_HOME:-$HOME/.config}/waybar/style" + waybar_style_link="${XDG_CONFIG_HOME:-$HOME/.config}/waybar/style.css" style_prefix="\\[${theme}\\].*\\.css$" style_file=$(find -L "$waybar_styles" -maxdepth 1 -type f -regex ".*$style_prefix" | shuf -n 1) @@ -99,7 +159,7 @@ set_waybar_style() { # Call the function after determining the mode set_waybar_style "$next_mode" -notify_user "$next_mode" +[ "$notify_enabled" -eq 1 ] && notify_user "$next_mode" # swaync color change @@ -140,29 +200,31 @@ for pid_kitty in $(pidof kitty); do done # Set Dynamic Wallpaper for Dark or Light Mode -if [ "$next_mode" = "Dark" ]; then - next_wallpaper="$(find -L "${dark_wallpapers}" -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | shuf -n1 -z | xargs -0)" -else - next_wallpaper="$(find -L "${light_wallpapers}" -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | shuf -n1 -z | xargs -0)" -fi +if [ "$preserve_wallpaper" -eq 0 ]; then + if [ "$next_mode" = "Dark" ]; then + next_wallpaper="$(find -L "${dark_wallpapers}" -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | shuf -n1 -z | xargs -0)" + else + next_wallpaper="$(find -L "${light_wallpapers}" -type f \( -iname "*.jpg" -o -iname "*.png" \) -print0 | shuf -n1 -z | xargs -0)" + fi -# Update wallpaper using swww command -$swww "${next_wallpaper}" $effect + # Update wallpaper using swww command + $swww "${next_wallpaper}" $effect +fi # Set Kvantum Manager theme & QT5/QT6 settings if [ "$next_mode" = "Dark" ]; then kvantum_theme="catppuccin-mocha-blue" - #qt5ct_color_scheme="$HOME/.config/qt5ct/colors/Catppuccin-Mocha.conf" - #qt6ct_color_scheme="$HOME/.config/qt6ct/colors/Catppuccin-Mocha.conf" + #qt5ct_color_scheme="${XDG_CONFIG_HOME:-$HOME/.config}/qt5ct/colors/Catppuccin-Mocha.conf" + #qt6ct_color_scheme="${XDG_CONFIG_HOME:-$HOME/.config}/qt6ct/colors/Catppuccin-Mocha.conf" else kvantum_theme="catppuccin-latte-blue" - #qt5ct_color_scheme="$HOME/.config/qt5ct/colors/Catppuccin-Latte.conf" - #qt6ct_color_scheme="$HOME/.config/qt6ct/colors/Catppuccin-Latte.conf" + #qt5ct_color_scheme="${XDG_CONFIG_HOME:-$HOME/.config}/qt5ct/colors/Catppuccin-Latte.conf" + #qt6ct_color_scheme="${XDG_CONFIG_HOME:-$HOME/.config}/qt6ct/colors/Catppuccin-Latte.conf" fi -sed -i "s|^color_scheme_path=.*$|color_scheme_path=$qt5ct_color_scheme|" "$HOME/.config/qt5ct/qt5ct.conf" -sed -i "s|^color_scheme_path=.*$|color_scheme_path=$qt6ct_color_scheme|" "$HOME/.config/qt6ct/qt6ct.conf" +sed -i "s|^color_scheme_path=.*$|color_scheme_path=$qt5ct_color_scheme|" "${XDG_CONFIG_HOME:-$HOME/.config}/qt5ct/qt5ct.conf" +sed -i "s|^color_scheme_path=.*$|color_scheme_path=$qt6ct_color_scheme|" "${XDG_CONFIG_HOME:-$HOME/.config}/qt6ct/qt6ct.conf" kvantummanager --set "$kvantum_theme" @@ -234,8 +296,8 @@ set_custom_gtk_theme() { gsettings set $icon_setting "$selected_icon" ## QT5ct icon_theme - sed -i "s|^icon_theme=.*$|icon_theme=$selected_icon|" "$HOME/.config/qt5ct/qt5ct.conf" - sed -i "s|^icon_theme=.*$|icon_theme=$selected_icon|" "$HOME/.config/qt6ct/qt6ct.conf" + sed -i "s|^icon_theme=.*$|icon_theme=$selected_icon|" "${XDG_CONFIG_HOME:-$HOME/.config}/qt5ct/qt5ct.conf" + sed -i "s|^icon_theme=.*$|icon_theme=$selected_icon|" "${XDG_CONFIG_HOME:-$HOME/.config}/qt6ct/qt6ct.conf" # Flatpak GTK apps (icons) if command -v flatpak &> /dev/null; then @@ -268,7 +330,7 @@ ${SCRIPTSDIR}/Refresh.sh sleep 0.5 # Display notifications for theme and icon changes -notify-send -u low -i "$notif" " Themes switched to:" " $next_mode Mode" +[ "$notify_enabled" -eq 1 ] && notify-send -u low -i "$notif" " Themes switched to:" " $next_mode Mode" exit 0 |
