Skip to content

fix(wallpaper): support matugen 4.x and TTY-less invocation#39

Open
wendeus0 wants to merge 1 commit into
debuggyo:mainfrom
wendeus0:fix/matugen-4-prefer-and-dict-format
Open

fix(wallpaper): support matugen 4.x and TTY-less invocation#39
wendeus0 wants to merge 1 commit into
debuggyo:mainfrom
wendeus0:fix/matugen-4-prefer-and-dict-format

Conversation

@wendeus0
Copy link
Copy Markdown

Summary

Fixes theme regeneration on systems with matugen >= 4.x (current Arch Extra version). Two related bugs prevent the appearance toggle (Light/Dark, color schemes, wallpaper) from updating any color file — the user_settings.json is saved correctly but every downstream stylesheet stays stale, and on the next ignis reload the shell may crash entirely.

Closes #37

Root cause

1. Missing --prefer flag

Matugen 4.x requires --prefer <strategy> when an image has multiple extractable source colors and no TTY is attached. exec_sh_async never has a TTY, so every matugen image invocation aborts with:

Error: Multiple source colors found, no preference was inputted, and a terminal was not detected.
Use --prefer=PREFERENCE to find suitable colors without needing user input.

The asyncio.create_task swallows this silently, so from the user's perspective the toggle "does nothing".

2. --json hex output shape changed

Matugen 4.x emits

{"colors": {"background": {"light": {"color": "#fcfaec"}, "dark": {"color": "#11150c"}}}}

instead of the previous flat "#fcfaec" strings. generatePreviews() writes color_value straight into preview-colors.scss, producing invalid SCSS like

$palette-content-background: {'color': '#fcfaec'};

Sass compilation fails, the stylesheet pipeline dies, and on the next reload the Ignis shell renders without any CSS (Material Symbols become literal text labels, cards lose their background).

Changes

Where What
matugen image invocations Append --prefer saturation (matches visual intent of the selected scheme without UI input)
2× loops in generatePreviews() Unbox color_value when it is a dict, reading color / hex / first-value-fallback

Backwards compatible: the dict unbox only triggers when isinstance(color_value, dict) is true, so matugen-bin 3.x and matugen-git (which already returned strings) keep working.

Test plan

  • Reproduce on Arch with matugen-bin 4.1.0: confirmed toggle was a no-op and ignis reload crashed Ignis with Expected expression from preview-colors.scss
  • Apply patch, run matugen image -t scheme-expressive '<wallpaper>' -m light --prefer saturation manually — ~/.config/ignis/colors.scss, ~/.config/gtk-3.0/colors.css, ~/.config/gtk-4.0/colors.css, ~/.config/qt5ct/colors/matugen.conf, ~/.config/qt6ct/colors/matugen.conf all regenerate cleanly
  • preview-colors.scss now contains valid SCSS ($palette-content-background: #fcfaec;)
  • ignis reload succeeds; Light/Dark toggle applies in real time; color scheme bolinhos update palette
  • Confirm on matugen-bin 3.x / matugen-git (relying on isinstance guard for compat — would appreciate a second pair of eyes here)

Notes for reviewer

  • --prefer saturation is a heuristic choice. If you'd rather expose this as a setting (user_settings.appearance.wallcolors.prefer), happy to push a follow-up.
  • The dict unbox path only matters for the preview palette generation. The main setDarkMode / setColors flow doesn't read JSON output, only triggers matugen and lets the templates do their thing — so the existing template files do not need changes.

🤖 Generated with Claude Code

…tion

Two related bugs prevented theme regeneration when running with
matugen >= 4.x (current Arch Extra version):

1. matugen requires `--prefer` when multiple source colors can be
   extracted from an image and there is no TTY, which is always the
   case under `exec_sh_async`. Without it, the subprocess aborts
   silently. The user_settings JSON is updated, but the SCSS / GTK /
   Qt color files stay stale, so the next reload shows the previous
   palette and the toggle appears broken.

2. matugen 4.x changed the JSON shape of `--json hex` from raw hex
   strings to `{"color": "#hex"}` dicts. `generatePreviews()` writes
   `color_value` straight into preview-colors.scss, which now produces
   invalid SCSS like

       $palette-content-background: {'color': '#fcfaec'};

   This crashes Sass compilation on `ignis reload` and the shell
   silently dies (no stylesheet -> no UI).

This patch:
  - Adds `--prefer saturation` to all 8 `matugen image` invocations
    (3 in `setWall`, 3 in `setColors`/`setDarkMode`, 2 in
    `generatePreviews`). Saturation matches the visual intent of the
    selected scheme without UI input.
  - In `generatePreviews()`, unboxes `color_value` when it is a dict
    by reading `color`/`hex` keys (matugen 4.x) and falls back to the
    first value otherwise. Backwards compatible with matugen-bin 3.x
    and matugen-git, which already returned strings.

Closes debuggyo#37

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swww and Matugen not responding with wallpaper settings.

1 participant