Skip to content

fix(v3): report macOS and GTK screens in DIP space (mixed-DPI bounds) - #6346

Merged
leaanthony merged 2 commits into
wailsapp:masterfrom
juggler-ai:fix/screens-in-dip-space
Oct 27, 2026
Merged

leaanthony merged 2 commits into
wailsapp:masterfrom
juggler-ai:fix/screens-in-dip-space

Conversation

@julianstorer

@julianstorer julianstorer commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #5409.

This implements the fix shape recommended in the triage of #5409: an explicit already-DIP input path, so macOS and GTK no longer go through the placement walk that assumes a coherent device-pixel layout.

cScreenToScreen multiplied every NSScreen coordinate, origins included, by that screen's own backingScaleFactor to synthesise the device-pixel input LayoutScreens expects. That fails in two ways, both from the issue's triage:

  • applyDPIScaling rescales sizes, not origins, so a non-primary screen's Bounds.X/Y stay in the scaled space.
  • calculateScreensDipCoordinates (Chromium's screen_win algorithm) needs one coherent device-pixel layout. Scaling each screen's logical origin by its own factor doesn't produce one: displays that abut in logical space stop abutting when their scale factors differ, findAndRemoveTouchingScreens never reaches them, and they keep a doubled origin and a doubled size.

macOS and GTK already report logical coordinates against one shared origin, so a screen's DIP position can be read off rather than rebuilt. Both now feed a new unexported ScreenManager.layoutDIPScreens, which resolves the primary, fills in Size and the Physical* bookkeeping, and positions nothing. Windows reports a coherent device-pixel layout natively and keeps using LayoutScreens. iOS and Android also stay on LayoutScreens: each has a single display at the origin, where both paths agree.

It is a separate method rather than a per-platform constant inside LayoutScreens so that the device-pixel path stays exactly as it is for Windows, and each path's input contract is stated in one place.

Visible effect before the fix: on a mixed-DPI setup, Screen.Bounds/WorkArea for the scaled display described a region no window is ever reported in, so asking which screen a window was on returned none.

On GTK3 this also stops a scaled display from reporting its work-area insets halved (for example a 32px panel reported as 16px). GTK4 has no work-area API, so it is unaffected there.

No public API change.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Windows: no behaviour change (still LayoutScreens); GOOS=windows go vet ./pkg/application/ passes.
  • macOS
  • Linux: the change is one call in screen_linux.go. It has not been run on GTK hardware, and a confirmation from a GTK3 HiDPI user would be welcome.

New pure-Go tests in screenmanager_dip_test.go (no display needed):

  • TestLayoutDIPScreensKeepsMixedDPICoordinates: six mixed-DPI arrangements, including the issue's 2x display above a 1x primary.
  • TestLayoutDIPScreensFindsWindowOnSecondDisplay: a window on the scaled display is found within that display's bounds.
  • TestLayoutDIPScreensCompletesBookkeeping: Size and Physical* fields.
  • TestLayoutDIPScreensRejectsUnusableInput and TestLayoutDIPScreensDropsNilEntries.

go test ./pkg/application/ passes on macOS 27.0.1 (arm64, Go 1.26.3).

Test Configuration

Built from source at master b6167d9 + this commit; macOS 27.0.1 arm64, Go 1.26.3.

Checklist:

  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (none needed)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Fixed display positioning and sizing on macOS and Linux so screen bounds and work areas remain consistent with the coordinates used to measure windows, including across displays with different scaling factors.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between ff6a56b and 72ca78d.

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

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b6167d9 and ff6a56b.

Files selected for processing: 5
  • v3/UNRELEASED_CHANGELOG.md
  • v3/pkg/application/screen_darwin.go
  • v3/pkg/application/screen_linux.go
  • v3/pkg/application/screenmanager.go
  • v3/pkg/application/screenmanager_dip_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

macOS screen bounds and work areas now remain in points, while physical rectangles use the screen scale factor. macOS and GTK pass reported screens to the new DIP layout path, which retains their positions and completes missing physical fields. Tests cover mixed-DPI layouts, screen selection, and input validation.

Changes

DIP screen layout

Layer / File(s) Summary
DIP layout and field completion
v3/pkg/application/screenmanager.go, v3/pkg/application/screenmanager_dip_test.go
layoutDIPScreens retains screen positions, selects the primary screen, and rejects unusable input. It derives missing physical rectangles from DIP values and scale factors. Tests cover mixed-scale layouts, window-to-screen matching, field completion, and invalid inputs.
Platform screen conversion and layout
v3/pkg/application/screen_darwin.go, v3/pkg/application/screen_linux.go, v3/UNRELEASED_CHANGELOG.md
macOS uses point-based bounds for logical geometry and scales physical rectangles. macOS and GTK use layoutDIPScreens. The changelog records the coordinate fix.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: leaanthony

Merge Risk: Minimal · up to ff6a5

No known issue blocks merging. GTK hardware validation remains desirable but does not establish a defect.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reporting macOS and GTK screen bounds in DIP space for mixed-DPI layouts.
Description check Passed The description is complete and relevant. It explains the issue, implementation, affected platforms, testing, test configuration, and checklist status. It also links issue #5409 and notes that GTK har…
Linked Issues check Passed #5409 requires macOS mixed-DPI screen coordinates to remain in the logical coordinate space used by window positioning. The reviewed macOS code keeps Bounds and WorkArea coordinates unscaled, scal…
Out of Scope Changes check Passed The changes remain connected to #5409. The shared layoutDIPScreens method implements the required already-DIP input contract. The GTK call-site change applies the same coordinate-space correction de…
Full details: Description check

Explanation

The description is complete and relevant. It explains the issue, implementation, affected platforms, testing, test configuration, and checklist status. It also links issue #5409 and notes that GTK hardware testing was not performed.

Full details: Linked Issues check

Explanation

#5409 requires macOS mixed-DPI screen coordinates to remain in the logical coordinate space used by window positioning. The reviewed macOS code keeps Bounds and WorkArea coordinates unscaled, scales only Physical* rectangles, and passes enumerated screens to layoutDIPScreens. That method preserves reported DIP positions and fills Size and physical bookkeeping without running the device-pixel placement walk. The added tests cover the reported 1x-primary and 2x-secondary-above arrangement, mixed-DPI coordinates, and finding a window on the second display.

Full details: Out of Scope Changes check

Explanation

The changes remain connected to #5409. The shared layoutDIPScreens method implements the required already-DIP input contract. The GTK call-site change applies the same coordinate-space correction described by the PR. The tests verify the shared behavior, and the changelog records the fix. Windows, iOS, and Android retain their existing LayoutScreens paths.

Full details: Docstring Coverage

Explanation

Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the screens at night,
Each keeps its bounds in points just right.
The scaled rectangles join the show,
Across mixed displays, positions flow.
Then carrots mark the tests as green.

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

@github-actions github-actions Bot added Documentation Improvements or additions to documentation MacOS Linux labels Oct 25, 2026
…ured in

cScreenToScreen multiplied every NSScreen coordinate, origins included, by
that screen's own backingScaleFactor, to synthesise the device-pixel input
LayoutScreens expects and have applyDPIScaling divide it back out again.
applyDPIScaling rescales sizes, not origins, so a non-primary screen's
Bounds.X/Y were left in the scaled space (wailsapp#5409).

A second fault sits behind that one. calculateScreensDipCoordinates is
Chromium's screen_win algorithm, whose input contract is a single coherent
device-pixel layout. Multiplying each screen's logical origin by its own
scale factor does not produce one: displays that abut exactly in logical
space stop abutting as soon as their scale factors differ, so
findAndRemoveTouchingScreens never reaches the screen, no placement is
applied to it and applyDPIScaling never runs on it at all. A 2x display
beside a 1x primary therefore kept both a doubled origin and a doubled size.

Windows reports a coherent device-pixel layout natively and continues to use
LayoutScreens. macOS and GTK report logical coordinates against one shared
origin, where a screen's DIP position can be read off rather than rebuilt,
so both now feed layoutDIPScreens: it resolves the primary, completes the
Size and Physical* bookkeeping, and positions nothing. On GTK3 this also
stops a scaled display from reporting its work-area insets halved.

The visible effect was that Screen.Bounds and Screen.WorkArea for such a
display described a region no window is ever reported in. Code asking which
screen a window occupied was told it occupied none of them, and an
application that acts on that answer — moving a window it believes has been
left off-screen — would haul every window on that display back to the
primary.

iOS and Android also report logical coordinates, but each has a single
display at the origin, where both paths agree; they are left on
LayoutScreens.
@julianstorer
julianstorer force-pushed the fix/screens-in-dip-space branch from ff6a56b to 72ca78d Compare October 26, 2026 13:59
@leaanthony

Copy link
Copy Markdown
Member

Thanks! These are tricky ones!

@leaanthony
leaanthony merged commit 59802f8 into wailsapp:master Oct 27, 2026
15 of 16 checks passed
leaanthony pushed a commit that referenced this pull request Oct 27, 2026
… and GTK screens in DIP space (mixed-DPI bounds)
@julianstorer
julianstorer deleted the fix/screens-in-dip-space branch November 3, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation Linux MacOS v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3, macOS] Screen.Bounds.X/Y on non-primary screens are off by the screen's scale factor (mixed-DPI)

2 participants