Skip to content

fix(tauri): use CSS pixels for embedded window rect - #527

Open
Clarkkkk wants to merge 1 commit into
webdriverio:mainfrom
Clarkkkk:codex/fix-tauri-window-rect-hidpi
Open

fix(tauri): use CSS pixels for embedded window rect#527
Clarkkkk wants to merge 1 commit into
webdriverio:mainfrom
Clarkkkk:codex/fix-tauri-window-rect-hidpi

Conversation

@Clarkkkk

@Clarkkkk Clarkkkk commented Jul 14, 2026

Copy link
Copy Markdown

Description

Fixes the embedded Tauri WebDriver server's desktop Get Window Rect and Set Window Rect implementation so the W3C values are expressed in CSS/logical pixels instead of Tauri physical pixels.

On a Retina display, the existing implementation returned and accepted physical dimensions. A Tauri window reported by WebDriver as 1320x860 at DPR 2 therefore exposed only a 660x430 DOM viewport, and setting a WebDriver size could shrink the application to half of the requested logical size.

This change:

  • converts Tauri physical outer position and size through to_logical() using the current window scale factor;
  • uses LogicalPosition and LogicalSize when applying WebDriver rects;
  • measures the window decoration in logical pixels before a possible display move, avoiding stale physical metrics being combined with a new display scale factor;
  • waits for Tauri's tauri://move and tauri://resize events instead of relying on fixed delays, and reports a WebDriver unknown error if a native operation fails or times out;
  • applies position before size when both are requested and skips native setters whose requested value is unchanged;
  • documents the CSS-pixel contract without changing the endpoint or public response shape.

The behavior follows the W3C Set Window Rect command and Tauri's PhysicalSize::to_logical API.

Regression evidence

The embedded E2E was first run against the previous implementation. It failed while the existing window tests passed:

should return the native outer rect in logical pixels
Received difference: 2492px

should set the outer size in logical pixels without shrinking the viewport
Received difference: 360px

With the fix, the same Retina run observed a 720x540 WebDriver rect backed by 1440x1080 physical bounds at scale factor 2. The DOM viewport changed by the same logical delta, and all 14 window tests passed.

Related Issues

None.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code style/refactoring (no functional changes)
  • Internal/tooling change (build scripts, CI, etc.)
  • Performance improvement

Scope

  • scope:electron - Electron service and CDP bridge
  • scope:tauri - Tauri service and plugin

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project (passes pnpm lint)
  • I have added tests that prove my fix is effective
  • All new and existing tests pass (pnpm test)
  • I have updated the documentation
  • My changes generate no new TypeScript errors (pnpm typecheck)

A direct root pnpm test is not a CI-equivalent entry point on macOS: it bypasses test-package.ts, selects the official Tauri driver fixture, and fails because that provider is unsupported on macOS. The CI-equivalent unit/integration suite, repository pre-push package suite, and the relevant native E2E all pass locally. CI remains responsible for the fully provisioned cross-platform fixture and provider matrix.

Testing

  • Unit tests added/updated
  • Integration tests added/updated (not applicable)
  • E2E tests added/updated
  • Manually tested on: macOS arm64, Retina scale factor 2

Passed locally:

  • cargo test (17 passed)
  • rustfmt --edition 2021 --check src/platform/executor.rs
  • cargo clippy --all-targets -- -D warnings -A clippy::incompatible-msrv
  • pnpm exec turbo run build --filter='./fixtures/package-tests/*' (27 successful)
  • pnpm run test:unit test:integration --only --concurrency=1 (19 successful)
  • pnpm run test:coverage --concurrency=1 (29 successful)
  • TAURI_WEBDRIVER_PORT=4545 pnpm --filter @repo/e2e test:e2e:tauri-basic-embedded:window (14 passing)
  • pnpm format:check
  • pnpm lint
  • pnpm typecheck (28 successful)
  • repository pre-push package suite (26 successful)

Two strict Rust checks expose unrelated current-main/toolchain issues:

  • cargo fmt --check with rustfmt 1.96 reports formatting drift only in untouched Rust files; the modified Rust file passes a direct rustfmt check.
  • cargo clippy --all-targets -- -D warnings with Rust 1.96 reports existing clippy::incompatible_msrv warnings for cast_unsigned / cast_signed because the crate declares MSRV 1.77; allowing only that lint produces a clean clippy run.

Screenshots/Videos

Not applicable; the regression is asserted against WebDriver rects, DOM viewport dimensions, and native Tauri physical bounds.

Additional Context

This changes desktop behavior on macOS, Windows, and Linux because all three platforms share the same cfg(desktop) implementation. Mobile implementations and public endpoint shapes are unchanged. Clients that relied on the non-standard physical-pixel values will now receive W3C CSS-pixel values.

A genuine mixed-DPI multi-display transition was not available for manual testing. Scale factors 1.0, 1.25, and 2.0, negative positions, integer rounding, decoration conversion, combined move/resize, and size-only updates are covered by deterministic Rust tests and the native embedded E2E; CI provides the remaining platform matrix.


Note: This repository does not backport changes to older versions. All changes target the current main branch.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 14, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Clarkkkk / name: Aaron_Zhou (b2c9cbf)

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR corrects the embedded Tauri WebDriver Get Window Rect and Set Window Rect implementation to report and accept W3C CSS (logical) pixels instead of raw Tauri physical pixels. On Retina/HiDPI displays the previous code returned physical dimensions, making the window appear at half the expected size to WebDriver clients.

  • get_window_rect now reads scale_factor and converts outer_position()/outer_size() with to_logical() before returning.
  • set_window_rect captures window-chrome dimensions in logical pixels before any display move, then applies position first (waiting for tauri://move) and size second (waiting for tauri://resize), replacing the previous tokio::time::sleep approach with event-driven confirmation.
  • Three new E2E tests and two deterministic Rust unit tests verify the conversion at scale factors 1.0, 1.25, and 2.0, plus the viewport-delta assertion that proves chrome subtraction is correct.

Confidence Score: 5/5

Safe to merge — the change corrects a well-defined physical-to-logical pixel conversion bug and replaces error-prone fixed sleeps with event-driven waiting, all backed by deterministic unit tests and a native E2E run on Retina hardware.

All four changed files have a clear, focused purpose: the Rust executor correctly reads scale factor, converts coordinates before any display move, and waits for native window events instead of sleeping. Error paths that previously swallowed failures now propagate them. The unit tests cover scale factors 1.0, 1.25, and 2.0 with rounding edge cases, and the E2E tests verify both the physical-to-logical mapping and the viewport-delta invariant. No logic errors, data-loss paths, or security concerns were identified.

No files require special attention.

Important Files Changed

Filename Overview
packages/tauri-plugin-webdriver/src/platform/executor.rs Core fix: get_window_rect and set_window_rect now convert Tauri physical coordinates to CSS logical pixels using the window's scale factor; chrome decoration is captured before any display move; fixed-delay sleeps replaced with tauri://move/tauri://resize event waits; errors are properly propagated instead of silently swallowed.
e2e/test/tauri/window.spec.ts New 'Embedded WebDriver WindowRect CSS pixel semantics' describe block adds three E2E tests that validate the native outer rect in logical pixels, combined move+resize, and size-only change without viewport shrinkage; tests are gated on DRIVER_PROVIDER === 'embedded' and properly restore state in finally blocks.
fixtures/e2e-apps/tauri/src-tauri/src/main.rs Added WindowMetrics struct (with scale_factor) replacing WindowBounds; get_window_bounds Tauri command now also returns the display scale factor so E2E tests can independently verify the physical-to-logical conversion.
packages/tauri-plugin-webdriver/README.md Added a short prose note documenting that Get Window Rect / Set Window Rect operate in CSS pixels and that position changes complete before size is applied.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant WD as WebDriver Client
    participant EX as PlatformExecutor
    participant TW as Tauri Window
    participant OS as OS / Window Manager

    WD->>EX: Set Window Rect (x, y, w, h) [CSS px]
    EX->>TW: is_fullscreen() / is_maximized()
    alt fullscreen or maximized
        EX->>TW: set_fullscreen(false) / unmaximize()
        OS-->>TW: tauri://resize event
        TW-->>EX: event received
    end
    EX->>TW: scale_factor(), outer_position(), outer_size(), inner_size()
    TW-->>EX: physical metrics
    EX->>EX: physical_window_rect_to_logical → current_rect (logical)
    EX->>EX: physical_window_chrome_to_logical → chrome_size (logical)
    alt position changed
        EX->>TW: "set_position(LogicalPosition{x, y})"
        OS-->>TW: tauri://move event
        TW-->>EX: event received
    end
    alt size changed
        EX->>TW: "set_size(LogicalSize{w - chrome_w, h - chrome_h})"
        OS-->>TW: tauri://resize event
        TW-->>EX: event received
    end
    EX->>TW: outer_position(), outer_size(), scale_factor()
    TW-->>EX: updated physical metrics
    EX->>EX: physical_window_rect_to_logical → final rect (logical)
    EX-->>WD: WindowRect (CSS px)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant WD as WebDriver Client
    participant EX as PlatformExecutor
    participant TW as Tauri Window
    participant OS as OS / Window Manager

    WD->>EX: Set Window Rect (x, y, w, h) [CSS px]
    EX->>TW: is_fullscreen() / is_maximized()
    alt fullscreen or maximized
        EX->>TW: set_fullscreen(false) / unmaximize()
        OS-->>TW: tauri://resize event
        TW-->>EX: event received
    end
    EX->>TW: scale_factor(), outer_position(), outer_size(), inner_size()
    TW-->>EX: physical metrics
    EX->>EX: physical_window_rect_to_logical → current_rect (logical)
    EX->>EX: physical_window_chrome_to_logical → chrome_size (logical)
    alt position changed
        EX->>TW: "set_position(LogicalPosition{x, y})"
        OS-->>TW: tauri://move event
        TW-->>EX: event received
    end
    alt size changed
        EX->>TW: "set_size(LogicalSize{w - chrome_w, h - chrome_h})"
        OS-->>TW: tauri://resize event
        TW-->>EX: event received
    end
    EX->>TW: outer_position(), outer_size(), scale_factor()
    TW-->>EX: updated physical metrics
    EX->>EX: physical_window_rect_to_logical → final rect (logical)
    EX-->>WD: WindowRect (CSS px)
Loading

Reviews (2): Last reviewed commit: "fix(tauri): use CSS pixels for embedded ..." | Re-trigger Greptile

Comment thread packages/tauri-plugin-webdriver/src/platform/executor.rs
Comment thread e2e/test/tauri/window.spec.ts Outdated
@Clarkkkk
Clarkkkk marked this pull request as draft July 14, 2026 06:13
@Clarkkkk
Clarkkkk force-pushed the codex/fix-tauri-window-rect-hidpi branch from 2d68e18 to b2c9cbf Compare July 14, 2026 08:07
@Clarkkkk
Clarkkkk marked this pull request as ready for review July 14, 2026 08:09
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