Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Incorrect mouse position likely due to high DPI display #1241

Closed
Sogomn opened this issue Dec 10, 2018 · 16 comments · Fixed by #1246
Closed

Incorrect mouse position likely due to high DPI display #1241

Sogomn opened this issue Dec 10, 2018 · 16 comments · Fixed by #1246

Comments

@Sogomn
Copy link
Contributor

Sogomn commented Dec 10, 2018

InputHandler::mouse_position seems to return incorrect values on displays with high DPI.

image

The "Screen" size in the image is the window size. Top left of the window is still (0, 0) but the mouse position can be greater than the window bounds without leaving the window.

Occurs on a 3840x2160 28" (~157 DPI) monitor but only recently (since 0.10).

@AnneKitsune
Copy link
Contributor

Thats my bad haha. Normally, screen size should be the physical pixel size. Are you getting this value from ScreenDimensions?

@ghost
Copy link

ghost commented Dec 10, 2018

I can actually confirm this as well. My mouse gets higher values than what the ScreenDimensions resource provides.

I assume the problem lies in the resource and not the input.

@Sogomn
Copy link
Contributor Author

Sogomn commented Dec 10, 2018

Yeah the window size came from ScreenDimensions.

@AnneKitsune
Copy link
Contributor

AnneKitsune commented Dec 11, 2018

I actually tested this and it was working just fine on my hidpi setup when we released.

@azriel91
Copy link
Member

Not sure if relevant, but may be.
On my Ubuntu 16.04 laptop that is running Gnome 3.28 on X, the ui example draws a black window for the 0.10 release. That laptop has a 1.3333 hidpi factor. I did try setting it to 1.0 using WINIT_HIDPI_FACTOR=1.0, but it didn't do anything.

@Sogomn
Copy link
Contributor Author

Sogomn commented Dec 11, 2018

The screen dimensions are correct for me tho. They are the values I have in my display.ron.

@ghost
Copy link

ghost commented Dec 11, 2018

Mine aren't due to Wayland (unless that's the problem). The problem of mine happens in fullscreen so there is no border and i guess the dimesnions should be the same as the screen resolution.

@Sogomn
Copy link
Contributor Author

Sogomn commented Dec 12, 2018

Did some more testing on a different device and it here it seems the window size isn't accurate. It's set to 1280x720 in the display.ron but the window fills the entire screen (1920x1080). 96 DPI monitor.
So I think ScreenDimensions returns the correct size the window is supposed to have but the actual window size is wrong?

@AnneKitsune
Copy link
Contributor

We are using the physical size returned by winit instead of converting it to logical size like before. On a 4k monitor with a dpi setting making my resolution 1080p, making the window fullscreen would return the 4k screen size, which was the intended result. Tested on wayland and xorg. We got people that tested it on both windows and mac too. Its possible that when creating the window it is the wrong size, as I might have forgot to update the init code for the window. Is this what you are observing?

@AnneKitsune
Copy link
Contributor

AnneKitsune commented Dec 12, 2018

The dpi setting is in ScreenDimensions by the way, if you can check what the value is.

@Sogomn
Copy link
Contributor Author

Sogomn commented Dec 12, 2018

Ah, I see. So is there a way to either get the logical mouse position or the physical window size (without multiplying it by the HDPI factor)?

@AnneKitsune
Copy link
Contributor

Normally you should be getting the physical mouse position as well as the physical window size. I'll test on my laptop(hidpi) to make sure the results are valid.

@AnneKitsune
Copy link
Contributor

Okay its clearly broken again for some reason...

@AnneKitsune
Copy link
Contributor

Hello, can you test this and confirm if it works for you? Thanks! #1246

@Sogomn
Copy link
Contributor Author

Sogomn commented Dec 12, 2018

Yes, it does!

bors bot added a commit that referenced this issue Dec 13, 2018
1243: Removed unnecessary code. r=Xaeroxe,jojolepro ,TimonPost a=TimonPost

Removed some unnecessary code. 

1246: Fix reported ScreenDimension and wrong DisplayConfig sizes. r=happenslol,azriel91,udoprog a=jojolepro

fixes #1241


1248: Add example Ron configs to docs r=Xaeroxe ,LucioFranco ,jojolepro udoprog ,azriel91 a=Sogomn



Co-authored-by: Timon <timonpost@hotmail.nl>
Co-authored-by: Joël Lupien (Jojolepro) <jojolepromain@gmail.com>
Co-authored-by: Johannes Boczek <johannes.boczek@web.de>
@bors bors bot closed this as completed in #1246 Dec 13, 2018
@yancouto
Copy link
Contributor

Hello!

I think I've been hitting exactly this same issue. When using my large monitor, I see this in the logs:

Guessed window DPI factor: 1.25

And then the mouse position gets "out of sync" with the actual position on the screen by exactly this factor.

So I have a question: is the DPI scaling supposed to be transparent to us users when acessing mouse positions?

  • If so, then this is probably a bug that needs fixing.
  • If not, then how do I track the current DPI? (In order to take that into account.) I see WindowEvent::HiDpiFactorChanged when reading this, and tried handling that event in my game state, but it does not show up. What is the correct way of tracking DPI?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants