Compare commits

..

No commits in common. "9a03bb684b4ce51ef84b555b91c53024321efd1d" and "7767ef1b3c969c886e2b35a55ecf1f9f8fb21556" have entirely different histories.

6 changed files with 37 additions and 94 deletions

View file

@ -1,4 +1,4 @@
#? Config file for btop v. 1.4.3 #? Config file for btop v. 1.4.1
#* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. #* 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" #* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes"

View file

@ -63,11 +63,11 @@
(network_speed :label "󰈀" :interface "enp6s0")) (network_speed :label "󰈀" :interface "enp6s0"))
(defwidget wlan [] (defwidget wlan []
(network_speed :label "" (network_speed :label ""
{% if host.name == "chonk" %} {% if host.name == "chonk" %}
:interface "wlo1" :interface "wlo1"
{% else %} {% else %}
:interface "wlp1s0" :interface "wlp1s0"
{% endif %} {% endif %}
)) ))
(defwidget date [] (defwidget date []
@ -94,8 +94,8 @@
(label :text "" :class "lock")) (label :text "" :class "lock"))
(eventbox :onclick "systemctl suspend" :cursor "pointer" (eventbox :onclick "systemctl suspend" :cursor "pointer"
(label :text "鈴" :class "sleep")) (label :text "鈴" :class "sleep"))
;(eventbox :onclick "systemctl hibernate" :cursor "pointer" ; (eventbox :onclick "systemctl hibernate" :cursor "pointer"
;(label :text "" :class "hibernate")) ; (label :text "" :class "hibernate"))
(eventbox :onclick "reboot" :cursor "pointer" (eventbox :onclick "reboot" :cursor "pointer"
(label :text "ﰇ" :class "reboot")) (label :text "ﰇ" :class "reboot"))
(eventbox :onclick "shutdown now" :cursor "pointer" (eventbox :onclick "shutdown now" :cursor "pointer"
@ -118,11 +118,11 @@
(eventbox :onclick command :cursor "pointer" :timeout "3600s" (eventbox :onclick command :cursor "pointer" :timeout "3600s"
(label :text text :class "primary"))) (label :text text :class "primary")))
;(defwidget colour_selector [] ;(defwidget colour_selector []
;(clicker :text "" :command "uwsm-app -- hyprpicker -a")) ; (clicker :text "" :command "uwsm-app -- hyprpicker -a"))
(defwidget wallpaper [] (defwidget wallpaper []
(clicker :text "󰸉" :command "~/scripts/swww_change.py")) (clicker :text "󰸉" :command "~/scripts/swww_change.py"))
(defwidget sunset [] (defwidget sunset []
(clicker :text "" :command "~/scripts/sunset.py")) (clicker :text "" :command "systemctl --user start sunset.service"))
(defpoll brightness :interval 60 "~/.config/eww/scripts/backlight get") (defpoll brightness :interval 60 "~/.config/eww/scripts/backlight get")
@ -167,9 +167,9 @@
(systray :pack_direction "ltr" :icon-size 20) (systray :pack_direction "ltr" :icon-size 20)
(box :class "right" :orientation "h" :space-evenly false :halign "end" (box :class "right" :orientation "h" :space-evenly false :halign "end"
(gametime)(space) (gametime)(space)
;(colour_selector)(space) ; (colour_selector)(space)
(sunset)(space) (sunset)(space)
(wallpaper)(sep) (wallpaper)(space)
(mountpoint :label "/" :mount "/")(space) (mountpoint :label "/" :mount "/")(space)
(mountpoint :label "󰋊" :mount "/home/mbradley/hdd")(sep) (mountpoint :label "󰋊" :mount "/home/mbradley/hdd")(sep)
(ram)(space) (ram)(space)
@ -186,7 +186,7 @@
(systray :pack_direction "ltr" :icon-size 20) (systray :pack_direction "ltr" :icon-size 20)
(box :class "right" :orientation "h" :space-evenly false :halign "end" (box :class "right" :orientation "h" :space-evenly false :halign "end"
(weather)(sep) (weather)(sep)
;(colour_selector)(space) ; (colour_selector)(space)
(sunset)(space) (sunset)(space)
(wallpaper)(sep) (wallpaper)(sep)
(ram)(space) (ram)(space)
@ -201,12 +201,11 @@
(defwindow left (defwindow left
:monitor 1 :monitor 1
:geometry (geometry :geometry (geometry :x "0px"
:x "0px" :y "4px"
:y "4px" :width "1912px"
:width "1912px" :height "24px"
:height "24px" :anchor "top center")
:anchor "top center")
:stacking "bg" :stacking "bg"
:exclusive true :exclusive true
:focusable false :focusable false
@ -214,10 +213,10 @@
(defwindow right (defwindow right
:monitor 0 :monitor 0
:geometry (geometry :x "0px" :geometry (geometry :x "0px"
:y "4px" :y "4px"
:width "1912px" :width "1912px"
:height "24px" :height "24px"
:anchor "top center") :anchor "top center")
:stacking "fg" :stacking "fg"
:exclusive true :exclusive true
:focusable false :focusable false
@ -226,10 +225,10 @@
(defwindow laptop (defwindow laptop
:monitor 0 :monitor 0
:geometry (geometry :x "0px" :geometry (geometry :x "0px"
:y "4px" :y "4px"
:width "1912px" :width "1912px"
:height "24px" :height "24px"
:anchor "top center") :anchor "top center")
:stacking "fg" :stacking "fg"
:exclusive true :exclusive true
:focusable false :focusable false

View file

@ -5,7 +5,6 @@ general {
inhibit_sleep = 0 inhibit_sleep = 0
} }
{% if host.name != "chonk" %}
listener { listener {
timeout = 120 timeout = 120
on-timeout = brightnessctl -sd amdgpu_bl1 set 66- on-timeout = brightnessctl -sd amdgpu_bl1 set 66-
@ -33,4 +32,3 @@ listener {
timeout = 330 timeout = 330
on-timeout = systemctl suspend on-timeout = systemctl suspend
} }
{% endif %}

View file

@ -1,11 +1,8 @@
#!/bin/env python #!/bin/env python
"""Sets the monitor temperature based on the current time using Hyprsunset""" """Sets the monitor temperature based on the current time using Hyprsunset"""
from argparse import ArgumentParser, Namespace
from datetime import datetime from datetime import datetime
from os import environ from os import environ
from pathlib import Path
from socket import AF_UNIX, SOCK_STREAM, socket from socket import AF_UNIX, SOCK_STREAM, socket
from typing import cast
type Range = tuple[float, float] type Range = tuple[float, float]
@ -27,83 +24,32 @@ def day_elapsed(hours: int = 0, minutes: int = 0, seconds: int = 0) -> float:
return ((((hours * 60) + minutes) * 60) + seconds) / 86400 return ((((hours * 60) + minutes) * 60) + seconds) / 86400
def now_elapsed() -> float: def main(sunrise: Range, sunset: Range, temp_range: Range) -> None:
"""How far through the day it is""" """Adjusts the monitor temperature based on the current time"""
now = datetime.now() now = datetime.now()
return day_elapsed(now.hour, now.minute, now.second) elapsed = 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]: if elapsed <= sunrise[0]:
return temperature_range[0] temperature = temp_range[0]
elif elapsed < sunrise[1]: elif elapsed < sunrise[1]:
return smoothstep(lerped_amount(elapsed, sunrise), temperature_range) temperature = smoothstep(lerped_amount(elapsed, sunrise), temp_range)
elif elapsed <= sunset[0]: elif elapsed <= sunset[0]:
return temperature_range[1] temperature = temp_range[1]
elif elapsed < sunset[1]: elif elapsed < sunset[1]:
return smoothstep(lerped_amount(elapsed, sunset), (temperature_range[1], temperature_range[0])) temperature = smoothstep(lerped_amount(elapsed, sunset), (temp_range[1], temp_range[0]))
else: else:
return temperature_range[0] temperature = temp_range[0]
def setup_socket() -> socket:
"""Connects to the Hyprsunset socket"""
hyprsunset = socket(AF_UNIX, SOCK_STREAM) hyprsunset = socket(AF_UNIX, SOCK_STREAM)
# In theory I should use $XDG_RUNTIME_DIR, but for me it's always `/run/user/1000/` # In theory I should use $XDG_RUNTIME_DIR, but for me it's always `/run/user/1000/`
hyprsunset.connect(f"{environ["XDG_RUNTIME_DIR"]}/hypr/{environ["HYPRLAND_INSTANCE_SIGNATURE"]}/.hyprsunset.sock") hyprsunset.connect(f"/run/user/1000/hypr/{environ["HYPRLAND_INSTANCE_SIGNATURE"]}/.hyprsunset.sock")
return hyprsunset # In theory the message might not send in one go, but in practice it does do I won't bother handling it
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, /, 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()) _ = 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:
"""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, /, 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):
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__": 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( main(
(day_elapsed(5), day_elapsed(7)), (day_elapsed(5), day_elapsed(7)),
(day_elapsed(21), day_elapsed(23)), (day_elapsed(21), day_elapsed(23)),
(2500.0, 6000.0), (2500.0, 6000.0)
check_steam=args.check_steam,
instant=args.instant
) )

View file

@ -3,4 +3,4 @@ Description=Sets the monitor temperature based on the time of day
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/bin/env python -O /home/mbradley/scripts/sunset.py --check-steam ExecStart=/bin/env python -O /home/mbradley/scripts/sunset.py

View file

@ -2,7 +2,7 @@
# If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas. # 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" "$schema" = "https://yazi-rs.github.io/schemas/yazi.json"
[mgr] [manager]
ratio = [ 1, 3, 4 ] ratio = [ 1, 3, 4 ]
show_hidden = true show_hidden = true