Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
golddranks opened this issue Nov 1, 2017 · 12 comments · Fixed by #548
Labels
C - in progress Implementation is proceeding smoothly DS - macos
Milestone

Comments

@golddranks
Copy link

golddranks commented Nov 1, 2017

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.

@golddranks golddranks changed the title HiDPI macOS, mouse position in in physical pixels whereas windows creation happens in logical pixels HiDPI macOS, mouse position is in physical pixels whereas windows creation happens in logical pixels Nov 3, 2017
@kryptan
Copy link
Contributor

kryptan commented Nov 3, 2017

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?

You might be interested in discussion in #105. I proposed to use physical pixels everywhere.

methods should be added to get the scale factor.

There are Window::hidpi_factor() and MonitorId::get_hidpi_factor() methods to get scale factor of the window and monitor but the one for monitor is currently not implemented for macOS.

@golddranks
Copy link
Author

Thanks for the pointer. It seems that there is a push for being HiDPI aware by default, with #319 merged and all. That means that one should expect the window creation api to create windows based on physical pixels, right?

@kryptan
Copy link
Contributor

kryptan commented Nov 5, 2017

Yes, that's the current intention.

@golddranks
Copy link
Author

However, because HiDPI-aware windows are meant to adapt to different resolutions when moved to different monitors, the "meant to be" physical pixel dimensions are device-dependent. That means that the window creation API should be reflect that. At the moment it doesn't take in the device the window is going to be drawn on.

@francesca64
Copy link
Member

@sodiumjoe window creation on macOS uses physical pixels now, right?

@sodiumjoe
Copy link
Contributor

@francesca64 I believe that's the case as of #435

@francesca64 francesca64 added this to the HiDPI Support milestone May 6, 2018
@francesca64
Copy link
Member

@sodiumjoe that looks like it only affects the size methods though? macOS HiDPI is something I can't test, since it doesn't seem to want to cooperate with my 1440p monitor.

@sodiumjoe
Copy link
Contributor

@francesca64 sorry about the late reply. It looks to me like it's still using logical pixels.

The following:

    let _window = winit::WindowBuilder::new()
        .with_title("A fantastic window!")
        .with_dimensions(1440, 900)
        .build(&events_loop)
        .unwrap();

produces a window that fills the screen of my retina 13" macbook pro, which has a native resolution of 2560x1600, but is scaled to 1440x900.

I'm a little confused by logical vs physical, esp. with the default scaling on this machine.

@francesca64
Copy link
Member

I'm a little confused by logical vs physical, esp. with the default scaling on this machine.

It's taken me surprisingly long to understand the intentions prescribed in #105, but the gist seems to be that window creation should give you a render surface with that many physical pixels, and that no part of the API should produce or consume logical pixels. This way, handling non-1.0 DPI factors is purely "opt-in".

@francesca64
Copy link
Member

Okay I seem to have been wrong about that: #105 (comment)

@francesca64
Copy link
Member

I convinced macOS to set one of my monitors to (very low resolution) HiDPI, so I'll be able to take care of this.

@francesca64
Copy link
Member

I've confirmed that this issue is still relevant. It will be resolved as part of the API changes that will result from #105.

@francesca64 francesca64 added the C - in progress Implementation is proceeding smoothly label May 15, 2018
tmfink pushed a commit to tmfink/winit that referenced this issue Jan 5, 2022
Associate texture parameters in shaders with specific texture units, to work around a macOS Radeon driver bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - in progress Implementation is proceeding smoothly DS - macos
Development

Successfully merging a pull request may close this issue.

4 participants