diff options
Diffstat (limited to 'bin/udt-accent')
| -rwxr-xr-x | bin/udt-accent | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/bin/udt-accent b/bin/udt-accent index e88a512..703f483 100755 --- a/bin/udt-accent +++ b/bin/udt-accent @@ -12,6 +12,7 @@ running `wal -i`, because `wal -i` rewrites the whole ~/.cache/wal directory including the terminal's ANSI colors. See the design spec for why that matters. """ +import json import math import os import subprocess @@ -43,6 +44,19 @@ MIN_CHROMA = 10.0 OUTPUT = Path.home() / ".cache" / "wal" / "udt-accent.rasi" BORDER_OUTPUT = Path.home() / ".cache" / "wal" / "udt-border.lua" DUNSTRC = Path.home() / ".cache" / "wal" / "dunstrc" +COLORS_JSON = Path.home() / ".cache" / "wal" / "colors.json" + +# Catppuccin Macchiato, in pywal's slot order. Firefox is themed from this +# via pywalfox, which reads colors.json and nothing else. +MACCHIATO = { + "background": "#24273a", "foreground": "#cad3f5", "cursor": "#f4dbd6", + "colors": [ + "#494d64", "#ed8796", "#a6da95", "#eed49f", + "#8aadf4", "#f5bde6", "#8bd5ca", "#b8c0e0", + "#5b6078", "#ed8796", "#a6da95", "#eed49f", + "#8aadf4", "#f5bde6", "#8bd5ca", "#a5adcb", + ], +} def _to_lab(hexval): @@ -166,6 +180,46 @@ def write_border(name): raise +def write_colors_json(name, image): + """Rewrite colors.json as Macchiato with the accent in the highlight slots. + + pywalfox reads this file and nothing else, so this is how Firefox tracks the + wallpaper. pywal wrote the file moments earlier with wallpaper-derived ANSI + colours; this replaces them wholesale, which is the point: the terminal + palette stays fixed Macchiato while only the accent moves. + """ + hexval = ACCENTS[name] + colors = list(MACCHIATO["colors"]) + # Slots 4 and 12 are pywalfox's link/highlight colour. + colors[4] = colors[12] = hexval + + doc = { + "wallpaper": str(image), + "alpha": "100", + "special": { + "background": MACCHIATO["background"], + "foreground": MACCHIATO["foreground"], + "cursor": hexval, + }, + "colors": {f"color{i}": c for i, c in enumerate(colors)}, + } + + fd, tmp = tempfile.mkstemp(dir=str(COLORS_JSON.parent), suffix=".tmp") + try: + with os.fdopen(fd, "w") as handle: + json.dump(doc, handle, indent=4) + handle.write("\n") + os.replace(tmp, COLORS_JSON) + except BaseException: + if os.path.exists(tmp): + os.unlink(tmp) + raise + + # Firefox only picks the new colours up when pywalfox pushes them. Never + # fatal: pywalfox may not be installed, and the desktop theme is unaffected. + subprocess.run(["pywalfox", "update"], capture_output=True, check=False) + + def write_dunst(name): """Substitute the accent into the dunst config pywal just rendered. @@ -209,6 +263,7 @@ def main(image): write_accent(name) write_border(name) write_dunst(name) + write_colors_json(name, image) # Hyprland only rereads its config on request, and may not be running. subprocess.run(["hyprctl", "reload"], capture_output=True, check=False) |
