Skip to content

[FEATURE REQUEST] Background: a picture's own opacity, and a mask over it - #88

Closed
Dararaaaa wants to merge 3 commits into
ELY-Open-Source:mainfrom
Dararaaaa:feat/background-mask
Closed

Dararaaaa wants to merge 3 commits into
ELY-Open-Source:mainfrom
Dararaaaa:feat/background-mask

Conversation

@Dararaaaa

@Dararaaaa Dararaaaa commented Nov 10, 2026 •

Copy link
Copy Markdown

[FEATURE REQUEST] Background: a picture's own opacity, and a mask over it

Type

  • Bug
  • Feature

What and why

A background picture can now fade where it paints: by its own opacity, and by a mask that fades it across its box, as CSS's mask-image does. The window's Background opacity keeps doing what it did — the whole window's ground and picture — while the picture's own opacity fades only the picture, so a picture can sit lightly over the theme's ground.

Settings › Appearance › Background gains, after the gradient's rows:

  • Picture opacity, a slider from 0 to 1 (background_image_opacity).
  • Mask, a switch (background_mask) with an angle in degrees, 0 upward and turning clockwise (background_mask_angle), two to sixteen stops, comma separated (background_mask_stops), whose alpha is the mask, and the mask's own box: a size (background_mask_size) and a place (background_mask_position), as CSS's mask-size and mask-position.

The picture's opacity applies to every tile. The mask fades a picture that does not repeat, since a repeated picture's tiles would cut the fade; it is drawn by scaling the fourth byte of gpui's straight BGRA pixels, the alpha, through the picture's place in its box, and only inside the mask's box — a pixel outside it stays clear. Masked copies are kept by image, mask and box, four at most, so a frame does not mask again.

validate() refuses an opacity outside 0 to 1, an angle outside 0 to 360 and a stops list that does not read, so a bad settings file stops the start, as any other out-of-range value does.

How it was tested

  • Rebased onto upstream/main a0c01b6 after PR3 merged as 8ff412c, then 69080d7 T176; the branch carries three commits: 9b2a0a2 (opacity and mask), 1afce3f (the mask's size and position) and 3e7a84c (the hints).
  • cargo build, cargo fmt --all -- --check clean, cargo clippy --all-targets -- -D warnings clean.
  • cargo test --lib wallpaper::: 9 passed (the mask's alpha, its box, and a box smaller than its picture leaving the rest clear); settings::tests::a_mask… and a_picture…: 3 passed. The full suite fails on this machine's sandbox in the tests that write a temp folder (they panic at src/files/tests.rs:11, fs::create_dir_all) and in the known shell and registry tests, which fail the same way on main.
  • New tests: src/settings/mask.rs (each_stop_is_a_color, the_angle_fades_across_the_box, the_stops_share_the_way_evenly), src/settings/tests.rs::a_mask_and_the_pictures_opacity_keep_their_figures, src/workspace/wallpaper/mask.rs (the_mask_fades_the_pictures_alpha, a_mask_box_leaves_the_picture_outside_it_clear, a_mask_box_keeps_its_place_and_size).
  • On screen, on Windows 10 (build 19045), with a window-scope picture, mask angle 90, size 100% 100%, place center and stops transparent, transparent, black: the picture fades in from the window's left edge to full at its right, over the theme's ground (target/pr4c/mask.png). With size 40% 100% and place right top, the picture stays inside the window's right 40% and everything outside that box is clear (target/mask-pos/mask-right-top.png).

Screenshots

Before After
image image

Checklist

  • PRD.md, AGENTS.md, tasks/acceptance.md and docs/en_us|zh_cn/features.md say what this does.
  • Files stay at or under 500 lines, comments are one short line.
  • No migration shim: the fields sit beside background_image and an old settings file still loads.
  • Every state change on a key path is logged.
  • The base of this PR is main; PR3 is merged there.

@Raiden-MeixElysia

Copy link
Copy Markdown
Contributor

Merged into main with you as the author of all three commits: 2e163b7, 1fb7b0e and 5bccbcb. It ships in 0.2.4. Thank you.

Review found things in the mask that I fixed on top, in 2895626, 3cfbb72 and 410bcb2:

  • The masked copies were kept four at a time, keyed by the image's address, and their textures were never taken out of the window's atlas, which gpui keeps until Window::drop_image. A cover picture made a new copy and a new texture at every step of a resize. Now one copy is kept, keyed by the picture's ImageId, the mask, the scale and the lengths that place it; a new copy drops the old texture, and a mask turned off drops the last.
  • Mask::alpha worked the sine and cosine out at every pixel. The mask now works its line out once.
  • A slanted mask ignored the box's shape. It now runs along CSS's gradient line, |W sin| + |H cos| long, so 45 degrees on a 200 by 100 box fades as a browser fades it.
  • The alpha was baked at the picture's own resolution, so a small picture drawn large got steps, and a 1 by 1 picture one flat alpha. The frame is now stretched to the device pixels it is drawn in first, 4096 a side and 4096 by 4096 in all at most.
  • split(',') cut rgba(0, 0, 0, 0) at its own commas, so such a stop was refused. Stops now part only at commas outside parentheses.
  • Mask::new(...).ok() and masked(...) -> Option drew the picture unmasked without a word when something failed. The settings check the mask, so the paint now expects it.
  • PICTURE_OPACITY duplicated OPACITY; src/settings/mod.rs had passed 500 lines after the rebase.

Two limits stay, and AGENTS.md says so: a resize that moves a masked picture masks again at each step, a whole pass over its pixels on the main thread; and an animated picture shows its first frame under a mask.

Closing, since the commits are in main.

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