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

getPosition and setPosition don't work correctly on Windows with multiple scaled screens #474

Open
ToH2002 opened this issue Jul 27, 2024 · 0 comments

Comments

@ToH2002
Copy link

ToH2002 commented Jul 27, 2024

When using window_manager with a configuration with multiple screens in a Windows environment, the values from getPosition diverge massively from the ones reported by Windows directly.

Example:

  • main screen is 3840x2160, set to scale 125%
  • second screen (to the right) is 1920x1080, scale 175%

Putting a window on the second screen, Windows reports a horizontal position of 3120, which (taking into account the 1.25 scaling of the first screen) is perfectly fine to identify as being on the second screen. The physical position in unscaled pixels (x*1.25) is 3900, so finding the correct window is easy.

window_manager reports a horizontal position of 2242 - which suggests that the window sits fully on the first screen. There is no way to find out from window_manager's getPosition data that the window is actually on the second screen. It looks like window_manager uses the scale of the second screen to divide the pixel position, but even that doesn't fully work out (3900 / 1.75 would be 2228)

TL/DR: getPosition is broken when using multiple screens with different scaling!

Second issue is around setPosition:

When using the value I get from getPosition with the setPosition function, scaling strikes again:

  • window_manager uses the scale of the screen the window is currently on to calculate the actual position. So there is no predictable way to get a window to a specific position on multiple screens. Where setPosition() moves the window always depends on where it is currently. I can work around this by always using setPosition(0,0) first, but that's really a mess.

Also, of course, since the original position received by getPosition may be incorrect, I have no correct position to set the window to.

I could work around some of the problems by translating the incorrect values to something that setPosition can deal with, but if the values provided by getPosition don't even let my reliably find out what screen the window is currently on, such a correction function will only work correctly for some specific situation, and not at all in others (if two windows on different screens report the same x coordinate, there's no way I can correct for that - mathematics will just not allow it...).

I truly hope that this can be addressed - ideally, I could trust the position reported by getPosition so that simply using setPosition with that value puts the window to where it was before. This is essential for any app storing its window position on exit and restoring on start. Currently, this is pretty much unusable, unless all monitors use the same scaling (which is not always the case, especially with small "side screens".

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

No branches or pull requests

1 participant