Skip to content

fix(cua-driver): add DPI awareness manifest for Windows - #1821

Merged
ddupont808 merged 9 commits into
mainfrom
fix/windows-dpi-awareness
Jun 5, 2026
Merged

fix(cua-driver): add DPI awareness manifest for Windows#1821
ddupont808 merged 9 commits into
mainfrom
fix/windows-dpi-awareness

Conversation

@ddupont808

@ddupont808 ddupont808 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds DPI awareness manifest to cua-driver.exe on Windows
  • Fixes coordinate offset bug when using 125%/150%/200% display scaling

Problem

Users reported that x/y coordinates were offset when running cua-driver-rs on Windows with 125% display scaling. This happened because Windows treats processes without a DPI manifest as DPI-unaware and provides physical pixels instead of logical pixels.

Without the manifest:

  • At 125% scaling, clicking logical (100, 100) would land at physical (125, 125)
  • Screenshot coordinates wouldn't match click coordinates
  • The cua-driver-uia.exe worker had the manifest, but the main daemon didn't

Solution

Added a Windows application manifest declaring Per-Monitor V2 DPI awareness (matching cua-driver-uia.exe). This ensures:

  • Windows provides logical coordinates (what the user sees)
  • Coordinates match screenshot pixel positions
  • No scaling mismatch between daemon and worker

The manifest is embedded at build time via embed-resource crate (Windows-only build dependency).

Test plan

  • Build on Windows with 125% scaling
  • Verify clicks land at correct positions
  • Verify no regression on 100% scaling
  • Confirm build still succeeds on macOS/Linux (manifest is Windows-only)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Integrated DPI-awareness configuration into the Windows driver build process, enabling proper display scaling and rendering on high-resolution monitors.

Fixes coordinate offset when using 125%/150%/200% display scaling on
Windows. Without the manifest, Windows treats the process as DPI-unaware
and provides physical pixels instead of logical pixels, causing clicks
to land at the wrong position.

The manifest declares Per-Monitor V2 DPI awareness (same as cua-driver-uia),
ensuring the process receives logical coordinates that match what the user
sees on screen and what screenshot coordinates represent.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Jun 5, 2026 1:31am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 297677ea-6afe-4fd8-8f93-d4ed2b2db19d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds Windows DPI awareness support to the cua-driver crate by introducing a Windows application manifest, declaring the embed-resource build dependency, and configuring the build script to embed the manifest at compile time.

Changes

Windows DPI Awareness Setup

Layer / File(s) Summary
Manifest, build dependency, and embedding
libs/cua-driver/rust/crates/cua-driver/cua-driver.manifest, libs/cua-driver/rust/crates/cua-driver/Cargo.toml, libs/cua-driver/rust/crates/cua-driver/build.rs
New cua-driver.manifest defines Windows DPI-awareness settings for the com.trycua.driver assembly with asInvoker execution level and both legacy and per-monitor V2 DPI awareness. Cargo.toml declares the embed-resource = "2" build dependency. build.rs adds Windows-specific logic to compile and embed the manifest using embed_resource::compile.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A manifest bright for Windows to see,
DPI awareness, crisp and free!
Embed the resource, build it with care,
High-res displays treated fair and square.
Rust and resources, a bunny's delight! 🪟✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a DPI awareness manifest for Windows to the cua-driver crate. It is concise, specific, and clearly reflects the primary objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/windows-dpi-awareness

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/cua-driver/rust/crates/cua-driver/build.rs`:
- Line 16: The build script currently calls
embed_resource::compile("cua-driver.manifest", ...) which is wrong because
embed_resource::compile expects a Windows .rc resource script, not a raw
.manifest; create a resource script named cua-driver.rc containing the
RT_MANIFEST definition and reference to the XML manifest (e.g., "`#define`
RT_MANIFEST 24" and "1 RT_MANIFEST \"cua-driver.manifest\""), then update the
call to embed_resource::compile("cua-driver.rc", embed_resource::NONE) so the
manifest is embedded correctly by the embed_resource::compile function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 406ee2f2-642b-4c02-b60b-bddcdd5a641c

📥 Commits

Reviewing files that changed from the base of the PR and between 02fdd98 and 61d3ef2.

📒 Files selected for processing (3)
  • libs/cua-driver/rust/crates/cua-driver/Cargo.toml
  • libs/cua-driver/rust/crates/cua-driver/build.rs
  • libs/cua-driver/rust/crates/cua-driver/cua-driver.manifest

Comment thread libs/cua-driver/rust/crates/cua-driver/build.rs Outdated
embed_resource::compile() expects a Windows resource script (.rc) that
references the manifest via RT_MANIFEST, not the raw .manifest XML file.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
ddupont808 added a commit that referenced this pull request Jun 4, 2026
Add high-DPI awareness support for Windows, enabling proper coordinate
scaling and display clarity on high-resolution displays.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
ddupont808 and others added 7 commits June 4, 2026 18:12
Fix critical bugs where logical and physical pixel coordinates were
mismatched after adding DPI awareness manifest.

**Fixes:**
1. screenshot_display_bytes: Scale logical GetSystemMetrics dimensions
   to physical pixels before BitBlt capture
2. screenshot_via_screen_region: Scale GetWindowRect logical coords to
   physical pixels for screen DC BitBlt
3. screenshot_window_bytes (occlusion path): Scale window dimensions
   to physical pixels for bitmap creation
4. get_screen_size: Update comments - GetSystemMetrics already returns
   logical pixels with permonitorv2, no double-scaling needed

With permonitorv2 DPI awareness:
- GetSystemMetrics/GetWindowRect return logical pixels (DPI-scaled)
- BitBlt/CreateCompatibleBitmap work in physical device pixels
- Conversion: physical = logical × (DPI / 96.0)

These fixes ensure screenshots and coordinates work correctly at any
DPI scaling (125%, 150%, 200%).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
CI provided hash: sha256-1/dcdzoK8PC1ns1WyJY+QmWRMj7GKOXUpRO9zTPDbl4=
The embed-resource build dependency should only be included on Windows
builds to avoid vendoring issues on Linux Nix builds.
CI provided hash: sha256-TezobhZKan2E087x8cECCqZS0lafEBAOd0Cx70BgP9w=
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.

1 participant