fix(cua-driver-rs/windows): screenshot screen-region fallback for XAML/UWP targets (partial CUA-542) - #1599
Conversation
…tBlt for XAML/UWP targets
Partial fix for CUA-542 — `PrintWindow` doesn't capture
DirectComposition-backed surfaces (modern UWP / WinUI3 apps render
directly to the compositor, no GDI back buffer). For known XAML host
targets (detected via the existing `input::is_xaml_host_hwnd`
predicate), the screenshot tool now skips PrintWindow and copies the
window's on-screen bounds from the desktop DC. Mirrors the screen-
capture approach the Windows Snipping Tool uses for its "Window" mode.
Coverage:
- Visible-at-real-size UWP / WinUI3 apps (Edge, Photos with content
open, Settings, modern Notepad when foreground) — fixed. Their
GetWindowRect returns real bounds and the desktop DC has their
composited pixels.
- Legacy Win32 apps — unchanged, still PrintWindow.
- Background-collapsed UWP (notably Windows 11 Calculator launched
via SW_SHOWNOACTIVATE) — NOT fixed. Calculator's top-level window
persists at 120×30 px at (0, 1) even after SetWindowPos +
ShowWindow(SW_RESTORE) + SetForegroundWindow attempts; the real
Calculator UI is hosted in a child CoreWindow managed by the
compositor with no addressable HWND. Capturing this case requires
Windows.Graphics.Capture against the CoreWindow's GraphicsCapture-
Item — left tracked on CUA-542 as the proper followup.
Implementation notes:
- `is_xaml_host_hwnd` is the predicate from PR #1597 — checks top-
level window class against a list and falls back to the owning
.exe basename. Verified live via `debug_window_info` (which also
shipped in #1597) that Calculator's `xaml_class_match: true` and
`xaml_routing_recommended: true` predicates fire.
- `screenshot_via_screen_region` opens NULL-HWND desktop DC, BitBlts
from screen coordinates returned by `GetWindowRect`, then
GetDIBits to BGRA buffer. Same encode path as the PrintWindow
success branch.
- The mostly-black sentinel heuristic (`is_mostly_black_bgra`) is
kept as a safety net for the rare legacy-Win32-app-using-D3D
case, but the primary trigger is now the XAML host predicate.
Tested live on the Windows VM:
- Foreground Calculator window (forced via SetForegroundWindow):
still 120×30 due to Calculator's compositor-managed UI; no improvement
visible in this specific case. Limitation documented above.
- Build clean; no regression on the legacy Win32 capture path.
Closes part of CUA-542 (the visible-UWP case). The Calculator-style
case is reopened on the same ticket; WGC implementation is the proper
followup and is well-scoped from the work in this PR.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR addresses CUA-542 by adding a screen-region BitBlt fallback to the Windows screenshot capture function, activated when PrintWindow fails on UWP/DirectComposition surfaces. A mostly-black detection heuristic identifies failed renders, and the fallback is routed for known XAML-host HWNDs or triggered post-capture when black pixels are detected. ChangesCUA-542 fallback capture for DirectComposition surfaces
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Summary
Partial fix for CUA-542. For XAML / WinUI3 / UWP targets (detected via the existing `input::is_xaml_host_hwnd` predicate from #1597), the screenshot tool now skips PrintWindow and copies the window's on-screen bounds from the desktop DC — same approach the Windows Snipping Tool uses for its "Window" mode.
Coverage
The Calculator case requires `Windows.Graphics.Capture` against the `GraphicsCaptureItem` for the CoreWindow — that's the proper follow-up, left tracked on CUA-542 (description updated separately).
What's in it
Net diff: 160 insertions / 2 deletions in `capture.rs` only. No new dependencies; uses the same `windows` crate features already enabled.
Verification on the Windows VM
Notes
This is the first of three remaining Windows tickets I've been working through on the VM (after kill_app + type_text routing landed today as #1596 and #1597). The other two (CUA-543 hotkey, CUA-544 UIA tree) are still open.
🤖 Generated with Claude Code
Summary by CodeRabbit