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

Win32 - Fix Window Frame Size and Position issues. #16608

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

emmauss
Copy link
Contributor

@emmauss emmauss commented Aug 6, 2024

What does the pull request do?

Our Window properties that rely on the window border/frame have inconsistent behavior on windows, esp. when compared to WPF. This pr ensures that the FrameSize and window Position doesn't change when decorations are changed, and client area is affected. Window Position and FrameSize now considers the whole window border, including the transparent border Windows apply to resizable windows. The following rules are enforced;

  1. Updates to Position should not cause Frame Size to change
  2. Updates to Width/Height should not cause Position to change
  3. Updates to WindowState should ensure Frame properties of other states do not change
  4. Updates to Decorations should not cause Frame properties of the current window state to change
    First time window without borders has incorrect position #16529
    11.1.0 - Window position is incorrect when the SystemDecorations property is set to BorderOnly #16454
  5. PositionChanged event should report the Frame position
  6. ExtendClient margins are calculated on updates to Window State
    Caption Buttons disappearing #16503

What is the current behavior?

Window Position doesn't consider the transparent part of the border, only the visible part, which is usually just 1 pixel wide. This causes the window Position to change when client is extended to window frame, even though the window hasn't moved. This behavior also affects reported FrameSize, even though the window hasn't been resized.
For normal windows with system decorations, setting system decorations to BorderOnly or None forces Frame to shrink to client area, instead of growing the client area like it is in WPF.

What is the updated/expected behavior with this PR?

Window FrameSize and Position are only updated when there's a change in WindowState, when user updates Window.Position or when use resizes the window. They are kept unchanged when there's an update to ExtendedClient properties and SystemDecorations. FrameSize and Position will consider all parts of the window that the OS considers as part of the window decorations.

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #16529
Fixes #16454
Fixes #16503
Fixes #14604
Fixes #11411

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051037-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051042-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051048-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]


SetWindowPos(_hwnd, IntPtr.Zero, newRect.left, newRect.top, newRect.Width, newRect.Height,
SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE |
SetWindowPos(_hwnd, IntPtr.Zero, rcWindow.left, rcWindow.top, 0 ,0,

This comment was marked as resolved.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051062-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6
Copy link
Member

maxkatz6 commented Aug 7, 2024

@emmauss does it also close #14604 and #11411

@maxkatz6
Copy link
Member

maxkatz6 commented Aug 7, 2024

Also, do we need this another PR from @TomEdwardsEnscape ?

@emmauss
Copy link
Contributor Author

emmauss commented Aug 7, 2024

@emmauss does it also close #14604 and #11411

Yes. I'll add them to the fix list

@emmauss
Copy link
Contributor Author

emmauss commented Aug 7, 2024

Also, do we need this another PR from @TomEdwardsEnscape ?

It seems their pr only extends client when a show operation is done, and not when window state is changed. Just to be certain extendclient is always checked, we can have both changes in.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051109-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051307-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul enabled auto-merge August 16, 2024 14:45
@MrJul MrJul added this pull request to the merge queue Aug 16, 2024
Merged via the queue into master with commit 8540780 Aug 16, 2024
11 checks passed
@MrJul MrJul deleted the win32_window_frame_fixes branch August 16, 2024 18:48
@josephmoresena
Copy link

Would this solve #11333?

@maxkatz6
Copy link
Member

@josephmoresena it should. You can check that by using nighly build from #16608 (comment)

@adirh3
Copy link
Contributor

adirh3 commented Aug 26, 2024

FYI this change introduced multiple issues with my FullScreen window, mostly the window shrinking when moving it between monitors with different resolutions/DPIs.
Will try to investigate and update/create PR for fix

@grokys grokys added the bug label Aug 30, 2024
@grokys grokys added backported-11.1.x customer-priority Issue reported by a customer with a support agreement. labels Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment