Skip to content

fix: use NULL class brush for transparent WebView2 windows#447

Merged
loonghao merged 7 commits into
loonghao:mainfrom
wojzj57:fix/transparent-window-opaque-background
Jun 18, 2026
Merged

fix: use NULL class brush for transparent WebView2 windows#447
loonghao merged 7 commits into
loonghao:mainfrom
wojzj57:fix/transparent-window-opaque-background

Conversation

@wojzj57

@wojzj57 wojzj57 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Transparent windows (transparent=True) showed a solid #020617 background instead of the desktop. The opaque dark class background brush — added to hide white edges before WebView2 paints — bled through wherever WebView2 hadn't yet composited, defeating transparency. Use the NULL stock brush on transparent windows so nothing is painted under the WebView2 content. Fixes #445.

1 commit · 6 files · no breaking public API change (Python arg is optional, defaults to False).

Key changes

crates/auroraview-core/src/builder/window_style.rs — transparent brush path

  • Add set_window_class_null_background() setting GCLP_HBRBACKGROUND to the NULL_BRUSH stock object so the background paints nothing.
  • Thread a transparent: bool param through fix_webview2_child_windows(); transparent windows get the NULL brush, opaque ones keep the dark solid brush.

src/webview/backend/native.rs, src/webview/desktop/mod.rs — call sites

  • Pass config.transparent into the child-window fixer.
  • Skip set_window_class_dark_background() entirely when transparent is set, on both the top-level and Qt-child code paths.

src/window_utils.rs, python/.../qt/embedding.py — Python binding

  • Add optional transparent=False arg to the fix_webview2_child_windows pyfunction.
  • Qt embedding reads self._webview._transparent and forwards it.

Type

  • fix

Breaking changes

None. The new transparent parameter is optional and defaults to False, preserving existing behavior.

Validation

  • cargo test -p auroraview-core — new regression test set_window_class_null_vs_dark_background asserts the transparent path sets NULL_BRUSH and the opaque path keeps a non-NULL brush.
  • cargo fmt --all · cargo clippy --all-targets -- -D warnings
  • Manual: a transparent=True window now shows the desktop through unpainted regions instead of #020617.

The opaque dark class background brush (#020617) showed through where
WebView2 had not yet painted, defeating transparent=True windows. Add
set_window_class_null_background using the NULL stock brush and thread a
`transparent` flag through fix_webview2_child_windows so transparent
windows skip the opaque brush on both the top-level and child windows.

Signed-off-by: wojzj57 <wojzj57@gmail.com>
@wojzj57 wojzj57 mentioned this pull request Jun 17, 2026
3 tasks
wojzj57 added 2 commits June 17, 2026 17:49
rustfmt --check flagged the after_null binding in
set_window_class_null_vs_dark_background; fits the width limit on
one line.

Signed-off-by: wojzj57 <wojzj57@gmail.com>
The NULL-brush transparency fix (a625b27) added four Win32 GDI
unsafe blocks (one in set_window_class_null_background, three in
its regression test) without updating the allowlist count, so
audit_unsafe.py failed on the 27 vs 31 mismatch. All four fall
under the existing GDI brush lifecycle rationale.

Signed-off-by: wojzj57 <wojzj57@gmail.com>
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.15%. Comparing base (7961691) to head (db0045d).
⚠️ Report is 2 commits behind head on main.

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (49.15%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #447      +/-   ##
==========================================
+ Coverage   49.11%   49.15%   +0.04%     
==========================================
  Files         119      119              
  Lines       13388    13389       +1     
  Branches       24       24              
==========================================
+ Hits         6576     6582       +6     
+ Misses       6812     6807       -5     
Flag Coverage Δ
py3.11 52.58% <0.00%> (-0.01%) ⬇️
python 52.58% <0.00%> (-0.01%) ⬇️
rust 38.86% <ø> (+0.16%) ⬆️
sdk 91.91% <ø> (ø)
typescript 91.91% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Python Core 46.65% <ø> (ø)
Python Qt Integration 66.29% <0.00%> (-0.05%) ⬇️
Rust Main 38.86% <ø> (+0.16%) ⬆️
AuroraView Core ∅ <ø> (∅)
AuroraView Pack ∅ <ø> (∅)
AuroraView CLI ∅ <ø> (∅)
AuroraView Plugins ∅ <ø> (∅)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c4fca0...db0045d. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

wojzj57 and others added 4 commits June 17, 2026 18:24
Capture `handler` as a default arg (`fn=handler`) so each lambda
registered in the loop uses its own value instead of the late-bound
loop variable (ruff B023). Also apply ruff import sorting and a
line-length wrap surfaced by the same lint pass.

Signed-off-by: wojzj57 <wojzj57@gmail.com>
Export set_window_class_null_background in crates/auroraview-core/src/builder/mod.rs to
prevent a dead code warning on non-Windows platforms where its only caller is stubbed out.

Signed-off-by: wojzj57 <wojzj57@gmail.com>
Fixes stale dep update PRs failing CLI Build (Windows) due to the 15-minute timeout.
Rewrap the window_style re-export so each line stays within rustfmt's
width limit, fixing the cargo fmt --check failure on the import block.

Signed-off-by: wojzj57 <wojzj57@gmail.com>
@wojzj57
wojzj57 force-pushed the fix/transparent-window-opaque-background branch from 2bc560b to db0045d Compare June 17, 2026 12:42
@wojzj57
wojzj57 marked this pull request as ready for review June 17, 2026 14:18
@wojzj57
wojzj57 requested a review from loonghao as a code owner June 17, 2026 14:18
@loonghao
loonghao merged commit 1870bdb into loonghao:main Jun 18, 2026
114 checks passed
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.

窗口太过方正

2 participants