code_style: move platform dependent code to initialize window to namespace SourceGit.Native

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-12 21:52:50 +08:00
parent c62b4a031f
commit ef4b639f8e
No known key found for this signature in database
9 changed files with 41 additions and 68 deletions

View file

@ -6,6 +6,7 @@ using System.Runtime.Versioning;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform;
namespace SourceGit.Native
{
@ -19,7 +20,17 @@ namespace SourceGit.Native
public void SetupWindow(Window window)
{
// Do Nothing.
if (OS.UseSystemWindowFrame)
{
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.Default;
window.ExtendClientAreaToDecorationsHint = false;
}
else
{
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
window.ExtendClientAreaToDecorationsHint = true;
window.Classes.Add("custom_window_frame");
}
}
public string FindGitExecutable()

View file

@ -6,6 +6,7 @@ using System.Runtime.Versioning;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform;
namespace SourceGit.Native
{
@ -39,7 +40,8 @@ namespace SourceGit.Native
public void SetupWindow(Window window)
{
// Do Nothing.
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome;
window.ExtendClientAreaToDecorationsHint = true;
}
public string FindGitExecutable()

View file

@ -70,6 +70,12 @@ namespace SourceGit.Native
set;
} = [];
public static bool UseSystemWindowFrame
{
get => OperatingSystem.IsLinux() && _enableSystemWindowFrame;
set => _enableSystemWindowFrame = value;
}
static OS()
{
if (OperatingSystem.IsWindows())
@ -232,5 +238,6 @@ namespace SourceGit.Native
private static IBackend _backend = null;
private static string _gitExecutable = string.Empty;
private static bool _enableSystemWindowFrame = false;
}
}

View file

@ -8,6 +8,7 @@ using System.Text;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform;
using Avalonia.Threading;
namespace SourceGit.Native
@ -15,18 +16,6 @@ namespace SourceGit.Native
[SupportedOSPlatform("windows")]
internal class Windows : OS.IBackend
{
[StructLayout(LayoutKind.Sequential)]
internal struct RTL_OSVERSIONINFOEX
{
internal uint dwOSVersionInfoSize;
internal uint dwMajorVersion;
internal uint dwMinorVersion;
internal uint dwBuildNumber;
internal uint dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal string szCSDVersion;
}
internal struct RECT
{
public int left;
@ -72,9 +61,6 @@ namespace SourceGit.Native
public int cyBottomHeight;
}
[DllImport("ntdll.dll")]
private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation);
[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
@ -96,9 +82,7 @@ namespace SourceGit.Native
public void SetupApp(AppBuilder builder)
{
// Fix drop shadow issue on Windows 10
RTL_OSVERSIONINFOEX v = new RTL_OSVERSIONINFOEX();
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOEX>();
if (RtlGetVersion(ref v) == 0 && (v.dwMajorVersion < 10 || v.dwBuildNumber < 22000))
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 22000, 0))
{
Window.WindowStateProperty.Changed.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
Control.LoadedEvent.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
@ -107,6 +91,10 @@ namespace SourceGit.Native
public void SetupWindow(Window window)
{
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
window.ExtendClientAreaToDecorationsHint = true;
window.Classes.Add("fix_maximized_padding");
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
// Custom WM_NCHITTEST