Skip to content

Commit 67e4043

Browse files
committed
enhance: supports Windows 11 Snap Layout when hovering the maximize button (#1957) (#1958)
Signed-off-by: leo <longshuang@msn.cn>
1 parent f763060 commit 67e4043

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Native/Windows.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,9 @@ public void SetupWindow(Window window)
7171

7272
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr _, IntPtr lParam, ref bool handled) =>
7373
{
74-
// Custom WM_NCHITTEST
75-
if (msg == 0x0084)
74+
// Custom WM_NCHITTEST only used to limit the resize border to 4 * window.RenderScaling pixels.
75+
if (msg == 0x0084 && window.WindowState == WindowState.Normal)
7676
{
77-
handled = true;
78-
79-
if (window.WindowState == WindowState.FullScreen || window.WindowState == WindowState.Maximized)
80-
return 1; // HTCLIENT
81-
8277
var p = IntPtrToPixelPoint(lParam);
8378
GetWindowRect(hWnd, out var rcWindow);
8479

@@ -95,18 +90,23 @@ public void SetupWindow(Window window)
9590
else if (p.Y < rcWindow.bottom && p.Y >= rcWindow.bottom - borderThickness)
9691
y = 2;
9792

93+
// If it's in the client area, do not handle it here.
9894
var zone = y * 3 + x;
95+
if (zone == 4)
96+
return IntPtr.Zero;
97+
98+
// If it's in the resize border area, return the proper HT code.
99+
handled = true;
99100
return zone switch
100101
{
101102
0 => 13, // HTTOPLEFT
102103
1 => 12, // HTTOP
103104
2 => 14, // HTTOPRIGHT
104105
3 => 10, // HTLEFT
105-
4 => 1, // HTCLIENT
106106
5 => 11, // HTRIGHT
107107
6 => 16, // HTBOTTOMLEFT
108108
7 => 15, // HTBOTTOM
109-
_ => 17,
109+
_ => 17, // HTBOTTOMRIGHT
110110
};
111111
}
112112

src/Views/CaptionButtons.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
x:Class="SourceGit.Views.CaptionButtons"
77
x:Name="ThisControl">
88
<StackPanel Orientation="Horizontal">
9-
<Button Classes="caption_button" Click="MinimizeWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
9+
<Button Classes="caption_button" Click="MinimizeWindow" Win32Properties.NonClientHitTestResult="MinButton" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
1010
<Path Width="11" Height="11" Margin="0,2,0,0" Data="{StaticResource Icons.Window.Minimize}"/>
1111
</Button>
12-
<Button Classes="caption_button max_or_restore_btn" Click="MaximizeOrRestoreWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
12+
<Button Classes="caption_button max_or_restore_btn" Win32Properties.NonClientHitTestResult="MaxButton" Click="MaximizeOrRestoreWindow" IsVisible="{Binding !#ThisControl.IsCloseButtonOnly}">
1313
<Path Width="10" Height="10" Margin="0,4,0,0"/>
1414
</Button>
15-
<Button Classes="caption_button" Click="CloseWindow">
15+
<Button Classes="caption_button" Win32Properties.NonClientHitTestResult="Close" Click="CloseWindow">
1616
<Path Width="9" Height="9" Margin="0,4,2,0" Data="{StaticResource Icons.Window.Close}"/>
1717
</Button>
1818
</StackPanel>

0 commit comments

Comments
 (0)