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

WindowStartupLocation DPI-awareness #1979

Closed
wants to merge 7 commits into from
Closed

WindowStartupLocation DPI-awareness #1979

wants to merge 7 commits into from

Conversation

OronDF343
Copy link
Contributor

Fixes #1961

Window.SetWindowStartupLocation() will now respect the display scaling when positioning the window. I am using ITopLevelImpl.Scaling to do this.

CenterScreen works for me at 150% on desktop Win 7. CenterOwner should also work in theory - only limited testing was done as I have no more time to work on this today. The code is pretty simple anyways.

if (WindowStartupLocation == WindowStartupLocation.CenterScreen)
{
var screen = Screens.ScreenFromPoint(Bounds.Position);

if (screen != null)
Position = screen.WorkingArea.CenterRect(new Rect(ClientSize)).Position;
Position = screen.WorkingArea.CenterRect(new Rect(ClientSize * scaling)).Position;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately this doesn't work for me.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is because the ClientSize is being treated as screen pixels somewhere and isn't being scaled. This is probably a backend-specific bug as I'm not getting it on Win32.

Which backend are you running on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danwalmsley any further info here?

@ahopper
Copy link
Contributor

ahopper commented Jan 16, 2019

I notitce that window position does not seem to use scaling on win32

@OronDF343
Copy link
Contributor Author

OronDF343 commented Jan 16, 2019 via email

@ahopper
Copy link
Contributor

ahopper commented Jan 16, 2019

Yes, it is not clear what should be scaled and what should allow for window chrome and where the transitions should happen.

@grokys
Copy link
Member

grokys commented Jan 17, 2019

Yes, I think the problem here is that we're not specific as to whether a window's position is in device co-ordinates or in device independent co-ordinates.

This SO answer suggests that win32's window position will be in device coordinates if you have a DPI-aware app (we do):

In particular, if you call GetWindowRect or GetClientRect from a high-DPI aware application, you will get the actual values in screen coordinates.

My feeling is that this makes sense, and that we should specify that Window.Position is always in device pixels. @kekekeks does that make sense for other platforms?

@kekekeks
Copy link
Member

It makes perfect sense to have Window.Position in device pixels. There would be a problem with GTK which scales everything, but we are going to get rid of it anyway.

We should also make Position to use PixelPoint instead of Point and make screens API to use PixelSize. Also, we need to fix public static PixelSize FromSize(Size, double) overload to use scaling factor instead of "dpi" which isn't a DPI anyway.

@grokys
Copy link
Member

grokys commented Jan 18, 2019

Thanks for this @OronDF343: the changes @kekekeks suggested made sense, but they were a bit more involved so we merged #2250 which incorporates your changes there.

@grokys grokys closed this Jan 18, 2019
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

Successfully merging this pull request may close these issues.

5 participants