diff options
Diffstat (limited to 'common/modules/window_managers/dwm/scripts.nix')
| -rw-r--r-- | common/modules/window_managers/dwm/scripts.nix | 79 |
1 files changed, 57 insertions, 22 deletions
diff --git a/common/modules/window_managers/dwm/scripts.nix b/common/modules/window_managers/dwm/scripts.nix index 5b52686..25ecc19 100644 --- a/common/modules/window_managers/dwm/scripts.nix +++ b/common/modules/window_managers/dwm/scripts.nix @@ -3,43 +3,76 @@ homeManager: let sync_dms = pkgs.writeShellScriptBin "sync_dms" '' jq=${pkgs.jq}/bin/jq - CONFIG_FILE=$HOME/.local/state/DankMaterialShell/session.json + SETTINGS_FILE="$HOME/.config/noctalia/settings.json" + WALLPAPER_FILE="$HOME/.cache/noctalia/wallpapers.json" - get_val() { $jq -r ".$1" "$CONFIG_FILE"; } - set_val() { + # --- Helpers --- + + get_setting() { + $jq -r "$1" "$SETTINGS_FILE" + } + + toggle_nightlight_state() { local tmp=$(mktemp) - $jq --arg val "$2" ".$1 = \$val" "$CONFIG_FILE" > "$tmp" && mv "$tmp" "$CONFIG_FILE" + # Flips the boolean cleanly without changing it to a string + $jq '.nightLight.enabled = (.nightLight.enabled | not)' "$SETTINGS_FILE" > "$tmp" && mv "$tmp" "$SETTINGS_FILE" } + # --- Modules --- + + apply_wallpaper() { + # Read dark mode and monitor preferences from settings.json + local is_dark=$(get_setting '.colorSchemes.darkMode') + local monitor=$(get_setting '.colorSchemes.monitorForColors') + + # Default to eDP-1 if monitor setting is missing + if [[ "$monitor" == "null" || -z "$monitor" ]]; then + monitor="eDP-1" + fi + + local mode="light" + if [[ "$is_dark" == "true" ]]; then + mode="dark" + fi - function sync_all { - ISNIGHTMODE=$(get_val "nightModeEnabled") - NIGHTMODETEMP=$(get_val "nightModeTemperature") - WALL=$(get_val "wallpaperPath") - ${pkgs.xwallpaper}/bin/xwallpaper --zoom "$WALL" + # Use jq variables to safely parse the nested monitor and mode keys + local wall=$($jq -r --arg mon "$monitor" --arg mode "$mode" '.wallpapers[$mon][$mode]' "$WALLPAPER_FILE") - if [[ "$ISNIGHTMODE" == "true" ]]; then - echo "bitch $ISNIGHTMODE" - ${pkgs.redshift}/bin/redshift -o "$NIGHTMODETEMP" + if [[ "$wall" != "null" && -n "$wall" ]]; then + ${pkgs.xwallpaper}/bin/xwallpaper --zoom "$wall" + fi + } + + apply_nightlight() { + local is_night_mode=$(get_setting '.nightLight.enabled') + local night_temp=$(get_setting '.nightLight.nightTemp') + + if [[ "$is_night_mode" == "true" ]]; then + echo "bitch $is_night_mode" + # -P resets prior adjustments, -O applies one-shot manual temperature + ${pkgs.redshift}/bin/redshift -P -O "$night_temp" else + # -x clears all redshift adjustments ${pkgs.redshift}/bin/redshift -x fi } - function dmenu_settings { - ISNIGHTMODE=$(get_val "nightModeEnabled") - options="NightMode (Currently $ISNIGHTMODE)\nSync Now" + sync_all() { + apply_wallpaper + apply_nightlight + } - choice=$(echo -e "$options" | dmenu -p "Settings:") + dmenu_settings() { + local is_night_mode=$(get_setting '.nightLight.enabled') + local options="Toggle NightMode (Currently $is_night_mode)\nSync Now" + + local choice=$(echo -e "$options" | dmenu -p "Settings:") case "$choice" in *"NightMode"*) - if [[ "$ISNIGHTMODE" == "true" ]]; then - set_val "nightModeEnabled" "false" - else - set_val "nightModeEnabled" "true" - fi - sync_all + toggle_nightlight_state + # Immediately apply the new state after toggling + apply_nightlight ;; "Sync Now") sync_all @@ -47,6 +80,8 @@ let esac } + # --- Main --- + case "$1" in settings) dmenu_settings ;; *) sync_all ;; |
