Skip to content

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

@leaanthony

Description

@leaanthony

Description

In pkg/application/screen_darwin.go, cScreenToScreen multiplies screen.x and screen.y by the screen's own backingScaleFactor before assigning them to Bounds.X / Bounds.Y:

sf := float64(screen.scaleFactor)
toPhysical := func(points C.int) int { return int(float64(points) * sf) }

return &Screen{
    X: toPhysical(screen.x),
    Y: toPhysical(screen.y),
    Bounds: Rect{
        X: toPhysical(screen.x),
        Y: toPhysical(screen.y),
        ...
    },
    ...
}

The intent (per the code comment) is a round-trip workaround for applyDPIScaling in screenmanager.go, which divides Bounds.Width / Bounds.Height by the scale factor. But Bounds.X / Bounds.Y are not divided again in applyDPIScaling — they're left in points × ownScaleFactor space, while Bounds.Width / Bounds.Height end up in logical points.

After #5304 + the GetScreens normalization, Position() / SetPosition() are in logical points across screens. So on mixed-DPI setups (e.g., a Retina secondary above a 1x primary), SetPosition(s.Bounds.X, s.Bounds.Y) for a non-primary screen lands at the wrong location by a factor of that screen's ScaleFactor.

Steps to Reproduce

  1. Primary monitor: 1x (non-Retina).
  2. Secondary monitor: 2x Retina, positioned above the primary in macOS Displays settings.
  3. Read secondary.Bounds.Y from GetScreens().
  4. Call SetPosition(secondary.Bounds.X, secondary.Bounds.Y).
  5. Window does not land at the top-left of the secondary; it's off by secondary.ScaleFactor.

The same ScaleFactor doubling exists today but only becomes user-visible once Position/SetPosition are normalized to logical points (which is the goal of #5117 / #5304).

Notes

Environment

  • Wails v3 (pkg/application/screen_darwin.go, pkg/application/screenmanager.go)
  • macOS, mixed-DPI multi-monitor

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingMacOSP2Medium priorityinvestigatingThe bug is being investigatedv3

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions