diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index a7202ff2..2bdcf561 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -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() diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index fa3b1d2c..b76d239a 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -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() diff --git a/src/Native/OS.cs b/src/Native/OS.cs index fb211cf2..4c891283 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -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; } } diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 15201d1f..6a4f7376 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -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(); - if (RtlGetVersion(ref v) == 0 && (v.dwMajorVersion < 10 || v.dwBuildNumber < 22000)) + if (!OperatingSystem.IsWindowsVersionAtLeast(10, 22000, 0)) { Window.WindowStateProperty.Changed.AddClassHandler((w, _) => FixWindowFrameOnWin10(w)); Control.LoadedEvent.AddClassHandler((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 diff --git a/src/ViewModels/Preferences.cs b/src/ViewModels/Preferences.cs index d1e13f38..7404b6be 100644 --- a/src/ViewModels/Preferences.cs +++ b/src/ViewModels/Preferences.cs @@ -91,8 +91,8 @@ namespace SourceGit.ViewModels public bool UseSystemWindowFrame { - get => _useSystemWindowFrame; - set => SetProperty(ref _useSystemWindowFrame, value); + get => Native.OS.UseSystemWindowFrame; + set => Native.OS.UseSystemWindowFrame = value; } public double DefaultFontSize @@ -656,7 +656,6 @@ namespace SourceGit.ViewModels private string _defaultFontFamily = string.Empty; private string _monospaceFontFamily = string.Empty; private bool _onlyUseMonoFontInEditor = false; - private bool _useSystemWindowFrame = false; private double _defaultFontSize = 13; private double _editorFontSize = 13; private int _editorTabWidth = 4; diff --git a/src/Views/ChromelessWindow.cs b/src/Views/ChromelessWindow.cs index 557909fb..1662bcd7 100644 --- a/src/Views/ChromelessWindow.cs +++ b/src/Views/ChromelessWindow.cs @@ -3,7 +3,6 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Input; -using Avalonia.Platform; namespace SourceGit.Views { @@ -11,7 +10,7 @@ namespace SourceGit.Views { public bool UseSystemWindowFrame { - get => OperatingSystem.IsLinux() && ViewModels.Preferences.Instance.UseSystemWindowFrame; + get => Native.OS.UseSystemWindowFrame; } protected override Type StyleKeyOverride => typeof(Window); @@ -19,33 +18,6 @@ namespace SourceGit.Views public ChromelessWindow() { Focusable = true; - - if (OperatingSystem.IsLinux()) - { - if (UseSystemWindowFrame) - { - ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.Default; - ExtendClientAreaToDecorationsHint = false; - } - else - { - ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome; - ExtendClientAreaToDecorationsHint = true; - Classes.Add("custom_window_frame"); - } - } - else if (OperatingSystem.IsWindows()) - { - ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome; - ExtendClientAreaToDecorationsHint = true; - Classes.Add("fix_maximized_padding"); - } - else - { - ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome; - ExtendClientAreaToDecorationsHint = true; - } - Native.OS.SetupForWindow(this); } diff --git a/src/Views/Launcher.axaml b/src/Views/Launcher.axaml index 9876429e..7a2601a6 100644 --- a/src/Views/Launcher.axaml +++ b/src/Views/Launcher.axaml @@ -89,7 +89,7 @@ - + diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 84364ee0..3b171660 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -29,14 +29,9 @@ namespace SourceGit.Views set => SetValue(HasLeftCaptionButtonProperty, value); } - public bool IsRightCaptionButtonsVisible + public bool HasRightCaptionButton { - get - { - if (OperatingSystem.IsLinux()) - return !ViewModels.Preferences.Instance.UseSystemWindowFrame; - return OperatingSystem.IsWindows(); - } + get => OperatingSystem.IsWindows() || !Native.OS.UseSystemWindowFrame; } public Launcher() @@ -52,8 +47,7 @@ namespace SourceGit.Views { HasLeftCaptionButton = true; CaptionHeight = new GridLength(34); - ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | - ExtendClientAreaChromeHints.OSXThickTitleBar; + ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | ExtendClientAreaChromeHints.OSXThickTitleBar; } else if (UseSystemWindowFrame) { diff --git a/src/Views/Preferences.axaml b/src/Views/Preferences.axaml index 6742bcfc..b5826d11 100644 --- a/src/Views/Preferences.axaml +++ b/src/Views/Preferences.axaml @@ -129,23 +129,23 @@ + IsChecked="{Binding ShowAuthorTimeInGraph, Mode=TwoWay}"/> + IsChecked="{Binding ShowTagsInGraph, Mode=TwoWay}"/> + IsChecked="{Binding ShowChildren, Mode=TwoWay}"/> + IsChecked="{Binding Check4UpdatesOnStartup, Mode=TwoWay}"/> @@ -257,12 +257,12 @@ + IsChecked="{Binding UseFixedTabWidth, Mode=TwoWay}"/>