Skip to content

Commit 91bc1ee

Browse files
committed
fix: try to fix window drop shadow missing on Windows 10
1 parent 6cc6088 commit 91bc1ee

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/SourceGit/Native/Windows.cs

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

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

1112
namespace SourceGit.Native
1213
{
1314
[SupportedOSPlatform("windows")]
1415
internal class Windows : OS.IBackend
1516
{
17+
[StructLayout(LayoutKind.Sequential)]
18+
internal struct RTL_OSVERSIONINFOEX
19+
{
20+
internal uint dwOSVersionInfoSize;
21+
internal uint dwMajorVersion;
22+
internal uint dwMinorVersion;
23+
internal uint dwBuildNumber;
24+
internal uint dwPlatformId;
25+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
26+
internal string szCSDVersion;
27+
}
28+
29+
[StructLayout(LayoutKind.Sequential)]
30+
internal struct MARGINS
31+
{
32+
public int cxLeftWidth;
33+
public int cxRightWidth;
34+
public int cyTopHeight;
35+
public int cyBottomHeight;
36+
}
37+
1638
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
1739
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
1840

41+
[DllImport("ntdll")]
42+
private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation);
43+
44+
[DllImport("dwmapi.dll")]
45+
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
46+
1947
public void SetupApp(AppBuilder builder)
2048
{
2149
builder.With(new FontManagerOptions()
2250
{
2351
DefaultFamilyName = "Microsoft YaHei UI",
2452
FontFallbacks = [new FontFallback { FontFamily = "Microsoft YaHei" }],
2553
});
54+
55+
// Fix drop shadow issue on Windows 10
56+
RTL_OSVERSIONINFOEX v = new RTL_OSVERSIONINFOEX();
57+
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOEX>();
58+
if (RtlGetVersion(ref v) == 0 && (v.dwMajorVersion < 10 || v.dwBuildNumber < 22000))
59+
{
60+
Window.WindowStateProperty.Changed.AddClassHandler<Window>((w, e) =>
61+
{
62+
if (w.WindowState != WindowState.Maximized)
63+
{
64+
var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 };
65+
DwmExtendFrameIntoClientArea(w.TryGetPlatformHandle().Handle, ref margins);
66+
}
67+
});
68+
69+
Window.LoadedEvent.AddClassHandler<Window>((w, e) =>
70+
{
71+
if (w.WindowState != WindowState.Maximized)
72+
{
73+
var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 };
74+
DwmExtendFrameIntoClientArea(w.TryGetPlatformHandle().Handle, ref margins);
75+
}
76+
});
77+
}
2678
}
2779

2880
public string FindGitExecutable()

0 commit comments

Comments
 (0)