enhance: supports Windows 11 Snap Layout when hovering the maximize button (#1957) (#1958)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-12-08 10:56:24 +08:00
parent f763060bd6
commit 67e404330f
2 changed files with 12 additions and 12 deletions

View File

@@ -71,14 +71,9 @@ namespace SourceGit.Native
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr _, IntPtr lParam, ref bool handled) =>
{
// Custom WM_NCHITTEST
if (msg == 0x0084)
// Custom WM_NCHITTEST only used to limit the resize border to 4 * window.RenderScaling pixels.
if (msg == 0x0084 && window.WindowState == WindowState.Normal)
{
handled = true;
if (window.WindowState == WindowState.FullScreen || window.WindowState == WindowState.Maximized)
return 1; // HTCLIENT
var p = IntPtrToPixelPoint(lParam);
GetWindowRect(hWnd, out var rcWindow);
@@ -95,18 +90,23 @@ namespace SourceGit.Native
else if (p.Y < rcWindow.bottom && p.Y >= rcWindow.bottom - borderThickness)
y = 2;
// If it's in the client area, do not handle it here.
var zone = y * 3 + x;
if (zone == 4)
return IntPtr.Zero;
// If it's in the resize border area, return the proper HT code.
handled = true;
return zone switch
{
0 => 13, // HTTOPLEFT
1 => 12, // HTTOP
2 => 14, // HTTOPRIGHT
3 => 10, // HTLEFT
4 => 1, // HTCLIENT
5 => 11, // HTRIGHT
6 => 16, // HTBOTTOMLEFT
7 => 15, // HTBOTTOM
_ => 17,
_ => 17, // HTBOTTOMRIGHT
};
}

View File

@@ -6,13 +6,13 @@
x:Class="SourceGit.Views.CaptionButtons"
x:Name="ThisControl">
<StackPanel Orientation="Horizontal">
<Button Classes="caption_button" Click="MinimizeWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
<Button Classes="caption_button" Click="MinimizeWindow" Win32Properties.NonClientHitTestResult="MinButton" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
<Path Width="11" Height="11" Margin="0,2,0,0" Data="{StaticResource Icons.Window.Minimize}"/>
</Button>
<Button Classes="caption_button max_or_restore_btn" Click="MaximizeOrRestoreWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
<Button Classes="caption_button max_or_restore_btn" Win32Properties.NonClientHitTestResult="MaxButton" Click="MaximizeOrRestoreWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
<Path Width="10" Height="10" Margin="0,4,0,0"/>
</Button>
<Button Classes="caption_button" Click="CloseWindow">
<Button Classes="caption_button" Win32Properties.NonClientHitTestResult="Close" Click="CloseWindow">
<Path Width="9" Height="9" Margin="0,4,2,0" Data="{StaticResource Icons.Window.Close}"/>
</Button>
</StackPanel>