2024-06-12 20:54:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Controls.Primitives;
|
|
|
|
|
using Avalonia.Input;
|
2024-08-22 00:06:30 -07:00
|
|
|
|
using Avalonia.Platform;
|
2024-06-12 20:54:10 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
|
{
|
|
|
|
|
public class ChromelessWindow : Window
|
|
|
|
|
{
|
2024-08-21 21:37:26 -07:00
|
|
|
|
public bool UseSystemWindowFrame
|
|
|
|
|
{
|
|
|
|
|
get => OperatingSystem.IsLinux() && ViewModels.Preference.Instance.UseSystemWindowFrame;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 20:54:10 -07:00
|
|
|
|
protected override Type StyleKeyOverride => typeof(Window);
|
|
|
|
|
|
|
|
|
|
public ChromelessWindow()
|
|
|
|
|
{
|
|
|
|
|
if (OperatingSystem.IsLinux())
|
2024-08-21 21:37:26 -07:00
|
|
|
|
{
|
2024-08-22 00:06:30 -07:00
|
|
|
|
if (UseSystemWindowFrame)
|
|
|
|
|
{
|
|
|
|
|
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.Default;
|
|
|
|
|
ExtendClientAreaToDecorationsHint = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
|
|
|
|
|
ExtendClientAreaToDecorationsHint = true;
|
2024-08-21 21:37:26 -07:00
|
|
|
|
Classes.Add("custom_window_frame");
|
2024-08-22 00:06:30 -07:00
|
|
|
|
}
|
2024-08-21 21:37:26 -07:00
|
|
|
|
}
|
2024-10-31 06:36:51 -07:00
|
|
|
|
else if (OperatingSystem.IsWindows())
|
2024-08-21 21:37:26 -07:00
|
|
|
|
{
|
2024-08-22 00:06:30 -07:00
|
|
|
|
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
|
|
|
|
|
ExtendClientAreaToDecorationsHint = true;
|
2024-10-31 06:36:51 -07:00
|
|
|
|
Classes.Add("fix_maximized_padding");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome;
|
|
|
|
|
ExtendClientAreaToDecorationsHint = true;
|
2024-08-21 21:37:26 -07:00
|
|
|
|
}
|
2024-06-12 20:54:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-31 06:36:51 -07:00
|
|
|
|
public void BeginMoveWindow(object _, PointerPressedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ClickCount == 1)
|
|
|
|
|
BeginMoveDrag(e);
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MaximizeOrRestoreWindow(object _, TappedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (WindowState == WindowState.Maximized)
|
|
|
|
|
WindowState = WindowState.Normal;
|
|
|
|
|
else
|
|
|
|
|
WindowState = WindowState.Maximized;
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 20:54:10 -07:00
|
|
|
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnApplyTemplate(e);
|
|
|
|
|
|
|
|
|
|
if (Classes.Contains("custom_window_frame") && CanResize)
|
|
|
|
|
{
|
|
|
|
|
string[] borderNames = [
|
|
|
|
|
"PART_BorderTopLeft",
|
|
|
|
|
"PART_BorderTop",
|
|
|
|
|
"PART_BorderTopRight",
|
|
|
|
|
"PART_BorderLeft",
|
|
|
|
|
"PART_BorderRight",
|
|
|
|
|
"PART_BorderBottomLeft",
|
|
|
|
|
"PART_BorderBottom",
|
|
|
|
|
"PART_BorderBottomRight",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach (var name in borderNames)
|
|
|
|
|
{
|
|
|
|
|
var border = e.NameScope.Find<Border>(name);
|
|
|
|
|
if (border != null)
|
|
|
|
|
{
|
|
|
|
|
border.PointerPressed -= OnWindowBorderPointerPressed;
|
|
|
|
|
border.PointerPressed += OnWindowBorderPointerPressed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnWindowBorderPointerPressed(object sender, PointerPressedEventArgs e)
|
|
|
|
|
{
|
2024-06-13 00:25:04 -07:00
|
|
|
|
if (sender is Border border && border.Tag is WindowEdge edge && CanResize)
|
2024-06-12 20:54:10 -07:00
|
|
|
|
BeginResizeDrag(edge, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|