Theme presets, and make the bar itself actually re-theme (colors + opacity)

Presets (theme/presets.py): named snapshots of the whole palette, saved/loaded/
deleted from a new bookmark button on the theme widget. Stored outside the
repo in ~/.local/share/quickshell/theme-presets/ (JSON, per-machine data, same
precedent as the wallpaper history). A built-in Default entry can't be
overwritten or deleted.

Wiring that up exposed a real gap: the bar's own colors were hand-matched
hardcoded QML literals, not actually driven by theme/colors.toml, and opacity
wasn't themeable anywhere yet. Fixed both:
- colors.toml gains bar_color/pill_color/popup_color (paired with the existing
  *_opacity floats) plus generic opacity support in render.py (--set now
  accepts a 0-1 float, not just #rrggbb)
- Bar.qml now fetches the palette via render.py --dump and rebinds every
  matching hardcoded hex literal (accent, foreground, color1/2/3/5/6/8/12,
  the bar/pill/popup backgrounds, the logo tint and the bar's bottom border)
  to it; kitty's background_opacity is template-driven instead of a second
  hardcoded line fighting the themed one
- both the bar and the widget listen on their own Quickshell IPC target
  (render.py/presets.py ping both after every change) so edits reload with no
  restart, matching the "instant" promise the color editor already had
- the theme widget's color popup gained a slider + matching color swatch per
  surface (Bar/Pills/Popups/Terminal) below the existing role list, and its
  role labels now say what each color actually paints instead of "Color N"
  (verified against the templates and Bar.qml's literals, not guessed) with
  unused roles honestly marked as such
- the CPU pill's icon color is deliberately hardcoded again after this -
  it coincidentally shared color12's hex value with the help icon/detail
  text, so theming color12 was recoloring it too

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dujsk9jYfxUVLtb5B8eC94
This commit is contained in:
nico
2026-09-28 22:45:09 +02:00
parent e66691b469
commit 63a56f4a01
10 changed files with 813 additions and 124 deletions

View File

@@ -68,14 +68,17 @@ The artwork is drawn procedurally in [`hypr/cursor/shapes.py`](hypr/cursor/shape
Theming used to go through a third-party app called aether; it's gone now (it didn't work reliably), replaced with a small homegrown system in [`theme/`](theme/):
- [`theme/colors.toml`](theme/colors.toml) is the single source of truth for the palette (accent, cursor, foreground/background, 16 ANSI colors)
- [`theme/colors.toml`](theme/colors.toml) is the single source of truth for the palette: accent, cursor, foreground/background, 16 ANSI colors, three extra `*_color` fields (`bar_color`, `pill_color`, `popup_color` — the terminal reuses `background`, already shared with mako), and four matching `*_opacity` floats (`bar_opacity`, `pill_opacity`, `popup_opacity`, `terminal_opacity`, each 0-1)
- [`theme/templates/<app>/`](theme/templates/) holds one `{config.json, template}` pair per themed app (Hyprland, Kitty, Rofi, mako). `config.json` names the destination file; the template uses `{key}` placeholders (`{color4}`, `{background}`, `{accent}`, …), `{key.strip}` for the hex without `#`, or `{key.rgba:ALPHA}` for a `rgba(r, g, b, ALPHA)` string
- [`theme/render.py`](theme/render.py) renders every template to its destination and reloads the affected apps (`hyprctl reload`, `makoctl reload`, kitty via `SIGUSR1`). Run it after editing a template by hand, or use `--set KEY '#rrggbb'` to change one color from a terminal, `--get KEY` / `--dump` to read the palette back out
- [`theme/render.py`](theme/render.py) renders every template to its destination and reloads the affected apps (`hyprctl reload`, `makoctl reload`, kitty via `SIGUSR1`). It also pings the running shell over Quickshell's two IPC targets (`theme` for the bar, `theme-widget` for the widget itself — two separate top-level QML components) so the bar's own accent/border/pill colors and all four opacities, which live in QML rather than a config file another app reads, pick up changes immediately too — no restart. Run it after editing a template by hand, or use `--set KEY VALUE` to change one color (`#rrggbb`) or opacity (`0`-`1`) from a terminal, `--get KEY` / `--dump` to read the palette back out
- [`theme/wallpaper.py`](theme/wallpaper.py) swaps the wallpaper: `apply <path>` archives the current one (deduped by hash) into `~/.local/share/quickshell/wallpapers/` and copies the new one to [`hypr/wallpaper.png`](hypr/wallpaper.png) (loaded via `swaybg` in `hyprland.lua`), `pick` does the same via a native file picker, `list` feeds the widget's gallery of past wallpapers
- [`theme/presets.py`](theme/presets.py) saves/loads/deletes named snapshots of the *entire* palette (every color and opacity value) as JSON files in `~/.local/share/quickshell/theme-presets/` — per-machine user data, not project config, so it's never tracked by this repo, same reasoning as the wallpaper history above. A built-in `Default` entry (the palette below) is always available, can't be saved over or deleted, and doesn't live in that folder — it's hardcoded in both `presets.py` and the widget
mako's per-urgency border colors (normal = accent, low = muted, critical = red) work the same way as Hyprland's border colors: edit the template at `theme/templates/mako/colors.ini`, not `mako/colors.ini` itself — that gets overwritten on the next render.
Day to day, neither script needs to be run by hand — the **theme widget**, a small standalone Quickshell window pinned to the top-left corner of the main monitor (independent of the bar), has two buttons: a picture icon opens the wallpaper gallery/picker, a paintbrush icon opens a menu to pick which color role to change and then a palette (plus a hex field) to change it to. Both call straight into the scripts above.
Day to day, none of those scripts need to be run by hand — the **theme widget**, a small standalone Quickshell window pinned to the top-left corner of the main monitor (independent of the bar, and deliberately on the Bottom wlr layer so normal windows cover it instead of sitting over everything), has three buttons: a picture icon opens the wallpaper gallery/picker; a paintbrush icon opens a menu to pick which color role to change and then a palette (plus a hex field) to change it to, with an Opacity section below the role list — a slider per surface (Bar/Pills/Popups/Terminal) with its own small color swatch right next to it, since each of those pairs a `*_color` with a `*_opacity`; and a bookmark icon opens the preset list — a name field + Save button at the top, `Default` and every saved preset below it (click to load, trash icon to delete a saved one), with a checkmark on whichever one matches the palette currently live. All three call straight into the scripts above and reflect changes instantly — dragging a slider updates its own live preview continuously but only actually calls `render.py --set` (which reloads everything) on release, not on every pixel of movement.
A few icon colors in the bar are deliberately hardcoded rather than bound to the palette, where they happened to reuse the exact hex value of an unrelated role (e.g. the CPU pill's icon used to share `color12` with the help icon and every popup's detail text — recoloring one recolored the other) — see the comments at each spot in `Bar.qml` if a bar icon doesn't seem to follow a color change.
It's a blue theme (`#1793d1` accent on a dark `#1a1b26` background) built around the stock default Hyprland wallpaper — the anime girl waiting at the train stop with the glowing blue Hyprland-logo cats. Every accent color across the bar, Rofi, Kitty, and the rest was picked to match that wallpaper's palette rather than the other way around.