Fix dynamic theming: enable filesystem writes and add theme switching

- Add LD_LIBRARY_PATH and ILLOGICAL_IMPULSE_VIRTUAL_ENV to quickshell service
- Set ProtectSystem=false to allow color generation scripts to write files
- Fix MaterialThemeLoader to properly detect file changes with onFileChanged
- Add switchwall-wrapper.sh to source environment variables dynamically
- Fix light/dark mode buttons to use Process with current wallpaper
- Add --choose flag to switchwall.sh for wallpaper selection dialog
- Add IPC commands 'dark' and 'light' for console theme switching
- Update keybinds: Ctrl+Super+T (choose), Ctrl+Super+Shift+T (random)
- Fix terminal color application in applycolor.sh
This commit is contained in:
Celes Renata
2025-11-29 18:57:23 -08:00
parent 3655e7aaee
commit d192bee3d9
9 changed files with 333 additions and 70 deletions
@@ -2,6 +2,7 @@
import argparse
import math
import json
import os
from PIL import Image
from materialyoucolor.quantize import QuantizeCelebi
from materialyoucolor.score.score import Score
@@ -86,6 +87,11 @@ if args.path is not None:
elif args.color is not None:
argb = hex_to_argb(args.color)
hct = Hct.from_int(argb)
elif args.cache is not None and os.path.exists(args.cache):
with open(args.cache, 'r') as file:
cached_color = file.read().strip()
argb = hex_to_argb(cached_color)
hct = Hct.from_int(argb)
if args.scheme == 'scheme-fruit-salad':
from materialyoucolor.scheme.scheme_fruit_salad import SchemeFruitSalad as Scheme
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Wrapper to set up environment for switchwall.sh
# Source environment config
[ -f "$HOME/.config/quickshell/env.sh" ] && source "$HOME/.config/quickshell/env.sh"
export ILLOGICAL_IMPULSE_VIRTUAL_ENV="${ILLOGICAL_IMPULSE_VIRTUAL_ENV:-$HOME/.local/state/quickshell/.venv}"
echo "[wrapper] Called with args: $@" >> /tmp/switchwall-wrapper.log
echo "[wrapper] LD_LIBRARY_PATH: $LD_LIBRARY_PATH" >> /tmp/switchwall-wrapper.log
# Run switchwall.sh with all arguments
exec "$(dirname "$0")/switchwall.sh" "$@"
@@ -1,5 +1,16 @@
#!/usr/bin/env bash
# Log execution
LOG="/tmp/switchwall.log"
echo "[$(date)] switchwall.sh started" >> "$LOG"
echo "ILLOGICAL_IMPULSE_VIRTUAL_ENV=$ILLOGICAL_IMPULSE_VIRTUAL_ENV" >> "$LOG"
# Ensure LD_LIBRARY_PATH is set for Python venv
if [ -z "$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH="/run/current-system/sw/lib"
echo "Set LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> "$LOG"
fi
QUICKSHELL_CONFIG_NAME="ii"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
@@ -84,9 +95,10 @@ check_and_prompt_upscale() {
img_height=$(identify -format "%h" "$img" 2>/dev/null)
fi
if [[ "$img_width" -lt "$min_width_desired" || "$img_height" -lt "$min_height_desired" ]]; then
action=$(notify-send "Upscale?" \
action=$(timeout 5 notify-send "Upscale?" \
"Image resolution (${img_width}x${img_height}) is lower than screen resolution (${min_width_desired}x${min_height_desired})" \
-A "open_upscayl=Open Upscayl"\
-t 5000 \
-a "Wallpaper switcher")
if [[ "$action" == "open_upscayl" ]]; then
if command -v upscayl &>/dev/null; then
@@ -187,7 +199,10 @@ switch() {
exit 0
fi
check_and_prompt_upscale "$imgpath" &
# Only check upscale if not using --noswitch
if [[ -z "$noswitch_flag" ]]; then
check_and_prompt_upscale "$imgpath" &
fi
kill_existing_mpvpaper
if is_video "$imgpath"; then
@@ -281,11 +296,34 @@ switch() {
fi
matugen "${matugen_args[@]}"
source "$(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate"
python3 "$SCRIPT_DIR/generate_colors_material.py" "${generate_colors_material_args[@]}" \
> "$STATE_DIR"/user/generated/material_colors.scss
"$SCRIPT_DIR"/applycolor.sh
deactivate
echo "[$(date)] Running python script" >> "$LOG"
"$(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/python3" "$SCRIPT_DIR/generate_colors_material.py" "${generate_colors_material_args[@]}" \
> "$STATE_DIR"/user/generated/material_colors.scss 2>> "$LOG"
echo "[$(date)] Python done, scss size: $(wc -l < "$STATE_DIR"/user/generated/material_colors.scss)" >> "$LOG"
# Only convert to JSON if SCSS was generated successfully
if [ -s "$STATE_DIR"/user/generated/material_colors.scss ]; then
# Convert SCSS to JSON for quickshell MaterialThemeLoader
echo "[$(date)] Converting SCSS to JSON" >> "$LOG"
awk -F': ' '/^\$/ {gsub(/\$|;/, "", $0); print "\"" $1 "\": \"" $2 "\","}' \
"$STATE_DIR"/user/generated/material_colors.scss | \
sed '$ s/,$//' | \
(echo "{"; cat; echo "}") > "$STATE_DIR"/user/generated/colors.json.tmp
mv "$STATE_DIR"/user/generated/colors.json.tmp "$STATE_DIR"/user/generated/colors.json
sync "$STATE_DIR"/user/generated/colors.json
echo "[$(date)] JSON created, size: $(wc -l < "$STATE_DIR"/user/generated/colors.json)" >> "$LOG"
else
echo "[$(date)] SCSS generation failed, skipping JSON creation" >> "$LOG"
fi
"$XDG_CONFIG_HOME/quickshell/scripts/colors/applycolor.sh"
# Wait for all file operations to complete
wait
sleep 1
# Trigger quickshell to reload theme via IPC (doesn't restart the process)
quickshell ipc -c ii call materialTheme reload 2>/dev/null || true
# Pass screen width, height, and wallpaper path to post_process
max_width_desired="$(hyprctl monitors -j | jq '([.[].width] | min)' | xargs)"
@@ -300,6 +338,7 @@ main() {
color_flag=""
color=""
noswitch_flag=""
choose_flag=""
get_type_from_config() {
jq -r '.appearance.palette.type' "$SHELL_CONFIG_FILE" 2>/dev/null || echo "auto"
@@ -339,6 +378,10 @@ main() {
imgpath=$(jq -r '.background.wallpaperPath' "$SHELL_CONFIG_FILE" 2>/dev/null || echo "")
shift
;;
--choose)
choose_flag="1"
shift
;;
*)
if [[ -z "$imgpath" ]]; then
imgpath="$1"
@@ -369,8 +412,17 @@ main() {
# Only prompt for wallpaper if not using --color and not using --noswitch and no imgpath set
if [[ -z "$imgpath" && -z "$color_flag" && -z "$noswitch_flag" ]]; then
cd "$(xdg-user-dir PICTURES)/Wallpapers/showcase" 2>/dev/null || cd "$(xdg-user-dir PICTURES)/Wallpapers" 2>/dev/null || cd "$(xdg-user-dir PICTURES)" || return 1
imgpath="$(kdialog --getopenfilename . --title 'Choose wallpaper')"
# Try to pick a random wallpaper from Wallpapers directory
WALLPAPER_DIR="$(xdg-user-dir PICTURES)/Wallpapers"
if [[ -d "$WALLPAPER_DIR" ]] && [[ -z "$choose_flag" ]]; then
imgpath=$(find "$WALLPAPER_DIR" -type f \( -name "*.jpg" -o -name "*.png" \) 2>/dev/null | shuf -n 1)
fi
# If --choose flag is set or still no wallpaper, prompt with kdialog
if [[ -n "$choose_flag" ]] || [[ -z "$imgpath" ]]; then
cd "$(xdg-user-dir PICTURES)/Wallpapers/showcase" 2>/dev/null || cd "$(xdg-user-dir PICTURES)/Wallpapers" 2>/dev/null || cd "$(xdg-user-dir PICTURES)" || return 1
imgpath="$(kdialog --getopenfilename . --title 'Choose wallpaper')"
fi
fi
# If type_flag is 'auto', detect scheme type from image (after imgpath is set)