From bfedfb88c412739df35d36e9270d0f24d51859de Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Wed, 4 Jun 2025 23:29:17 -0400 Subject: [PATCH 1/6] Tool config auto-updates --- btop/btop.conf | 2 +- yazi/yazi.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/btop/btop.conf b/btop/btop.conf index 084b5fd..21233d7 100755 --- a/btop/btop.conf +++ b/btop/btop.conf @@ -1,4 +1,4 @@ -#? Config file for btop v. 1.4.1 +#? Config file for btop v. 1.4.3 #* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. #* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes" diff --git a/yazi/yazi.toml b/yazi/yazi.toml index 6296073..fa336ae 100644 --- a/yazi/yazi.toml +++ b/yazi/yazi.toml @@ -2,7 +2,7 @@ # If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas. "$schema" = "https://yazi-rs.github.io/schemas/yazi.json" -[manager] +[mgr] ratio = [ 1, 3, 4 ] show_hidden = true From 26219faf6e7c7133eba70b8c40540a1f1fd8c3fc Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Wed, 4 Jun 2025 23:30:04 -0400 Subject: [PATCH 2/6] Only idle on laptop --- hypr/hypridle.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hypr/hypridle.conf b/hypr/hypridle.conf index 6aac63c..6dc13d5 100644 --- a/hypr/hypridle.conf +++ b/hypr/hypridle.conf @@ -5,6 +5,7 @@ general { inhibit_sleep = 0 } +{% if host.name != "chonk" %} listener { timeout = 120 on-timeout = brightnessctl -sd amdgpu_bl1 set 66- @@ -32,3 +33,4 @@ listener { timeout = 330 on-timeout = systemctl suspend } +{% endif %} From 52b7668c72b14ee42f1d8d720b1c88da5b05a0c8 Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Thu, 5 Jun 2025 00:12:28 -0400 Subject: [PATCH 3/6] Reduce hyprsunset impact Don't change temperature while on Steam and don't send updates unnecessarily --- scripts/sunset.py | 57 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/scripts/sunset.py b/scripts/sunset.py index ce0426d..577c939 100755 --- a/scripts/sunset.py +++ b/scripts/sunset.py @@ -2,6 +2,7 @@ """Sets the monitor temperature based on the current time using Hyprsunset""" from datetime import datetime from os import environ +from pathlib import Path from socket import AF_UNIX, SOCK_STREAM, socket @@ -24,29 +25,65 @@ def day_elapsed(hours: int = 0, minutes: int = 0, seconds: int = 0) -> float: return ((((hours * 60) + minutes) * 60) + seconds) / 86400 -def main(sunrise: Range, sunset: Range, temp_range: Range) -> None: - """Adjusts the monitor temperature based on the current time""" +def now_elapsed() -> float: + """How far through the day it is""" now = datetime.now() - elapsed = day_elapsed(now.hour, now.minute, now.second) + return day_elapsed(now.hour, now.minute, now.second) + +def calculate_temperature(sunrise: Range, sunset: Range, temperature_range: Range) -> float: + """What temperature the monitor should be""" + elapsed = now_elapsed() if elapsed <= sunrise[0]: - temperature = temp_range[0] + return temperature_range[0] elif elapsed < sunrise[1]: - temperature = smoothstep(lerped_amount(elapsed, sunrise), temp_range) + return smoothstep(lerped_amount(elapsed, sunrise), temperature_range) elif elapsed <= sunset[0]: - temperature = temp_range[1] + return temperature_range[1] elif elapsed < sunset[1]: - temperature = smoothstep(lerped_amount(elapsed, sunset), (temp_range[1], temp_range[0])) + return smoothstep(lerped_amount(elapsed, sunset), (temperature_range[1], temperature_range[0])) else: - temperature = temp_range[0] + return temperature_range[0] + +def setup_socket() -> socket: + """Connects to the Hyprsunset socket""" hyprsunset = socket(AF_UNIX, SOCK_STREAM) # In theory I should use $XDG_RUNTIME_DIR, but for me it's always `/run/user/1000/` - hyprsunset.connect(f"/run/user/1000/hypr/{environ["HYPRLAND_INSTANCE_SIGNATURE"]}/.hyprsunset.sock") - # In theory the message might not send in one go, but in practice it does do I won't bother handling it + hyprsunset.connect(f"{environ["XDG_RUNTIME_DIR"]}/hypr/{environ["HYPRLAND_INSTANCE_SIGNATURE"]}/.hyprsunset.sock") + return hyprsunset + + +def get_temperature(hyprsunset: socket) -> int: + """Retrieves the current screen temperature""" + # In theory the message might not send in one go, but in practice it does so I won't bother handling the error + _ = hyprsunset.send(b"temperature") + # 4 bytes should be enough but why not 8 for comfort + # Just raise an error if it's not a number, nothing special to do here + return int(hyprsunset.recv(8)) + + +def set_temperature(hyprsunset: socket, temperature: float) -> None: + # In theory the message might not send in one go, but in practice it does so I won't bother handling the error _ = hyprsunset.send(f"temperature {temperature:.1f}".encode()) +def on_steam() -> bool: + """Whether the Steam PID is in use""" + pid_file = Path("~/.steampid").expanduser().resolve(strict=True) + pid = pid_file.read_text().strip() + pid_dir = Path("/proc") / pid + return pid_dir.is_dir() + + +def main(sunrise: Range, sunset: Range, temperature_range: Range) -> None: + """Adjusts the monitor temperature based on the current time""" + hyprsunset = setup_socket() + temperature = int(calculate_temperature(sunrise, sunset, temperature_range)) + if temperature != get_temperature(hyprsunset) and not on_steam(): + set_temperature(hyprsunset, temperature) + + if __name__ == "__main__": main( (day_elapsed(5), day_elapsed(7)), From d9fc0327493632655bea7b75c33619e40949283a Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Thu, 5 Jun 2025 00:17:16 -0400 Subject: [PATCH 4/6] Call sunset script directly from EWW --- eww/eww.yuck | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eww/eww.yuck b/eww/eww.yuck index 65a8bd7..eeab559 100644 --- a/eww/eww.yuck +++ b/eww/eww.yuck @@ -122,7 +122,7 @@ (defwidget wallpaper [] (clicker :text "󰸉" :command "~/scripts/swww_change.py")) (defwidget sunset [] - (clicker :text "" :command "systemctl --user start sunset.service")) + (clicker :text "" :command "~/scripts/sunset.py")) (defpoll brightness :interval 60 "~/.config/eww/scripts/backlight get") @@ -169,7 +169,7 @@ (gametime)(space) ; (colour_selector)(space) (sunset)(space) - (wallpaper)(space) + (wallpaper)(sep) (mountpoint :label "/" :mount "/")(space) (mountpoint :label "󰋊" :mount "/home/mbradley/hdd")(sep) (ram)(space) From 1db9f8817961ec15ce039cf80cf5cb362a64efbe Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Thu, 5 Jun 2025 00:17:34 -0400 Subject: [PATCH 5/6] Format EWW config --- eww/eww.yuck | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/eww/eww.yuck b/eww/eww.yuck index eeab559..a9f75d3 100644 --- a/eww/eww.yuck +++ b/eww/eww.yuck @@ -63,11 +63,11 @@ (network_speed :label "󰈀" :interface "enp6s0")) (defwidget wlan [] (network_speed :label "" -{% if host.name == "chonk" %} + {% if host.name == "chonk" %} :interface "wlo1" -{% else %} + {% else %} :interface "wlp1s0" -{% endif %} + {% endif %} )) (defwidget date [] @@ -94,8 +94,8 @@ (label :text "" :class "lock")) (eventbox :onclick "systemctl suspend" :cursor "pointer" (label :text "鈴" :class "sleep")) -; (eventbox :onclick "systemctl hibernate" :cursor "pointer" -; (label :text "" :class "hibernate")) + ;(eventbox :onclick "systemctl hibernate" :cursor "pointer" + ;(label :text "" :class "hibernate")) (eventbox :onclick "reboot" :cursor "pointer" (label :text "ﰇ" :class "reboot")) (eventbox :onclick "shutdown now" :cursor "pointer" @@ -118,7 +118,7 @@ (eventbox :onclick command :cursor "pointer" :timeout "3600s" (label :text text :class "primary"))) ;(defwidget colour_selector [] -; (clicker :text "" :command "uwsm-app -- hyprpicker -a")) + ;(clicker :text "" :command "uwsm-app -- hyprpicker -a")) (defwidget wallpaper [] (clicker :text "󰸉" :command "~/scripts/swww_change.py")) (defwidget sunset [] @@ -167,7 +167,7 @@ (systray :pack_direction "ltr" :icon-size 20) (box :class "right" :orientation "h" :space-evenly false :halign "end" (gametime)(space) -; (colour_selector)(space) + ;(colour_selector)(space) (sunset)(space) (wallpaper)(sep) (mountpoint :label "/" :mount "/")(space) @@ -186,7 +186,7 @@ (systray :pack_direction "ltr" :icon-size 20) (box :class "right" :orientation "h" :space-evenly false :halign "end" (weather)(sep) -; (colour_selector)(space) + ;(colour_selector)(space) (sunset)(space) (wallpaper)(sep) (ram)(space) @@ -201,11 +201,12 @@ (defwindow left :monitor 1 - :geometry (geometry :x "0px" - :y "4px" - :width "1912px" - :height "24px" - :anchor "top center") + :geometry (geometry + :x "0px" + :y "4px" + :width "1912px" + :height "24px" + :anchor "top center") :stacking "bg" :exclusive true :focusable false @@ -213,10 +214,10 @@ (defwindow right :monitor 0 :geometry (geometry :x "0px" - :y "4px" - :width "1912px" - :height "24px" - :anchor "top center") + :y "4px" + :width "1912px" + :height "24px" + :anchor "top center") :stacking "fg" :exclusive true :focusable false @@ -225,10 +226,10 @@ (defwindow laptop :monitor 0 :geometry (geometry :x "0px" - :y "4px" - :width "1912px" - :height "24px" - :anchor "top center") + :y "4px" + :width "1912px" + :height "24px" + :anchor "top center") :stacking "fg" :exclusive true :focusable false From 9a03bb684b4ce51ef84b555b91c53024321efd1d Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Thu, 5 Jun 2025 00:34:34 -0400 Subject: [PATCH 6/6] Add CLI flags for Steam avoidance and instant transitions If called manually, ignore Steam by default. The systemd service checks for Steam as that is more likely to run at an annoying time. --- scripts/sunset.py | 27 ++++++++++++++++++++++----- systemd/sunset.service | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/scripts/sunset.py b/scripts/sunset.py index 577c939..c81152e 100755 --- a/scripts/sunset.py +++ b/scripts/sunset.py @@ -1,9 +1,11 @@ #!/bin/env python """Sets the monitor temperature based on the current time using Hyprsunset""" +from argparse import ArgumentParser, Namespace from datetime import datetime from os import environ from pathlib import Path from socket import AF_UNIX, SOCK_STREAM, socket +from typing import cast type Range = tuple[float, float] @@ -63,9 +65,12 @@ def get_temperature(hyprsunset: socket) -> int: return int(hyprsunset.recv(8)) -def set_temperature(hyprsunset: socket, temperature: float) -> None: +def set_temperature(hyprsunset: socket, temperature: float, /, instant: bool = False) -> None: # In theory the message might not send in one go, but in practice it does so I won't bother handling the error _ = hyprsunset.send(f"temperature {temperature:.1f}".encode()) + if instant: + # Setting the temperature twice in quick succession sometimes skips the transition period + set_temperature(hyprsunset, temperature, instant=False) def on_steam() -> bool: @@ -76,17 +81,29 @@ def on_steam() -> bool: return pid_dir.is_dir() -def main(sunrise: Range, sunset: Range, temperature_range: Range) -> None: +def main(sunrise: Range, sunset: Range, temperature_range: Range, /, check_steam: bool = False, instant: bool = False) -> None: """Adjusts the monitor temperature based on the current time""" hyprsunset = setup_socket() temperature = int(calculate_temperature(sunrise, sunset, temperature_range)) - if temperature != get_temperature(hyprsunset) and not on_steam(): - set_temperature(hyprsunset, temperature) + if temperature != get_temperature(hyprsunset): + if check_steam and on_steam(): + return + set_temperature(hyprsunset, temperature, instant=instant) +class Arguments(Namespace): + check_steam: bool = False + instant: bool = False + if __name__ == "__main__": + parser = ArgumentParser(description="Adjusts the temperature of your screen based on the time of day") + _ = parser.add_argument("-s", "--check-steam", action="store_true", help="Don't adjust temperature if Steam is active") + _ = parser.add_argument("-i", "--instant", action="store_true", help="Try to instantly change temperature") + args = cast(Arguments, parser.parse_args()) main( (day_elapsed(5), day_elapsed(7)), (day_elapsed(21), day_elapsed(23)), - (2500.0, 6000.0) + (2500.0, 6000.0), + check_steam=args.check_steam, + instant=args.instant ) diff --git a/systemd/sunset.service b/systemd/sunset.service index 30686f3..1dce2d9 100644 --- a/systemd/sunset.service +++ b/systemd/sunset.service @@ -3,4 +3,4 @@ Description=Sets the monitor temperature based on the time of day [Service] Type=oneshot -ExecStart=/bin/env python -O /home/mbradley/scripts/sunset.py +ExecStart=/bin/env python -O /home/mbradley/scripts/sunset.py --check-steam