AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.11k stars 2.26k forks source link

Properly handle nc hittest for caption buttons #17380

Closed maxkatz6 closed 2 weeks ago

maxkatz6 commented 1 month ago

What does the pull request do?

Properly handles WM_NCHITTEST message with extended client decorations enabled. Previously caption buttons were returning NC_CLIENT result, making them no different from the rest of the app in OS eyes. But if we want to support all Windows features, like Win 11 snap layout, we should let OS know about our caption controls.

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

There are two nuances in this PR:

  1. ~We have to hardcode names for caption buttons. It will work with third party themes well, but it strictly expects CaptionButton > Button#PART_RestoreButton hierarchy. Same can be re-done later after https://github.com/AvaloniaUI/Avalonia/issues/14908.~ Added Win32Properties.NonClientHitTestResultProperty instead of hardcoding.
  2. When WM_NCHITTEST returns anything but NC_CLIENT, OS sends NonClient input events to the app. Avalonia doesn't have any ways for user code to handle all kinds of NonClient events, including move and up events. To make input work with caption buttons, we have to fake client input events from the non-client messages.

Due to these nuances, I kept all changes in WindowImpl.CustomCaptionProc.cs class, which is only used with custom title bar.

Fixed issues

Fixes #11409 Fixes #14908

avaloniaui-bot commented 1 month ago

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

avaloniaui-bot commented 1 month ago

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

avaloniaui-bot commented 2 weeks ago

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