Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions MapWizard.Desktop/Controls/MapWizardWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using SukiUI.Controls;

namespace MapWizard.Desktop.Controls;

/// <summary>
/// Applies the SukiUI Wayland resize fix while retaining SukiWindow's template and behavior.
/// This can be removed once the fix from SukiUI PR #621 is included in the referenced package.
/// </summary>
public class MapWizardWindow : SukiWindow
{
public MapWizardWindow()
{
if (OperatingSystem.IsLinux())
{
AddHandler(
PointerPressedEvent,
OnResizeGripPointerPressed,
RoutingStrategies.Tunnel);
}
}

private void OnResizeGripPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (!CanResize || WindowState != WindowState.Normal)
return;

if (e.Source is not Border { Tag: string edge })
return;

if (!TryGetWindowEdge(edge, out var windowEdge))
return;

if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WAYLAND_DISPLAY")) &&
WindowDecorations == WindowDecorations.None)
{
WindowDecorations = WindowDecorations.BorderOnly;
}

// SukiUI 7.0.1 uses VisualRoot here, which is null on Wayland. The
// SukiWindow instance is already the Window, so invoke the drag on it directly.
BeginResizeDrag(windowEdge, e);
e.Handled = true;
}

private static bool TryGetWindowEdge(string edge, out WindowEdge windowEdge)
{
windowEdge = edge switch
{
"North" => WindowEdge.North,
"South" => WindowEdge.South,
"West" => WindowEdge.West,
"East" => WindowEdge.East,
"NW" => WindowEdge.NorthWest,
"NE" => WindowEdge.NorthEast,
"SW" => WindowEdge.SouthWest,
"SE" => WindowEdge.SouthEast,
_ => default
};

return edge is "North" or "South" or "West" or "East" or "NW" or "NE" or "SW" or "SE";
}
}
5 changes: 3 additions & 2 deletions MapWizard.Desktop/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<suki:SukiWindow
<controls:MapWizardWindow
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MapWizard.Desktop.ViewModels"
Expand All @@ -11,6 +11,7 @@
xmlns:comboColourStudio="clr-namespace:MapWizard.Desktop.Views.ComboColourStudio"
xmlns:mapCleaner="clr-namespace:MapWizard.Desktop.Views.MapCleaner"
xmlns:settings="clr-namespace:MapWizard.Desktop.Views.Settings"
xmlns:controls="clr-namespace:MapWizard.Desktop.Controls"
x:Class="MapWizard.Desktop.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
WindowDecorations="BorderOnly"
Expand Down Expand Up @@ -340,4 +341,4 @@
</TransitioningContentControl>
</Grid>
</VisualLayerManager>
</suki:SukiWindow>
</controls:MapWizardWindow>
4 changes: 2 additions & 2 deletions MapWizard.Desktop/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Avalonia.Interactivity;
using MapWizard.Desktop.Controls;
using MapWizard.Desktop.Services;
using MapWizard.Desktop.ViewModels;
using SukiUI.Controls;
using SukiUI.Enums;

namespace MapWizard.Desktop.Views
{
public partial class MainWindow : SukiWindow
public partial class MainWindow : MapWizardWindow
{
private readonly IThemeService _themeService;

Expand Down
Loading