From 5574dd2c384277312d74649555902cd6da953d77 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 19 Sep 2024 09:50:27 +0800 Subject: [PATCH] refactor: a better way to fix window drop shadow effect on Win10 --- src/Native/Windows.cs | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index ab91ffdb..8bb4a0f0 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -26,23 +26,11 @@ namespace SourceGit.Native internal string szCSDVersion; } - [StructLayout(LayoutKind.Sequential)] - internal struct MARGINS - { - public int cxLeftWidth; - public int cxRightWidth; - public int cyTopHeight; - public int cyBottomHeight; - } - - [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)] - private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs); - [DllImport("ntdll")] private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation); - [DllImport("dwmapi.dll")] - private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins); + [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)] + private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs); [DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = false)] private static extern IntPtr ILCreateFromPathW(string pszPath); @@ -60,8 +48,8 @@ namespace SourceGit.Native v.dwOSVersionInfoSize = (uint)Marshal.SizeOf(); if (RtlGetVersion(ref v) == 0 && (v.dwMajorVersion < 10 || v.dwBuildNumber < 22000)) { - Window.WindowStateProperty.Changed.AddClassHandler((w, _) => ExtendWindowFrame(w)); - Control.LoadedEvent.AddClassHandler((w, _) => ExtendWindowFrame(w)); + Window.WindowStateProperty.Changed.AddClassHandler((w, _) => FixWindowFrameOnWin10(w)); + Control.LoadedEvent.AddClassHandler((w, _) => FixWindowFrameOnWin10(w)); } } @@ -206,14 +194,12 @@ namespace SourceGit.Native Process.Start(start); } - private void ExtendWindowFrame(Window w) + private void FixWindowFrameOnWin10(Window w) { - var platformHandle = w.TryGetPlatformHandle(); - if (platformHandle == null) - return; - - var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 }; - DwmExtendFrameIntoClientArea(platformHandle.Handle, ref margins); + if (w.WindowState != WindowState.Normal) + w.SystemDecorations = SystemDecorations.Full; + else + w.SystemDecorations = SystemDecorations.BorderOnly; } #region EXTERNAL_EDITOR_FINDER