Repository navigation
Bound wallpaper resource use when sampling bar colors - #14281
Conversation
[Medium impact] The PR appears safe to merge; no outstanding findings remain. SummaryThe PR bounds ImageMagick’s memory, disk, thread, and time use when sampling wallpaper colors, and reduces the sampling canvas for high-resolution screens. It adds coverage for resource bounds, fallback behavior, and fine-detail averaging. Reviews (5) · Last reviewed commit: "Make the stripe test fail when the wallp..." · Reviewed by Greptile |
chessing234
left a comment
There was a problem hiding this comment.
Reviewed head b32a8bcb1a019424b3b528a4dbf3cead137da2cf.
Reviewed the ImageMagick memory/map/disk/time/thread bounds, hard timeout, and existing fallback path. No actionable production-code defect found. The added stub case checks configured limits rather than actual timeout/resource enforcement; I did not run a native ImageMagick/Omarchy wallpaper integration test.
|
Bounding this makes sense. One thing to double-check before merging is whether 256 MiB is enough for large-but-legit wallpapers. Arch's ImageMagick is Q16-HDRI (float channels), so a 6K (6016×3384) RGB image is already around 230 MiB of pixel cache before Could you run it against a 6K and an 8K wallpaper? If they fall back, then either raising the memory limit to around 512 MiB or shrinking at read time where the coder supports it (e.g. |
The 256 MiB pixel-cache limit made many legitimate wallpapers fall back to the configured text color: Arch's ImageMagick is Q16-HDRI, so a 6K image alone needs about 230 MiB, and resizing to a 4K or 6K screen added a second full-size buffer. 31 of 92 stock theme backgrounds fell back at 1080p, 46 at 4K. Raise the limit to 512 MiB, let JPEG decode at about canvas size, sample on a canvas at most 1920 px wide, and point-sample to it instead of resizing. Only the bar strip's mean color is needed. All 92 stock backgrounds now make the same choice as unbounded sampling, 6K and 8K JPEG and PNG are sampled, and a 96 MP PNG still falls back cheaply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Good catch, you're right, and it was worse than 6K/8K photos: many stock theme backgrounds are 6K WebP, so 256 MiB made 31 of the 92 fall back at 1080p and 46 at 4K. Measured with ImageMagick 7.1.2 Q16-HDRI in a sandbox:
Test updated and PR description refreshed. |
|
Thanks for measuring this across all the stock backgrounds. 512 MiB plus One remaining gap: I think Greptile's P1 on |
|
Thanks for measuring against the stock backgrounds. All 92 making the same choice as unbounded sampling is convincing, and 512 MiB plus On Greptile's point-sampling note: if it ever matters, |
Point sampling to the canvas could land on one phase of fine stripes and pick the wrong text color. Box scaling averages every source pixel at about the same memory cost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
You were right, and Pushed as 0b80c02: |
|
Thanks for testing it against the stripe cases. 22/22 matching |
The stripe assertion expected the configured text color, which is also what the helper prints when ImageMagick gives up, so a sample that never ran passed it. Swap the colors so only a finished, averaged sample produces the expected one; point sampling and a failed sample both still fail it. Co-Authored-By: Codex Medium <noreply@openai.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed at 0ce821c, tested on a disposable Omarchy worker (ImageMagick 7.1.2-33 Q16-HDRI). The fix is real and proportionate. Reproduction. A 290 KB, 12000×8000 RGB PNG made the Tests. Pushed: 0ce821c. The stripe test expected One cost, for the maintainer. RGB PNGs at 5K, 6K and 8K still sample. 6K and 8K PNGs with an alpha channel do not: ImageMagick runs out of its 512 MiB cache while decoding them, so they keep the configured text color where Overlap. #8307 changes the same geometry and the same Second opinion. Codex Medium reviewed it in two rounds. It found the vacuous stripe assertion and had nothing left on the final head. On its own fixtures it confirmed the canvas geometry for landscape, portrait and ultrawide screens and all four bar positions, and it found the RGBA failure happens during decoding. Its independence from this review is not guaranteed. This now waits on the maintainer. |
* Bound wallpaper resource use when sampling bar colors * Test the configured-color fallback when a wallpaper sample fails or times out * Sample 6K and 8K wallpapers within the bar color memory bound The 256 MiB pixel-cache limit made many legitimate wallpapers fall back to the configured text color: Arch's ImageMagick is Q16-HDRI, so a 6K image alone needs about 230 MiB, and resizing to a 4K or 6K screen added a second full-size buffer. 31 of 92 stock theme backgrounds fell back at 1080p, 46 at 4K. Raise the limit to 512 MiB, let JPEG decode at about canvas size, sample on a canvas at most 1920 px wide, and point-sample to it instead of resizing. Only the bar strip's mean color is needed. All 92 stock backgrounds now make the same choice as unbounded sampling, 6K and 8K JPEG and PNG are sampled, and a 96 MP PNG still falls back cheaply. * Average wallpaper detail when scaling the bar color sample Point sampling to the canvas could land on one phase of fine stripes and pick the wrong text color. Box scaling averages every source pixel at about the same memory cost. * Make the stripe test fail when the wallpaper sample does not finish The stripe assertion expected the configured text color, which is also what the helper prints when ImageMagick gives up, so a sample that never ran passed it. Swap the colors so only a finished, averaged sample produces the expected one; point sampling and a failed sample both still fail it. --------- (cherry picked from commit 40054aa) Co-authored-by: Alexander Holbreich <holbreich@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Omarchybot <317366263+omarchybot@users.noreply.github.com> Co-authored-by: Codex Medium <noreply@openai.com>
…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>
Both conflicts resolve to quattro's side. bin/omarchy-bar-text-color takes omacom#14281's bounded sampling, which covers this branch's downscale. test/shell.d/runtime-smoke-test.sh was restructured on quattro, so the bar test is rewritten against it in a later commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge took quattro's omarchy-bar-text-color, whose 1920px canvas, JPEG size hint and resource caps from omacom#14281 already bound the sample this branch shrank, so its tests for the old downscale go with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tate writes (#8307) * Stop re-sampling the wallpaper for the transparent bar on unrelated state writes The bar watched ~/.local/state/omarchy/current for background changes. A directory path never sits in QFileSystemWatcher's file set, so Quickshell's FileView re-emitted fileChanged for every entry created, renamed or removed in ~/.local/state/omarchy as well. Any plugin writing there atomically (tmp + rename) re-ran omarchy-bar-text-color, and on a 5K display that ImageMagick pass cost ~2.6 core-seconds across every thread. One plugin saving every 10 s held ~40% of a core for the whole session, invisible in quickshell's own CPU figure because magick is a reaped grandchild. Watching the symlink directly does not work: inotify follows it to the old image and ln -nsf never touches that inode. Keep the directory watch, resolve the link with readlink -f and only refresh when the wallpaper actually moved. Sample at a reduced scale in omarchy-bar-text-color too. The strip is averaged to one pixel, so shrink the geometry by an integer factor (never upscale) and let the JPEG decoder skip the detail: 2.58 -> 0.065 core-seconds per sample on a 2912x1632 JPEG at 5120x2160, same result. * Resolve the background link at startup and cover the watcher in the runtime smoke test FileView reports no change for its initial load, so without a baseline the first unrelated write in the state directory still compared against "" and sampled once. Run the probe when the bar starts. The smoke test now stubs omarchy-bar-text-color and counts calls in the running shell: turning transparency on samples once, an atomic write of an unrelated file in ~/.local/state/omarchy does not sample again, and repointing current/background does. Against the previous Bar.qml the unrelated write registers as a second sample and the test fails. * Drop the reduced-scale helper tests, which #14281 covers The merge took quattro's omarchy-bar-text-color, whose 1920px canvas, JPEG size hint and resource caps from #14281 already bound the sample this branch shrank, so its tests for the old downscale go with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Watch inside current/ so unrelated state writes do not re-sample the bar FileView watches its path's parent directory too, and re-emits fileChanged for every entry created, renamed or removed there whenever the path itself is not a watched file. Watching ~/.local/state/omarchy/current made that parent ~/.local/state/omarchy, which plugins write to constantly, so the transparent bar re-ran ImageMagick on every unrelated save. Watching current/theme moves the parent to current/, where omarchy-theme-set swaps the theme and omarchy-theme-bg-set repoints the background link, and both still arrive. This replaces a readlink probe that resolved the link on every event: no extra process, and a theme switch that lands on a same-named background still re-samples. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Codex Medium <noreply@openai.com> --------- Co-authored-by: Omarchybot <317366263+omarchybot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Omarchybot <omabot@omarchy.org> Co-authored-by: Codex Medium <noreply@openai.com>
…tate writes (#8307) (#16799) * Stop re-sampling the wallpaper for the transparent bar on unrelated state writes The bar watched ~/.local/state/omarchy/current for background changes. A directory path never sits in QFileSystemWatcher's file set, so Quickshell's FileView re-emitted fileChanged for every entry created, renamed or removed in ~/.local/state/omarchy as well. Any plugin writing there atomically (tmp + rename) re-ran omarchy-bar-text-color, and on a 5K display that ImageMagick pass cost ~2.6 core-seconds across every thread. One plugin saving every 10 s held ~40% of a core for the whole session, invisible in quickshell's own CPU figure because magick is a reaped grandchild. Watching the symlink directly does not work: inotify follows it to the old image and ln -nsf never touches that inode. Keep the directory watch, resolve the link with readlink -f and only refresh when the wallpaper actually moved. Sample at a reduced scale in omarchy-bar-text-color too. The strip is averaged to one pixel, so shrink the geometry by an integer factor (never upscale) and let the JPEG decoder skip the detail: 2.58 -> 0.065 core-seconds per sample on a 2912x1632 JPEG at 5120x2160, same result. * Resolve the background link at startup and cover the watcher in the runtime smoke test FileView reports no change for its initial load, so without a baseline the first unrelated write in the state directory still compared against "" and sampled once. Run the probe when the bar starts. The smoke test now stubs omarchy-bar-text-color and counts calls in the running shell: turning transparency on samples once, an atomic write of an unrelated file in ~/.local/state/omarchy does not sample again, and repointing current/background does. Against the previous Bar.qml the unrelated write registers as a second sample and the test fails. * Drop the reduced-scale helper tests, which #14281 covers The merge took quattro's omarchy-bar-text-color, whose 1920px canvas, JPEG size hint and resource caps from #14281 already bound the sample this branch shrank, so its tests for the old downscale go with it. * Watch inside current/ so unrelated state writes do not re-sample the bar FileView watches its path's parent directory too, and re-emits fileChanged for every entry created, renamed or removed there whenever the path itself is not a watched file. Watching ~/.local/state/omarchy/current made that parent ~/.local/state/omarchy, which plugins write to constantly, so the transparent bar re-ran ImageMagick on every unrelated save. Watching current/theme moves the parent to current/, where omarchy-theme-set swaps the theme and omarchy-theme-bg-set repoints the background link, and both still arrive. This replaces a readlink probe that resolved the link on every event: no extra process, and a theme switch that lands on a same-named background still re-samples. --------- (cherry picked from commit bc220e7) Co-authored-by: Ryan Yogan <ryanyogan@gmail.com> Co-authored-by: Omarchybot <317366263+omarchybot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Codex Medium <noreply@openai.com>
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
A bar is usually set further off the edges it spans than off the one it hangs from — sketchybar and waybar both inset 8 at the sides and 4 at the top — which a single margin cannot express. Read the gap through Geometry.parseWidthSpec, the width spec the border widths already take, so margin accepts N, "Y X", "T X B" or "T R B L" with no new vocabulary. A scalar still means every edge. omarchy-bar-text-color crops the wallpaper at the screen edge to choose a legible transparent-mode foreground, a strip a detached bar no longer covers. It takes an --inset now, applied to all four crops. At margin 0 the crops are byte-identical, so a flush bar is untouched. [Rebased onto the full-screen bar window (omacom#6782): the margins inset the painted strip instead of the window. Drag points need no offset there, so the windowScreenPoint() change is dropped. Rebased again onto bounded wallpaper sampling (omacom#14281): the insets scale with the 1920 px sample canvas. The Bar.qml and Style.qml source asserts are dropped, as upstream no longer keeps source-text tests (omacom#16334).]
Fixes #14167.
Refs #8906
Problem
The transparent bar samples its wallpaper through ImageMagick. The existing
[0]selector bounds multi-frame backgrounds, but a single highly compressed, high-resolution image still expands at source size before the resize. ImageMagick's default memory limit follows available RAM and its disk cache is unlimited; on Omarchy/tmpis normally tmpfs.A sandboxed 12000×8000 RGB PNG (291 KiB on disk) made the current helper peak at 1.36 GB RSS just to choose between two configured colors.
Change
Bound this best-effort sample to:
To keep legitimate 6K and 8K wallpapers inside that bound (Arch's ImageMagick is Q16-HDRI, so a 6K image alone needs about 230 MiB):
-define jpeg:size)-scale) instead of resized, which avoids a second full-size buffer while still averaging every source pixel (point sampling aliased on fine stripes)When a wallpaper cannot be sampled inside those bounds, the helper uses its existing configured text-color fallback.
The regressions execute the real helper with stubbed
timeoutandmagick: they check every bound, the scaled canvas for a 6K screen, and that a failed or timed-out sample keeps the configured color. A real-image regression checks that fine stripes are averaged rather than point-sampled.Testing
test/shell.d/bar-text-color-test.sh: 9/9; each new assertion fails against the previous helper (the stripe test also fails with-sample)./test/cli: 117/117bash -n,git diff --check: passquattro(before the scaled canvas, 256 MiB made 31 of them fall back at 1080p and 46 at 4K)quattro; 12.7 MB fallback with this change-scalematches unbounded-resizein 22/22 cases;-samplediffered in 6 (4 clear wrong picks).-scalepeaks within 1 % of-sample(max 0.8 s)Measured in Bubblewrap with ImageMagick 7.1.2-31 Q16-HDRI. No live wallpaper or compositor process was changed during testing.
Related: #14220 avoids the second decode when GPU sampling succeeds, but retains this command as its fallback. #8307 reduces repeated work. This change keeps that fallback bounded independently.