Skip to content

feat: optional matugen support as alternative dcol backend - #1735

Open
0xGeN02 wants to merge 10 commits into
HyDE-Project:devfrom
0xGeN02:feat/optional-matugen-support
Open

feat: optional matugen support as alternative dcol backend#1735
0xGeN02 wants to merge 10 commits into
HyDE-Project:devfrom
0xGeN02:feat/optional-matugen-support

Conversation

@0xGeN02

@0xGeN02 0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds optional matugen (Material You color generation) support as an alternative color extraction backend for wallbash/dcol. This addresses the long-standing issue where some users' systems fail to extract colors via imagemagick.

Closes #1701

What this does

  • New file: wallbash-matugen.sh — Drop-in alternative to wallbash.sh that generates an identical 89-line .dcol file using matugen's tonal palettes instead of imagemagick's k-means clustering.
  • Modified: wallpaper/cache.sh — Added fn_generate_dcol() dispatcher function that routes dcol generation to the appropriate backend based on user configuration.
  • Modified: pkg_extra.lst — Added matugen-bin as an optional (commented) package.

Configuration

Users can set DCOL_BACKEND in their Hyde config:

Value Behavior
(unset) / imagemagick Default — original wallbash.sh, no change in behavior
matugen Use matugen exclusively (auto-fallback to imagemagick if matugen not installed)
auto Try imagemagick first, fallback to matugen if it fails or produces invalid output

How the mapping works

Matugen generates Material You tonal palettes (6 palettes × 18 tones). These are mapped to dcol's 4-group structure:

dcol group matugen palette Purpose
Group 1 (pry1) neutral Background/surface colors (dark, desaturated)
Group 2 (pry2) primary Main accent color
Group 3 (pry3) secondary Muted accent
Group 4 (pry4) tertiary Complementary accent

Each group maps 9 tones to xa1xa9 (dark→bright in dark mode, reversed in light mode).

