mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 11:44:59 +00:00
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:
parent
c62b4a031f
commit
ef4b639f8e
9 changed files with 41 additions and 68 deletions
|
@ -6,6 +6,7 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform;
|
||||||
|
|
||||||
namespace SourceGit.Native
|
namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
|
@ -19,7 +20,17 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
public void SetupWindow(Window window)
|
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()
|
public string FindGitExecutable()
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform;
|
||||||
|
|
||||||
namespace SourceGit.Native
|
namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
|
@ -39,7 +40,8 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
public void SetupWindow(Window window)
|
public void SetupWindow(Window window)
|
||||||
{
|
{
|
||||||
// Do Nothing.
|
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome;
|
||||||
|
window.ExtendClientAreaToDecorationsHint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FindGitExecutable()
|
public string FindGitExecutable()
|
||||||
|
|
|
@ -70,6 +70,12 @@ namespace SourceGit.Native
|
||||||
set;
|
set;
|
||||||
} = [];
|
} = [];
|
||||||
|
|
||||||
|
public static bool UseSystemWindowFrame
|
||||||
|
{
|
||||||
|
get => OperatingSystem.IsLinux() && _enableSystemWindowFrame;
|
||||||
|
set => _enableSystemWindowFrame = value;
|
||||||
|
}
|
||||||
|
|
||||||
static OS()
|
static OS()
|
||||||
{
|
{
|
||||||
if (OperatingSystem.IsWindows())
|
if (OperatingSystem.IsWindows())
|
||||||
|
@ -232,5 +238,6 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
private static IBackend _backend = null;
|
private static IBackend _backend = null;
|
||||||
private static string _gitExecutable = string.Empty;
|
private static string _gitExecutable = string.Empty;
|
||||||
|
private static bool _enableSystemWindowFrame = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ using System.Text;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
namespace SourceGit.Native
|
namespace SourceGit.Native
|
||||||
|
@ -15,18 +16,6 @@ namespace SourceGit.Native
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
internal class Windows : OS.IBackend
|
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
|
internal struct RECT
|
||||||
{
|
{
|
||||||
public int left;
|
public int left;
|
||||||
|
@ -72,9 +61,6 @@ namespace SourceGit.Native
|
||||||
public int cyBottomHeight;
|
public int cyBottomHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("ntdll.dll")]
|
|
||||||
private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation);
|
|
||||||
|
|
||||||
[DllImport("dwmapi.dll")]
|
[DllImport("dwmapi.dll")]
|
||||||
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
|
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
|
||||||
|
|
||||||
|
@ -96,9 +82,7 @@ namespace SourceGit.Native
|
||||||
public void SetupApp(AppBuilder builder)
|
public void SetupApp(AppBuilder builder)
|
||||||
{
|
{
|
||||||
// Fix drop shadow issue on Windows 10
|
// Fix drop shadow issue on Windows 10
|
||||||
RTL_OSVERSIONINFOEX v = new RTL_OSVERSIONINFOEX();
|
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 22000, 0))
|
||||||
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOEX>();
|
|
||||||
if (RtlGetVersion(ref v) == 0 && (v.dwMajorVersion < 10 || v.dwBuildNumber < 22000))
|
|
||||||
{
|
{
|
||||||
Window.WindowStateProperty.Changed.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
|
Window.WindowStateProperty.Changed.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
|
||||||
Control.LoadedEvent.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
|
Control.LoadedEvent.AddClassHandler<Window>((w, _) => FixWindowFrameOnWin10(w));
|
||||||
|
@ -107,6 +91,10 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
public void SetupWindow(Window window)
|
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) =>
|
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
|
||||||
{
|
{
|
||||||
// Custom WM_NCHITTEST
|
// Custom WM_NCHITTEST
|
||||||
|
|
|
@ -91,8 +91,8 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public bool UseSystemWindowFrame
|
public bool UseSystemWindowFrame
|
||||||
{
|
{
|
||||||
get => _useSystemWindowFrame;
|
get => Native.OS.UseSystemWindowFrame;
|
||||||
set => SetProperty(ref _useSystemWindowFrame, value);
|
set => Native.OS.UseSystemWindowFrame = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double DefaultFontSize
|
public double DefaultFontSize
|
||||||
|
@ -656,7 +656,6 @@ namespace SourceGit.ViewModels
|
||||||
private string _defaultFontFamily = string.Empty;
|
private string _defaultFontFamily = string.Empty;
|
||||||
private string _monospaceFontFamily = string.Empty;
|
private string _monospaceFontFamily = string.Empty;
|
||||||
private bool _onlyUseMonoFontInEditor = false;
|
private bool _onlyUseMonoFontInEditor = false;
|
||||||
private bool _useSystemWindowFrame = false;
|
|
||||||
private double _defaultFontSize = 13;
|
private double _defaultFontSize = 13;
|
||||||
private double _editorFontSize = 13;
|
private double _editorFontSize = 13;
|
||||||
private int _editorTabWidth = 4;
|
private int _editorTabWidth = 4;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Platform;
|
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
|
@ -11,7 +10,7 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
public bool UseSystemWindowFrame
|
public bool UseSystemWindowFrame
|
||||||
{
|
{
|
||||||
get => OperatingSystem.IsLinux() && ViewModels.Preferences.Instance.UseSystemWindowFrame;
|
get => Native.OS.UseSystemWindowFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Type StyleKeyOverride => typeof(Window);
|
protected override Type StyleKeyOverride => typeof(Window);
|
||||||
|
@ -19,33 +18,6 @@ namespace SourceGit.Views
|
||||||
public ChromelessWindow()
|
public ChromelessWindow()
|
||||||
{
|
{
|
||||||
Focusable = true;
|
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);
|
Native.OS.SetupForWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
<v:LauncherTabBar Grid.Column="2" Height="30" Margin="0,0,16,0" VerticalAlignment="Bottom"/>
|
<v:LauncherTabBar Grid.Column="2" Height="30" Margin="0,0,16,0" VerticalAlignment="Bottom"/>
|
||||||
|
|
||||||
<!-- Caption Buttons (Windows/Linux)-->
|
<!-- Caption Buttons (Windows/Linux)-->
|
||||||
<Border Grid.Column="3" Margin="16,0,0,0" IsVisible="{Binding #ThisControl.IsRightCaptionButtonsVisible}">
|
<Border Grid.Column="3" Margin="16,0,0,0" IsVisible="{Binding #ThisControl.HasRightCaptionButton}">
|
||||||
<v:CaptionButtons Height="30" VerticalAlignment="Top"/>
|
<v:CaptionButtons Height="30" VerticalAlignment="Top"/>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -29,14 +29,9 @@ namespace SourceGit.Views
|
||||||
set => SetValue(HasLeftCaptionButtonProperty, value);
|
set => SetValue(HasLeftCaptionButtonProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsRightCaptionButtonsVisible
|
public bool HasRightCaptionButton
|
||||||
{
|
{
|
||||||
get
|
get => OperatingSystem.IsWindows() || !Native.OS.UseSystemWindowFrame;
|
||||||
{
|
|
||||||
if (OperatingSystem.IsLinux())
|
|
||||||
return !ViewModels.Preferences.Instance.UseSystemWindowFrame;
|
|
||||||
return OperatingSystem.IsWindows();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Launcher()
|
public Launcher()
|
||||||
|
@ -52,8 +47,7 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
HasLeftCaptionButton = true;
|
HasLeftCaptionButton = true;
|
||||||
CaptionHeight = new GridLength(34);
|
CaptionHeight = new GridLength(34);
|
||||||
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome |
|
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | ExtendClientAreaChromeHints.OSXThickTitleBar;
|
||||||
ExtendClientAreaChromeHints.OSXThickTitleBar;
|
|
||||||
}
|
}
|
||||||
else if (UseSystemWindowFrame)
|
else if (UseSystemWindowFrame)
|
||||||
{
|
{
|
||||||
|
|
|
@ -129,23 +129,23 @@
|
||||||
<CheckBox Grid.Row="5" Grid.Column="1"
|
<CheckBox Grid.Row="5" Grid.Column="1"
|
||||||
Height="32"
|
Height="32"
|
||||||
Content="{DynamicResource Text.Preferences.General.ShowAuthorTime}"
|
Content="{DynamicResource Text.Preferences.General.ShowAuthorTime}"
|
||||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowAuthorTimeInGraph, Mode=TwoWay}"/>
|
IsChecked="{Binding ShowAuthorTimeInGraph, Mode=TwoWay}"/>
|
||||||
|
|
||||||
<CheckBox Grid.Row="6" Grid.Column="1"
|
<CheckBox Grid.Row="6" Grid.Column="1"
|
||||||
Height="32"
|
Height="32"
|
||||||
Content="{DynamicResource Text.Preferences.General.ShowTagsInGraph}"
|
Content="{DynamicResource Text.Preferences.General.ShowTagsInGraph}"
|
||||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowTagsInGraph, Mode=TwoWay}"/>
|
IsChecked="{Binding ShowTagsInGraph, Mode=TwoWay}"/>
|
||||||
|
|
||||||
<CheckBox Grid.Row="7" Grid.Column="1"
|
<CheckBox Grid.Row="7" Grid.Column="1"
|
||||||
Height="32"
|
Height="32"
|
||||||
Content="{DynamicResource Text.Preferences.General.ShowChildren}"
|
Content="{DynamicResource Text.Preferences.General.ShowChildren}"
|
||||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowChildren, Mode=TwoWay}"/>
|
IsChecked="{Binding ShowChildren, Mode=TwoWay}"/>
|
||||||
|
|
||||||
<CheckBox Grid.Row="8" Grid.Column="1"
|
<CheckBox Grid.Row="8" Grid.Column="1"
|
||||||
Height="32"
|
Height="32"
|
||||||
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
|
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
|
||||||
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"
|
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"
|
||||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=Check4UpdatesOnStartup, Mode=TwoWay}"/>
|
IsChecked="{Binding Check4UpdatesOnStartup, Mode=TwoWay}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
@ -257,12 +257,12 @@
|
||||||
<CheckBox Grid.Row="7" Grid.Column="1"
|
<CheckBox Grid.Row="7" Grid.Column="1"
|
||||||
Height="32"
|
Height="32"
|
||||||
Content="{DynamicResource Text.Preferences.Appearance.UseFixedTabWidth}"
|
Content="{DynamicResource Text.Preferences.Appearance.UseFixedTabWidth}"
|
||||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseFixedTabWidth, Mode=TwoWay}"/>
|
IsChecked="{Binding UseFixedTabWidth, Mode=TwoWay}"/>
|
||||||
|
|
||||||
<CheckBox Grid.Row="8" Grid.Column="1"
|
<CheckBox Grid.Row="8" Grid.Column="1"
|
||||||
Height="32"
|
Height="32"
|
||||||
Content="{DynamicResource Text.Preferences.Appearance.UseNativeWindowFrame}"
|
Content="{DynamicResource Text.Preferences.Appearance.UseNativeWindowFrame}"
|
||||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSystemWindowFrame, Mode=OneTime}"
|
IsChecked="{Binding UseSystemWindowFrame, Mode=OneTime}"
|
||||||
IsVisible="{OnPlatform False, Linux=True}"
|
IsVisible="{OnPlatform False, Linux=True}"
|
||||||
IsCheckedChanged="OnUseNativeWindowFrameChanged"/>
|
IsCheckedChanged="OnUseNativeWindowFrameChanged"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue