aboutsummaryrefslogtreecommitdiffstats
path: root/deckit
diff options
context:
space:
mode:
Diffstat (limited to 'deckit')
-rw-r--r--deckit/theme.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/deckit/theme.py b/deckit/theme.py
index 2ed3d51..142a79f 100644
--- a/deckit/theme.py
+++ b/deckit/theme.py
@@ -21,6 +21,7 @@ wallpaper accent to ~/.cache/udt/udt-accent.rasi. deck-it reads both rather
than restating the colours, so a scheme or wallpaper change reaches the tablet.
"""
+import json
import re
from pathlib import Path
@@ -31,6 +32,9 @@ BORDER = re.compile(r"rgb\(\s*([0-9a-fA-F]{6})\s*\)")
PALETTE_PATH = Path.home() / ".config" / "rofi" / "udt" / "palette.rasi"
ACCENT_PATH = Path.home() / ".cache" / "udt" / "udt-accent.rasi"
BORDER_PATH = Path.home() / ".cache" / "udt" / "udt-border.lua"
+# Keystone's fonts page owns text sizes: deck-it's own override, else the base.
+FONTS_PATH = Path.home() / ".config" / "keystone" / "fonts.json"
+FONT_SIZE = 14 # px, the size deck.css was designed at
# Catppuccin Macchiato, used before UDT has ever generated its files.
FALLBACK = {
@@ -58,8 +62,22 @@ def parse_border(text: str) -> list[str]:
return ["#" + value.lower() for value in BORDER.findall(text)]
-def css(colors: dict, accent: str | None, border: list[str] | None = None) -> str:
+def parse_font_size(text: str) -> int | None:
+ """deck-it's px size from keystone's fonts.json, range-checked as quickshell does."""
+ try:
+ data = json.loads(text)
+ px = (data.get("override") or {}).get("deckit", data.get("base"))
+ except (ValueError, AttributeError):
+ return None
+ if isinstance(px, (int, float)) and not isinstance(px, bool) and 8 <= px <= 40:
+ return round(px)
+ return None
+
+
+def css(colors: dict, accent: str | None, border: list[str] | None = None,
+ font_size: int | None = None) -> str:
lines = [":root {"]
+ lines.append(f" --udt-font-size: {font_size or FONT_SIZE}px;")
lines += [f" --udt-{name}: {value};" for name, value in colors.items()]
lines.append(f" --udt-accent: {accent or FALLBACK['accent']};")
stops = border if border and len(border) >= 3 else [
@@ -86,4 +104,8 @@ def load() -> str:
border = parse_border(BORDER_PATH.read_text())
except OSError:
border = None
- return css(colors, accent, border)
+ try:
+ font_size = parse_font_size(FONTS_PATH.read_text())
+ except OSError:
+ font_size = None
+ return css(colors, accent, border, font_size)