Skip to content

Commit af9cf6b

Browse files
committed
ux: force using 4 * RenderScaling as resize border size on Windows
Signed-off-by: leo <[email protected]>
1 parent 641098f commit af9cf6b

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

src/Native/Linux.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Runtime.Versioning;
66

77
using Avalonia;
8+
using Avalonia.Controls;
89

910
namespace SourceGit.Native
1011
{
@@ -16,6 +17,11 @@ public void SetupApp(AppBuilder builder)
1617
builder.With(new X11PlatformOptions() { EnableIme = true });
1718
}
1819

20+
public void SetupWindow(Window window)
21+
{
22+
// Do Nothing.
23+
}
24+
1925
public string FindGitExecutable()
2026
{
2127
return FindExecutable("git");

src/Native/MacOS.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Runtime.Versioning;
66

77
using Avalonia;
8+
using Avalonia.Controls;
89

910
namespace SourceGit.Native
1011
{
@@ -36,6 +37,11 @@ public void SetupApp(AppBuilder builder)
3637
Environment.SetEnvironmentVariable("PATH", path);
3738
}
3839

40+
public void SetupWindow(Window window)
41+
{
42+
// Do Nothing.
43+
}
44+
3945
public string FindGitExecutable()
4046
{
4147
var gitPathVariants = new List<string>() {

src/Native/OS.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.RegularExpressions;
77

88
using Avalonia;
9+
using Avalonia.Controls;
910

1011
namespace SourceGit.Native
1112
{
@@ -14,6 +15,7 @@ public static partial class OS
1415
public interface IBackend
1516
{
1617
void SetupApp(AppBuilder builder);
18+
void SetupWindow(Window window);
1719

1820
string FindGitExecutable();
1921
string FindTerminal(Models.ShellOrTerminal shell);
@@ -121,6 +123,11 @@ public static void SetupEnternalTools()
121123
ExternalTools = _backend.FindExternalTools();
122124
}
123125

126+
public static void SetupForWindow(Window window)
127+
{
128+
_backend.SetupWindow(window);
129+
}
130+
124131
public static string FindGitExecutable()
125132
{
126133
return _backend.FindGitExecutable();

src/Native/Windows.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,42 @@ internal struct RTL_OSVERSIONINFOEX
2727
internal string szCSDVersion;
2828
}
2929

30+
internal struct RECT
31+
{
32+
public int left;
33+
public int top;
34+
public int right;
35+
public int bottom;
36+
}
37+
38+
internal enum HitTest
39+
{
40+
HTERROR = -2,
41+
HTTRANSPARENT = -1,
42+
HTNOWHERE = 0,
43+
HTCLIENT = 1,
44+
HTCAPTION = 2,
45+
HTSYSMENU = 3,
46+
HTGROWBOX = 4,
47+
HTMENU = 5,
48+
HTHSCROLL = 6,
49+
HTVSCROLL = 7,
50+
HTMINBUTTON = 8,
51+
HTMAXBUTTON = 9,
52+
HTLEFT = 10,
53+
HTRIGHT = 11,
54+
HTTOP = 12,
55+
HTTOPLEFT = 13,
56+
HTTOPRIGHT = 14,
57+
HTBOTTOM = 15,
58+
HTBOTTOMLEFT = 16,
59+
HTBOTTOMRIGHT = 17,
60+
HTBORDER = 18,
61+
HTOBJECT = 19,
62+
HTCLOSE = 20,
63+
HTHELP = 21
64+
}
65+
3066
[StructLayout(LayoutKind.Sequential)]
3167
internal struct MARGINS
3268
{
@@ -54,6 +90,9 @@ internal struct MARGINS
5490
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = false)]
5591
private static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags);
5692

93+
[DllImport("user32.dll")]
94+
private static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
95+
5796
public void SetupApp(AppBuilder builder)
5897
{
5998
// Fix drop shadow issue on Windows 10
@@ -66,6 +105,44 @@ public void SetupApp(AppBuilder builder)
66105
}
67106
}
68107

108+
public void SetupWindow(Window window)
109+
{
110+
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
111+
{
112+
// Custom WM_NCHITTEST
113+
if (msg == 0x0084)
114+
{
115+
var p = IntPtrToPixelPoint(lParam);
116+
GetWindowRect(hWnd, out var rcWindow);
117+
118+
var borderThinkness = (int)(4 * window.RenderScaling);
119+
int row = 1;
120+
int col = 1;
121+
if (p.X >= rcWindow.left && p.X < rcWindow.left + borderThinkness)
122+
col = 0;
123+
else if (p.X < rcWindow.right && p.X >= rcWindow.right - borderThinkness)
124+
col = 2;
125+
126+
if (p.Y >= rcWindow.top && p.Y < rcWindow.top + borderThinkness)
127+
row = 0;
128+
else if (p.Y < rcWindow.bottom && p.Y >= rcWindow.bottom - borderThinkness)
129+
row = 2;
130+
131+
ReadOnlySpan<HitTest> zones = stackalloc HitTest[]
132+
{
133+
HitTest.HTTOPLEFT, HitTest.HTTOP, HitTest.HTTOPRIGHT,
134+
HitTest.HTLEFT, HitTest.HTCLIENT, HitTest.HTRIGHT,
135+
HitTest.HTBOTTOMLEFT, HitTest.HTBOTTOM, HitTest.HTBOTTOMRIGHT
136+
};
137+
138+
handled = true;
139+
return (IntPtr)(zones[row * 3 + col]);
140+
}
141+
142+
return IntPtr.Zero;
143+
});
144+
}
145+
69146
public string FindGitExecutable()
70147
{
71148
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
@@ -228,6 +305,12 @@ private void FixWindowFrameOnWin10(Window w)
228305
}, DispatcherPriority.Render);
229306
}
230307

308+
private PixelPoint IntPtrToPixelPoint(IntPtr param)
309+
{
310+
var v = IntPtr.Size == 4 ? param.ToInt32() : (int)(param.ToInt64() & 0xFFFFFFFF);
311+
return new PixelPoint((short)(v & 0xffff), (short)(v >> 16));
312+
}
313+
231314
#region EXTERNAL_EDITOR_FINDER
232315
private string FindVSCode()
233316
{

src/Views/ChromelessWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public ChromelessWindow()
4545
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome;
4646
ExtendClientAreaToDecorationsHint = true;
4747
}
48+
49+
Native.OS.SetupForWindow(this);
4850
}
4951

5052
public void BeginMoveWindow(object _, PointerPressedEventArgs e)

0 commit comments

Comments
 (0)