Estimate sunup/sundown times for earlier wallpaper changes in winter, update for Qtile 0.34.x

This commit is contained in:
Kevin Alberts 2026-01-06 09:41:51 +01:00
parent 27b41f975d
commit fa5bbee56e
3 changed files with 161 additions and 9 deletions

View file

@ -5,11 +5,11 @@ import time
import datetime
import socket
import subprocess
from dateutil import tz
from typing import Optional
from libqtile.backend.base import Window
from libqtile.backend.wayland.layer import LayerStatic
from libqtile.backend.wayland.xwindow import XWindow as WaylandXWindow, XStatic as WaylandXStatic
from libqtile.backend.wayland.window import Window as WaylandWindow, Static as WaylandStatic
from libqtile.backend.x11.window import XWindow as XorgXWindow
# Initialize logging
from libqtile.log_utils import logger
@ -30,6 +30,7 @@ logger.warning("Importing kuro utils...")
import kuro.utils.widgets
from kuro.utils import general as utils
from kuro.utils.suntime import Sun
logger.warning("Importing variables and other utils...")
@ -643,11 +644,9 @@ class Kuro(BaseTheme):
try:
w_pid = client.get_pid()
except AttributeError: # Some windows might not have this .get_pid method. Try other ways
if isinstance(client, WaylandXWindow) or isinstance(client, WaylandXStatic):
w_pid = client.surface.pid
elif isinstance(client, XorgXWindow):
if isinstance(client, XorgXWindow):
w_pid = client.get_net_wm_pid()
elif isinstance(client, LayerStatic):
elif isinstance(client, WaylandStatic) or isinstance(client, WaylandInternal):
pass # Wayland background layer 'window'
else:
logger.error(f"Unknown window type {client.__class__.__name__}")
@ -714,11 +713,18 @@ class Kuro(BaseTheme):
wallpapers = []
wallpaper_dir = Config.get("desktop_bg_folder", "")
# Use a wallpaper from the night folder after 9PM and before 6AM
# Get current and sunset/sunrise times using util
sun = Sun(Config.get("loc_latitude", 52.357603), Config.get("loc_longitude", 6.663761))
tzone = tz.gettz(Config.get("loc_timezone", "Europe/Amsterdam"))
cur_time = datetime.datetime.now(tz=tzone)
sunset = sun.get_sunset_time(time_zone=tzone)
sunrise = sun.get_sunrise_time(time_zone=tzone)
logger.warning("Using current time {}, sunset {}, sunrise {} to determine wallpaper.".format(cur_time, sunset, sunrise))
# Use a wallpaper from the night folder after sunset and before sunrise
wallpaper_night_dir = Config.get("desktop_bg_night_folder", "")
if wallpaper_night_dir and os.path.isdir(wallpaper_night_dir):
cur_time = datetime.datetime.now()
if cur_time.hour > 21 or cur_time.hour < 6:
if cur_time > sunset or cur_time < sunrise:
wallpaper_dir = wallpaper_night_dir
try: