From ba8b49d918748ae9ce91eb58bc5e25d3187cb19b Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Mon, 12 Oct 2020 23:22:28 +0200 Subject: [PATCH] Fix caption hit test. --- .../WindowImpl.CustomCaptionProc.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs index a31357bce5..68bd40da79 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.CustomCaptionProc.cs @@ -44,12 +44,25 @@ namespace Avalonia.Win32 ushort uCol = 1; bool onResizeBorder = false; + // Determine if the point is at the left or right of the window. + if (ptMouse.X >= rcWindow.left && ptMouse.X < rcWindow.left + borderThickness.left) + { + uCol = 0; // left side + } + else if (ptMouse.X < rcWindow.right && ptMouse.X >= rcWindow.right - borderThickness.right) + { + uCol = 2; // right side + } + // Determine if the point is at the top or bottom of the window. if (ptMouse.Y >= rcWindow.top && ptMouse.Y < rcWindow.top + borderThickness.top) { onResizeBorder = (ptMouse.Y < (rcWindow.top - rcFrame.top)); - if (onResizeBorder) + // Two cases where we have a valid row 0 hit test: + // - window resize border (top resize border hit) + // - area below resize border that is actual titlebar (caption hit). + if (onResizeBorder || uCol == 1) { uRow = 0; } @@ -59,16 +72,6 @@ namespace Avalonia.Win32 uRow = 2; } - // Determine if the point is at the left or right of the window. - if (ptMouse.X >= rcWindow.left && ptMouse.X < rcWindow.left + borderThickness.left) - { - uCol = 0; // left side - } - else if (ptMouse.X < rcWindow.right && ptMouse.X >= rcWindow.right - borderThickness.right) - { - uCol = 2; // right side - } - ReadOnlySpan hitZones = stackalloc HitTestValues[] { HitTestValues.HTTOPLEFT, onResizeBorder ? HitTestValues.HTTOP : HitTestValues.HTCAPTION,