Skip to content

HiDPI macOS, mouse position is in physical pixels whereas windows creation happens in logical pixels #337

@golddranks

Description

@golddranks

I'm using macOS with a HiDPI display, with the scale factor of 2.0.

There is an unfortunate mismatch in the API where the input mouse events are reported in physical pixels (they are scaled according to the scale factor reported by the window), whereas the window creation API naively requests a window of the size of the input values, without specifying the scale factor. A window of those logical pixel dimensions is created, but the physical pixels are double of that.

This leads the user of the library having to scale the mouse values down, or window dimensions up by themselves – and possibly fail to do that, if they are developing with scale factor of 1.0 and don't notice the problem.

Besides, the library documentation speaks mostly of "pixels", but "points" are mentioned too in a few APIs. I guess that the distinction refers to physical and logical pixels, but a explanation of those would be warranted in the documentation itself. (Note: please correct me if I'm wrong! Also, I'd be interested to know how if the distinction was actually considered when writing the docs – do the docs actually reflect some intention of separating those, or was pixel meant to be used as a general term referring both?)

I want to help with the current situation (at least for the macOS implementations), but I'm unaware what plans @tomaka has for the API.

Should a WindowBuilder.with_dimensions(800, 600) create a window of those logical dimensions? In that case, the docs should be changed to refer points, and methods should be added to get the scale factor. Or if with_dimensions was meant to create a window of those physical pixel dimensions, the implementation itself should be fixed, since at the moment it doesn't do that.

I'm going to send PRs once I get input from @tomaka what was the intention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C - in progressImplementation is proceeding smoothlyDS - appkitAffects the AppKit/macOS backend

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions