Skip to content

Sample the transparent bar's text colour from the wallpaper the shell already decoded - #14220

Closed
dt-lindberg wants to merge 7 commits into
omacom:quattrofrom
dt-lindberg:faster-transparent-bar-text-color
Closed

dt-lindberg wants to merge 7 commits into
omacom:quattrofrom
dt-lindberg:faster-transparent-bar-text-color

Conversation

@dt-lindberg

@dt-lindberg dt-lindberg commented Oct 4, 2026 •

Copy link
Copy Markdown

Addresses #14167. With a transparent bar, every wallpaper or theme change ran omarchy-bar-text-color, which decoded the whole wallpaper again in ImageMagick just to average the strip under the bar. The shell has already decoded that image to display it, so this reads the strip back from the shell's copy instead, and ImageMagick is left for the cases where the shell has nothing to read.

How it works

  • Background.qml exposes sampleBarStrip(position, barSize, callback) and settledBackground. The image sampled is whichever decoded image shows the current wallpaper on the first screen: a transition's incoming frame, else the still, so the colour flips as the reveal starts. A ShaderEffectSource copies just the strip and a Canvas reads its pixels, because Context2D.drawImage on an Image item reloads its URL at full size rather than reusing the decoded texture. The average is weighted by alpha, which is what a transparent wallpaper shows over the dark behind the background layer. It answers "" behind a video, for an image that failed to decode, and while a theme intro hides the background.
  • Bar.qml samples when settledBackground names the wallpaper (it is empty while the image is still decoding) and passes the result as --sample. On "", or without the built-in background plugin (or a clone of it from before this change), it runs the command as before. It samples again when settledBackground or the background's suspension changes.
  • omarchy-bar-text-color --sample #rrggbb skips ImageMagick and only makes the contrast choice, so the decision rule stays in one place. The bounded ImageMagick path from Bound wallpaper resource use when sampling bar colors #14281 is unchanged inside sample_background.

Measured

On a worker built from the Omarchy ISO (1280×800 virtio), from omarchy-theme-bg-set to the bar's answer across five stock Tokyo Night wallpapers: 263–509 ms with one --sample call each, against 214–785 ms on quattro, which spends a full ImageMagick decode every time. Most of what remains is the decode the shell does anyway, plus the bar's existing 120 ms debounce.

Known limits

Original work by @dt-lindberg; simplified and merged with quattro by omarchybot.

@dt-lindberg dt-lindberg changed the title Recolour the transparent bar's text in 36 ms instead of up to 1.3 s 18x recolour speedup of transparent bar's text Oct 4, 2026
@dt-lindberg
dt-lindberg marked this pull request as ready for review October 4, 2026 09:26
@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No new blocking issue was established in the reviewed changes.

Summary

The PR adds a faster path for choosing transparent-bar text colors.

  • Transparent bars reuse the decoded wallpaper to choose their text color.

No new actionable issue was established. dt-lindberg acknowledged that refreshes can still be dropped while the color command runs and deferred that separate fix to #14148.

Reviews (4) · Last reviewed commit: "Answer the bar for an undecodable wallpa..." · Reviewed by Greptile

Comment thread shell/plugins/background/Background.qml Resolved

@chessing234 chessing234 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.

Requesting changes on cb9dd1c.

[P2] Keep the canvas image and callback associated with the same sample request (shell/plugins/background/BarStripSampler.qml:32-47,54-55). sample() replaces pendingCallback and stripRect, but leaves the previous grabUrl active. If A's grab has returned and its canvas image is still loading, B can start before A finishes loading. A's image-loaded/paint event then calls average() with A's URL and B's callback. B receives A's color, and finish() clears B before its own grab completes. The bar's outer request counter accepts this result because it is delivered through B's current callback.

I executed the actual sample, average, and finish functions in a Node harness with controlled grab/image-load events: A returns old-white-grab, B starts, then A loads before B's grab returns. B's callback receives #ffffff sampled from old-white-grab.

Please invalidate/unload the old URL when replacing a request and carry a generation/token through both image loading and painting so only that generation can finish. Add a behavioral overlap test for this order of events. This independently confirms the existing overlapping-grabs thread. The harness verifies the state transition; I have not run a live Qt/Wayland rendering test.

@dt-lindberg

Copy link
Copy Markdown
Author

@chessing234 thanks for the harness, the fix has been added in a2017a0.

  • Sampler: each request now carries its own callback, strip and grab url. A newer request unloads the older one's grab, and every step (grab callback, average(), finish()) checks that its request is still the current one before it can finish.
  • Test: background-test.sh now runs BarStripSampler.qml's own sample/average/finish against stand-ins for the grab and canvas, in your order: A's grab returns, B starts, A's image loads, then B's grab returns and loads. It checks that nothing answers after A's load, that A's grab is unloaded, and that B gets #000000 from its own grab. On the previous sampler the test fails with B receiving #ffffff, as you found.
  • Live: with the fixed sampler on the GPU, the 736 stock cases at 1920×1080 and 3840×2160 still give 0 clear disagreements with the ImageMagick path.

The other thread (previous wallpaper sampled during a second transition) is fixed in the same commit.

dt-lindberg and others added 4 commits October 19, 2026 15:34
… already decoded

The bar ran omarchy-bar-text-color, which decoded the wallpaper again in
ImageMagick: 0.3-1.2s on large stock wallpapers, so the text kept the old
colour for up to a second after a wallpaper or theme change. The background
plugin has already decoded the same image at screen size, so it now grabs
the strip under the bar from it on the GPU and averages it (about 30ms), and
the command only makes the choice (--sample). Videos, the software renderer
and anything without a decoded still fall back to the old path.

On all 92 stock wallpapers x 4 screen sizes x 4 positions the choices match
the ImageMagick path except 6 near-ties (contrast margins 1.03-1.05).
ImageMagick flattens a transparent wallpaper over white before the file
path averages it. The shell's sampler averaged colour without alpha, so
fully transparent areas read as black and the two paths chose differently
on transparent wallpapers. Weigh each pixel by its alpha over white too.
Two races could give the bar a strip colour from the wrong pixels:

- The sampler kept one grab url for all requests. When a newer request
  started while an older grab's image was still loading, that image's
  paint answered the newer request with the older pixels. Each request
  now carries its own callback, strip and grab url, a replaced request's
  grab is unloaded, and only the current request can finish.
- transitionBackground() moves currentBackground before
  incomingBackground, and a waiting strip request sampled in between,
  taking the previous transition's incoming frame for the new wallpaper.
  It now samples once both have moved.

A new test runs the sampler's own functions with grabs and image loads
landing in the overlapping order; it fails on the old sampler.
…rsion to it.

Authored by Claude Opus 5.5 and DTL
@dt-lindberg
dt-lindberg force-pushed the faster-transparent-bar-text-color branch from a2017a0 to 1c735c8 Compare October 19, 2026 13:35
@omarchybot omarchybot added the enhancement New feature or request label Oct 21, 2026
omarchybot and others added 3 commits October 27, 2026 13:12
…lback

omacom#14281 bounded the helper's ImageMagick run; that block now lives in sample_background, which only runs without a --sample. quattro removed background-test.sh and the bar test's source checks (omacom#16334), so the source checks this branch added there go with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…allpaper

The sampler now lives beside the images it reads in Background.qml: a ShaderEffectSource copies the strip and a Canvas reads it back, because Context2D.drawImage on an Image item reloads its source URL at full size rather than reusing the decoded texture. The image is a transition's incoming frame, or else the still, so the colour flips as the reveal starts.

The bar no longer queues a request in the background plugin. It waits for settledBackground, which names the current wallpaper once the first screen has decoded it (or at once for a video), and samples then; a hidden panel or a video answers "" and the helper decodes the file as before. That removes the request queue, the 3 s timeout, the url matching and the callLater ordering: the bar re-reads the state when its 120 ms debounce fires, so a transient binding value can cost an extra sample but not a wrong one. A grab issued while the output is asleep simply waits for the next frame.

The strip is a plain average. Alpha weighting only mattered for transparent wallpapers, where a plain average is closer to what the screen shows anyway; and the software-renderer check guarded a backend the live shell does not use.

The source-text checks go, as quattro removed them elsewhere, and so do the --sample cases that pass without the flag. A live check samples a real still through the plugin instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…weight the strip by alpha

A still that fails to decode never produced an image, and recovery keeps the same path when it still exists, so settledBackground stayed empty and the bar waited for ever without turning transparent. A failed image now settles at once and answers without a sample, so the helper falls back to the text colour as before.

A grab issued just before a theme intro suspends the background can be lost with the hidden window, and nothing asked again. The bar now refreshes when the background's suspension changes.

A plain RGB average gave nearly transparent pixels full weight, reading a wallpaper that shows dark as light. Weighting by alpha averages what the screen shows over the dark behind the background layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: muse-spark-1.3-contributor via pi, thinking high <noreply@pi.dev>
@omarchybot omarchybot changed the title 18x recolour speedup of transparent bar's text Sample the transparent bar's text colour from the wallpaper the shell already decoded Oct 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @dt-lindberg — the core idea here is right: the shell has already decoded the wallpaper, so the bar should read its strip from that copy rather than decoding the file again. The maintainer asked for this to be made ready and as simple as it can be, so I merged quattro in and reworked the sampler on top of your branch. Your approach is unchanged; most of the plumbing around it is gone.

What changed and why

  • Merged quattro: Bound wallpaper resource use when sampling bar colors #14281's bounded ImageMagick run now sits inside your sample_background, and the source-text checks in background-test.sh and bar-test.sh went with Remove tests that only read source text #16334, which removed that kind of test from the suite.
  • BarStripSampler.qml is folded into Background.qml: a ShaderEffectSource on whichever decoded image shows the current wallpaper (a transition's incoming frame, else the still), a Canvas to read it, an average. The grab can't be skipped, because Context2D.drawImage on an Image item reloads its URL at full size (qquickcontext2d.cpp in Qt 6.12).
  • The request queue, 3 s timeout, URL matching and callLater ordering are replaced by settledBackground, which names the current wallpaper once the first screen has decoded it, or at once for a video or an image that failed to decode. The bar samples when it is set, and again when it changes or the background is suspended or resumed. Because the bar re-reads the state when its 120 ms debounce fires, a transient binding value can cost an extra sample but never a wrong one. A grab issued while the output is asleep waits for the next frame instead of falling back.
  • The software-renderer check is gone: the live shell doesn't run that backend, and every failure path already answers "", which falls back to the helper.
  • Transparency is weighted by alpha, i.e. what a transparent wallpaper shows over the dark behind the background layer. ImageMagick doesn't flatten over white either: its 1×1 average is alpha-weighted.
  • Tests: one --sample case that fails without the flag, plus a live check that loads the real background plugin in quickshell. It samples a wallpaper that is light above and nearly transparent below for a top and a bottom bar, and an undecodable one that must answer without a sample.

Net diff against quattro: 4 files, +256/−67 (+194/−5 ignoring whitespace; the helper is mostly a reindent), down from 5 files, +330/−68 for the merged original.

What was checked, on a worker built from the Omarchy ISO

  • Transparent bar over light and dark wallpapers, top and bottom, at scales 1, 1.25 and 2; after a wallpaper change; across theme switches with intros; and behind a video. A logging wrapper on the helper showed --sample for every still and the file path only behind the video. The colours were also checked in cropped screenshots.
  • From omarchy-theme-bg-set to the bar's answer across five stock wallpapers: 263–509 ms, against 214–785 ms on quattro, which spends a full ImageMagick decode each time. Your original head measured 157–383 ms on the same worker; the difference is the bar's existing debounce, which now runs after the decode instead of overlapping it. So the gain is the decode not spent, not faster wall-clock recolouring, and the title now says what the change does.
  • ./test/cli passes. Every bar and background shell test passes, as does shell-idle-spawn-test.sh. The remaining ./test/shell failures (a node-less worker, plus five unrelated files) fail identically on quattro. The new live checks go red when the sampler is reverted, when the bottom strip is read as the top, when alpha weighting is dropped, and when a failed image doesn't settle.

Second opinion: Codex Medium and muse-spark-1.3 (via pi, thinking high), over two rounds. Round 1 found three real problems, all fixed above: a corrupt wallpaper left the bar waiting for ever, a grab lost to a theme intro was never retried, and the plain average gave near-transparent pixels full weight. One claim was dismissed after checking the Qt source: a visible sliver from the off-screen sampler at fractional scale. Round 2 found nothing further; independence from this review isn't guaranteed.

Still open: a refresh that arrives while the helper is running is still dropped, which #14148 fixes separately. Multi-monitor samples the first screen, as before. I also updated the description to match the code as it now stands.

Waiting on the maintainer.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @dt-lindberg — sampling the image the shell has already decoded is a neat idea, and this branch taught us something real about the transparent bar. We're closing it anyway, because measured on a stock install it doesn't buy enough to carry the extra machinery.

On an Omarchy ISO worker, the time from omarchy-theme-bg-set to the bar's new colour was 263–509 ms with this branch and 214–785 ms on quattro, over five stock wallpapers. The bar's existing 120 ms debounce dominates, so what this saves is the ImageMagick decode, not wall-clock recolouring. Since this was opened, that decode has been capped by #14281 (bounded memory and time, 1920 px canvas), and #8307 stops the bar re-sampling on unrelated state writes, which was most of the wasted work. ImageMagick also stays as the fallback for video wallpapers and failed decodes, so the helper's path has to be kept either way. Against that, the grab-to-Canvas sampler is about 190 lines of shell code to maintain for a decode that now runs rarely and cheaply.

Measured by Claude Opus 5.5 on a worker; the simplified branch was reviewed by Codex Medium and muse-spark (high), and the decision to close is the maintainer's.

@omarchybot omarchybot closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants