From 214ffa7345400a805a82dd6f272238bd0cc5f7fc Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 14 Nov 2024 23:23:16 +0000 Subject: [PATCH] Properly handle nc hittest for caption buttons (#17380) * Set e.Handle=true on caption button click event * Return HTCLOSE, HTMINBUTTON and HTMAXBUTTON results on corresponding caption buttons * Redirect fake-client input for caption buttons * Introduce Win32Properties.NonClientHitTestResultProperty instead of hardcoding * Changes after revie --- .../Chrome/CaptionButtons.cs | 32 +++-- .../Platform/Win32Properties.cs | 29 ++++ .../Controls/CaptionButtons.xaml | 9 +- .../Controls/TitleBar.xaml | 6 +- .../Controls/CaptionButtons.xaml | 9 +- .../Controls/TitleBar.xaml | 7 +- .../WindowImpl.CustomCaptionProc.cs | 132 ++++++++++++++---- 7 files changed, 178 insertions(+), 46 deletions(-) diff --git a/src/Avalonia.Controls/Chrome/CaptionButtons.cs b/src/Avalonia.Controls/Chrome/CaptionButtons.cs index 82f4d16bfe..07ecbb188e 100644 --- a/src/Avalonia.Controls/Chrome/CaptionButtons.cs +++ b/src/Avalonia.Controls/Chrome/CaptionButtons.cs @@ -15,10 +15,10 @@ namespace Avalonia.Controls.Chrome [PseudoClasses(":minimized", ":normal", ":maximized", ":fullscreen")] public class CaptionButtons : TemplatedControl { - private const string PART_CloseButton = "PART_CloseButton"; - private const string PART_RestoreButton = "PART_RestoreButton"; - private const string PART_MinimizeButton = "PART_MinimizeButton"; - private const string PART_FullScreenButton = "PART_FullScreenButton"; + internal const string PART_CloseButton = "PART_CloseButton"; + internal const string PART_RestoreButton = "PART_RestoreButton"; + internal const string PART_MinimizeButton = "PART_MinimizeButton"; + internal const string PART_FullScreenButton = "PART_FullScreenButton"; private Button? _restoreButton; private IDisposable? _disposables; @@ -102,24 +102,40 @@ namespace Avalonia.Controls.Chrome if (e.NameScope.Find