Why matugen?

  1. Safety net — Some users have reported imagemagick failing to extract colors (broken kmeans on certain systems/images). Matugen uses its own Rust-based color extraction.
  2. Material You harmony — Matugen produces perceptually uniform, harmonious color schemes by design (based on Google's HCT color space).
  3. Zero impact on default — Without setting DCOL_BACKEND, behavior is 100% unchanged.

Testing

  • Tested with 5+ wallpapers, all produce exactly 89 lines with valid shell syntax
  • Live-tested wallbash template deployment with matugen-generated colors
  • Verified fallback behavior (matugen not found → imagemagick; imagemagick fails → matugen)

Dependencies

  • matugen-bin (AUR) — only required if user opts into matugen backend
  • python3 — already a HyDE dependency (used for JSON parsing in wallbash-matugen.sh)

Summary by CodeRabbit

  • New Features
    • Optional Material You–based palette backend and CLI wrapper that can produce an alternate color file and integrate with the app’s color selection, including automatic dark/light mode detection.
  • Bug Fixes
    • Palette generation now validates outputs, warns on unexpected results, and reports success with details.
  • Chores
    • Added a commented optional package entry for the new backend.

Add wallbash-matugen.sh as a drop-in alternative to wallbash.sh for
color extraction. Uses Material You tonal palettes from matugen instead
of imagemagick k-means clustering. This provides a safety net for
systems where imagemagick fails to extract colors.

Configuration via DCOL_BACKEND env var:
- imagemagick (default): original behavior, no change
- matugen: use matugen exclusively
- auto: try imagemagick first, fallback to matugen on failure

Closes HyDE-Project#1701
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an optional Material You backend: a new wallbash-matugen.sh CLI that wraps matugen to emit .mcol/.dcol-compatible output; wallpaper cache now delegates .dcol generation to fn_generate_dcol (which may invoke wallbash-matugen.sh), and color sourcing prefers .mcol when DCOL_BACKEND=matugen.

Changes

Wallpaper Color Extraction Backend Abstraction

Layer / File(s) Summary
Material You Entrypoint
Configs/.local/lib/hyde/wallbash-matugen.sh
New executable: parses --dark/--light and wallbash-style flags, checks input and matugen binary, runs matugen image --json ..., derives dark/light when auto, embeds a Python generator to emit an 89-line .mcol/.dcol-compatible output (hex + _rgba fields), validates line count.
Generation Helper
Configs/.local/lib/hyde/wallpaper/cache.sh (fn_generate_dcol)
New fn_generate_dcol produces .dcol via wallbash.sh and conditionally produces/refreshes a matching .mcol via wallbash-matugen.sh when matugen is present or .mcol is missing/invalid; exported for parallel workers.
Call Sites / Integration
Configs/.local/lib/hyde/wallpaper/cache.sh (call sites)
fn_wallcache and fn_wallcache_force now call fn_generate_dcol(...) instead of invoking wallbash.sh directly.
Color Sourcing Selection
Configs/.local/lib/hyde/color.set.sh
Adds mcol_file, extends cache-generation check for backend-specific .mcol availability, and prefers sourcing .mcol when DCOL_BACKEND=matugen (falls back to .dcol).
Packaging Note
Scripts/pkg_extra.lst
Adds a commented matugen-bin package suggestion under “Backends”.
Repository Metadata
Wiki
Submodule reference changed (diff shows a subproject commit update).

Sequence Diagram(s)

sequenceDiagram
  participant Cache as Wallpaper Cache (fn_wallcache)
  participant Gen as fn_generate_dcol
  participant WB as wallbash.sh
  participant MatuScript as wallbash-matugen.sh
  participant Mat as matugen
  participant FS as Filesystem

  Cache->>Gen: request .dcol for image
  Gen->>WB: invoke wallbash.sh to produce .dcol
  WB-->>Gen: .dcol created
  Gen->>FS: check .mcol (exists & valid?)
  alt .mcol missing/invalid and matugen available
    Gen->>MatuScript: invoke wallbash-matugen.sh with image
    MatuScript->>Mat: matugen image --json ...
    Mat-->>MatuScript: tonal JSON
    MatuScript->>MatuScript: python -> convert JSON to .mcol/.dcol lines
    MatuScript-->>Gen: .mcol written
  end
  Gen-->>Cache: return .dcol path (and .mcol if produced)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • kRHYME7

Poem

A rabbit nibbles at the hue,
Matugen hums a palette true,
If ImageMagick stumbles, fret not so,
Fallback tones and accents glow,
Nine gleaming shades in RGBA. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: optional matugen support as alternative dcol backend' accurately captures the main change: adding matugen as an optional backend alternative to ImageMagick for color extraction.
Linked Issues check ✅ Passed Code changes fully implement the objectives from #1701: optional matugen backend added, wallbash responsibilities decoupled via fn_generate_dcol(), coexistence/fallback strategy implemented, and seamless switching enabled via DCOL_BACKEND configuration.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to implementing matugen support: new wallbash-matugen.sh, cache.sh dispatcher, color.set.sh sourcing logic, and optional package entry. Wiki submodule change appears incidental per PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Note on color differences between backends

ImageMagick and matugen produce different colors from the same wallpaper — this is by design:

ImageMagick (wallbash.sh)

  • Uses k-means clustering to extract 4 dominant pixel colors directly from the image
  • Accents (xa1-xa9) are generated by varying brightness/saturation on the exact hue of each dominant color
  • Result: colors that match the wallpaper pixels

Matugen (wallbash-matugen.sh)

  • Extracts 1 source color (most saturated) from the wallpaper
  • Generates 6 harmonious tonal palettes using Google's Material You algorithm (HCT color space)
  • Result: a perceptually uniform color scheme derived from the wallpaper, not the literal pixels

Example (same wallpaper):

ImageMagick: pry1=#130E13  (actual dark pixel from image)
Matugen:     pry1=#1E1A1D  (neutral tone 10, harmonically derived)

Matugen is not meant to replicate imagemagick's output — it's an alternative approach that guarantees valid color extraction on systems where imagemagick's kmeans fails, while producing aesthetically coherent palettes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Configs/.local/lib/hyde/wallbash-matugen.sh (1)

67-76: ⚡ Quick win

Update the mapping/tone comments to match the implemented logic.

This comment block contradicts the actual mapping in Line 90 and tone selection in Lines 95–105. Please align the documentation with the real behavior to avoid accidental regressions during future edits.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Configs/.local/lib/hyde/wallbash-matugen.sh` around lines 67 - 76, The
comment block describing the color mapping/tone rules is out of sync with the
actual implementation; update the comment so it matches the real behavior used
in the dcol assignment block and the tone selection logic (the code that builds
pry, txt and xa1–xa9 for each dcol group). Specifically, read the implemented
dcol grouping and the tone selection code that assigns pry/txt/xa1..xa9, then
rewrite the header comments to reflect the correct mapping of group numbers to
palettes and the true tone numbers/direction used for pry and txt (and the
xa1–xa9 ordering) so the documentation mirrors the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Configs/.local/lib/hyde/wallbash-matugen.sh`:
- Around line 67-76: The comment block describing the color mapping/tone rules
is out of sync with the actual implementation; update the comment so it matches
the real behavior used in the dcol assignment block and the tone selection logic
(the code that builds pry, txt and xa1–xa9 for each dcol group). Specifically,
read the implemented dcol grouping and the tone selection code that assigns
pry/txt/xa1..xa9, then rewrite the header comments to reflect the correct
mapping of group numbers to palettes and the true tone numbers/direction used
for pry and txt (and the xa1–xa9 ordering) so the documentation mirrors the
code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3f90e32c-db58-4246-a40f-a204601450e4

📥 Commits

Reviewing files that changed from the base of the PR and between d2c6841 and 28e3739.

📒 Files selected for processing (3)
  • Configs/.local/lib/hyde/wallbash-matugen.sh
  • Configs/.local/lib/hyde/wallpaper/cache.sh
  • Scripts/pkg_extra.lst

@0xGeN02
0xGeN02 force-pushed the feat/optional-matugen-support branch from 28e3739 to 039cbff Compare May 7, 2026 03:14
@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Closes #1701

@kRHYME7

kRHYME7 commented May 7, 2026

Copy link
Copy Markdown
Contributor

wow!!! 🤯 You beat me to it!
Planning to do this and here it came free♥️. I have 2 planned approaches and looks like your implementation is seamless.

So just to be sure if I understand this. As wallbash uses magick to cache .dcol files. We are also implementing the same logic but using matugen right? I did not check the script's full logic but can we coexist both? maybe we can Output a hash.mcol? (Material color, dcol means dominant colors. Help me with naming)

In our theming script we can just source it and whatever color exist wins or if backend was set try to use it.

And I said I planned 2 approaches. 1st is this PR's implementation. Second is having a matugen template. This one's kinda complex because we need to resolve what template to use and explicitly switching them means we won't have a wallbash fallback, if matugen doesn't have the template. And more of this soon let's polish this matugen caching for now.

The Wiki submodule points to a repo that no longer exists and
.gitmodules was already removed. Clean up the dangling gitlink.
@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Yes, you've got it exactly right.

Current implementation: wallbash-matugen.sh generates the same .dcol format (89 lines, same variable names) so it's a transparent drop-in. The dispatcher in cache.sh just decides which script to call.

Your .mcol idea is better — having both coexist:

  • hash.dcol = imagemagick dominant colors (existing behavior)
  • hash.mcol = matugen material colors (new)

Then the theming script (color.set.sh) can source based on backend preference:

# Pseudocode for color.set.sh sourcing logic:
if [[ "$DCOL_BACKEND" == "matugen" ]] && [[ -f "$mcol_file" ]]; then
    source "$mcol_file"
elif [[ -f "$dcol_file" ]]; then
    source "$dcol_file"
fi

This way:

  • Both caches are always generated (no re-computation when switching backends)
  • dcol remains the default/fallback
  • Users can switch backends without waiting for cache regeneration

I'll update the PR to implement the .mcol coexistence approach. Will keep the same variable names inside (dcol_pry1, etc.) so downstream templates don't need changes — only the file extension and sourcing logic differ.

Re: approach #2 (matugen templates) — agreed, let's nail the caching layer first. The template approach would be a separate feature on top of this foundation.

Instead of replacing .dcol with matugen output, generate both:
- hash.dcol = imagemagick dominant colors (always generated)
- hash.mcol = matugen material colors (generated if matugen installed)

color.set.sh sources the appropriate file based on DCOL_BACKEND:
- unset/imagemagick: sources .dcol (default, no behavior change)
- matugen: sources .mcol if available, falls back to .dcol

This allows instant backend switching without cache regeneration.
@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

opencode just auto answered you ahahhaha didnt notice was running still

@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Updated! The implementation now uses the .mcol coexistence approach:

How it works now:

  1. cache.sh always generates .dcol (imagemagick). If matugen is installed, it also generates .mcol alongside.
  2. color.set.sh picks which file to source based on DCOL_BACKEND:
    • unset/imagemagick → sources hash.dcol (default, zero behavior change)
    • matugen → sources hash.mcol if it exists, falls back to hash.dcol

Benefits:

  • Both caches coexist (~/.cache/hyde/dcols/hash.dcol + hash.mcol)
  • Switching backend is instant (no re-computation needed)
  • .dcol is always the fallback safety net
  • .mcol generation is opportunistic (only if matugen binary is present)

Files changed:

  • wallbash-matugen.sh → outputs .mcol extension
  • wallpaper/cache.shfn_generate_dcol() generates both
  • color.set.sh → sourcing logic picks mcol or dcol based on DCOL_BACKEND
  • Also removed orphaned Wiki submodule reference (repo no longer exists)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Configs/.local/lib/hyde/color.set.sh`:
- Around line 164-166: The current cache-generation branch only checks for
dcol_file and will skip regeneration when an older .dcol exists even if
DCOL_BACKEND=matugen and the .mcol cache is missing; update the condition around
the call to "$scrDir/wallpaper/cache.sh" (the block using dcol_file,
wallbash_image and scrDir/wallpaper/cache.sh) so it also triggers when
DCOL_BACKEND equals "matugen" and the mcol_file is absent (i.e., regenerate if [
! -f "$dcol_file" ] || { [ "$DCOL_BACKEND" = "matugen" ] && [ ! -f "$mcol_file"
]; } ), and apply the same change to the similar block at 171-175.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: da69f846-691b-40e9-8a18-44925700f4d1

📥 Commits

Reviewing files that changed from the base of the PR and between c1f21a3 and 61cf7ad.

📒 Files selected for processing (3)
  • Configs/.local/lib/hyde/color.set.sh
  • Configs/.local/lib/hyde/wallbash-matugen.sh
  • Configs/.local/lib/hyde/wallpaper/cache.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • Configs/.local/lib/hyde/wallpaper/cache.sh
  • Configs/.local/lib/hyde/wallbash-matugen.sh

Comment thread Configs/.local/lib/hyde/color.set.sh Outdated
@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Now I think it is done, any other comment on this?

@kRHYME7

kRHYME7 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Ohhhh I scanned through the code but isn't it better to use full python for the wallbash equivalent? This way it is easier to debug. Any reason for the design?

matugen.py is fine for this IMO.

@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

The only reason was to mirror wallbash.sh

@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Added a command for hyde-shell to change the backend easier:

hyde-shell dcol.backend --get              # prints current backend
hyde-shell dcol.backend --set matugen      # switches to matugen
hyde-shell dcol.backend --set imagemagick  # switches back
hyde-shell dcol.backend --select           # rofi picker

@kRHYME7

kRHYME7 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Let's call it hyde-shell color.backend instead.

@0xGeN02

0xGeN02 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Done

@kRHYME7

This comment was marked as outdated.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

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.

3 participants