From ad845936d08edda9b3eebad6e720dd291ba55ef4 Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Thu, 27 Mar 2025 01:02:04 -0400 Subject: [PATCH] Make Hyprsunset slowly change temperature throughout day --- README.md | 2 -- bombadil.toml | 4 ++- scripts/screenshot.sh | 3 -- scripts/sunset.sh | 64 ++++++++++++++++++++++++++++++++++++++++++ systemd/sunset.service | 6 ++++ systemd/sunset.timer | 11 ++++++++ 6 files changed, 84 insertions(+), 6 deletions(-) create mode 100755 scripts/sunset.sh create mode 100644 systemd/sunset.service create mode 100644 systemd/sunset.timer diff --git a/README.md b/README.md index d15dc3d..6b9c1ef 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ The dotfiles are managed with [TOML Bombadil](https://github.com/oknozor/toml-bo ## TODO -* hyprsunset - * Ramp throughout day * Wallpaper * Adjust to time of day * Make sure changed wallpaper is new diff --git a/bombadil.toml b/bombadil.toml index 823e3af..9810c71 100644 --- a/bombadil.toml +++ b/bombadil.toml @@ -21,10 +21,12 @@ megasync = { source = "autostart/megasync.desktop", target = ".config/autostart/ git = { source = "git/config", target = ".config/git/config" } -# Also needs a one-time `systemctl --user enable --now eww-daemon.service eww-bars.service ip-geolocation.service swww-daemon.service' +# Also needs a one-time `systemctl --user enable --now eww-daemon.service eww-bars.service ip-geolocation.service sunset.timer swww-daemon.service' eww-daemon = { source = "systemd/eww-daemon.service", target = ".config/systemd/user/eww-daemon.service" } eww-bars = { source = "systemd/eww-bars.service", target = ".config/systemd/user/eww-bars.service" } ip-geolocation = { source = "systemd/ip-geolocation.service", target = ".config/systemd/user/ip-geolocation.service" } +sunset-service = { source = "systemd/sunset.service", target = ".config/systemd/user/sunset.service" } +sunset-timer = { source = "systemd/sunset.timer", target = ".config/systemd/user/sunset.timer" } swww-daemon = { source = "systemd/swww-daemon.service", target = ".config/systemd/user/swww-daemon.service" } btop = { source = "btop", target = ".config/btop" } diff --git a/scripts/screenshot.sh b/scripts/screenshot.sh index 5cd8197..b210fd9 100755 --- a/scripts/screenshot.sh +++ b/scripts/screenshot.sh @@ -1,8 +1,5 @@ #!/bin/env sh if [ "$(pidof slurp)" = "" ]; then - hyprshade off grimblast copy area - hyprshade auto fi - diff --git a/scripts/sunset.sh b/scripts/sunset.sh new file mode 100755 index 0000000..873db0f --- /dev/null +++ b/scripts/sunset.sh @@ -0,0 +1,64 @@ +#!/bin/env sh + +SUNRISE_START="$((5 * 60 * 60))" # When to start turning up temperature +SUNRISE_END="$((7 * 60 * 60))" # When to reach max temperature + +SUNSET_START="$((21 * 60 * 60))" # When to start turning down temperature +SUNSET_END="$((23 * 60 * 60))" # When to reach min temperature + +DAY_TEMP="6000" # Display temperature (K) to use in full daylight +NIGHT_TEMP="2400" # Display temperature (K) to use at night + +CURRENT="$(((($(date '+%H') * 60) + $(date '+%M')) * 60 + $(date '+%S')))" # Time in seconds since start of day + +# Performs a calculation using an argument containing an input string +calc() { + echo "scale=4; $1" | bc +} + +# Evaluates a boolean expression on an argument containing an input string +bool() { + echo "scale=1; $1" | bc +} + +# GLSL Smoothstep, takes a single number as an argument +smoothstep() { + if [ "$(bool "$1 <= 0")" = "1" ]; then + echo 0 + elif [ "$(bool "$1 >= 1")" = "1" ]; then + echo 1 + else + calc "$1 * $1 * (3 - 2 * $1)" + fi +} + +# Interpolates between the 4th and 5th arguments based on the value of the 2nd in relation to the 1st and 3rd +interpolate() { + LOWER_IN="$1" + VALUE="$2" + UPPER_IN="$3" + LOWER_OUT="$4" + UPPER_OUT="$5" + + if [ "$((VALUE <= LOWER_IN))" = "1" ]; then + echo "$LOWER_OUT" + elif [ "$((VALUE < UPPER_IN))" = "1" ]; then + calc "$LOWER_OUT + (($UPPER_OUT - $LOWER_OUT) * $(smoothstep "$(calc "($VALUE - $LOWER_IN) / ($UPPER_IN - $LOWER_IN)")"))" + else + echo "$UPPER_OUT" + fi +} + +if [ "$((CURRENT <= SUNRISE_START))" = "1" ]; then + TEMP="$NIGHT_TEMP" +elif [ "$((CURRENT < SUNRISE_END))" = "1" ]; then + TEMP="$(interpolate "$SUNRISE_START" "$CURRENT" "$SUNRISE_END" "$NIGHT_TEMP" "$DAY_TEMP")" +elif [ "$((CURRENT <= SUNSET_START))" = "1" ]; then + TEMP="$DAY_TEMP" +elif [ "$((CURRENT < SUNSET_END))" = "1" ]; then + TEMP="$(interpolate "$SUNSET_START" "$CURRENT" "$SUNSET_END" "$DAY_TEMP" "$NIGHT_TEMP")" +else + TEMP="$NIGHT_TEMP" +fi + +hyprctl hyprsunset temperature "$TEMP" diff --git a/systemd/sunset.service b/systemd/sunset.service new file mode 100644 index 0000000..4fa5f55 --- /dev/null +++ b/systemd/sunset.service @@ -0,0 +1,6 @@ +[Unit] +Description=Sets the monitor temperature based on the time of day + +[Service] +Type=oneshot +ExecStart=/home/mbradley/scripts/sunset.sh diff --git a/systemd/sunset.timer b/systemd/sunset.timer new file mode 100644 index 0000000..2f2da6c --- /dev/null +++ b/systemd/sunset.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Changes the monitor temperature over the course of the day to ease eye strain +After=graphical-session.target +After=hyprsunset.service + +[Timer] +OnCalendar=*-*-* *:*:00 +Persistent=true + +[Install] +WantedBy=timers.target