From f0a3a0d544677b5873545c9a13be67b25f8b8537 Mon Sep 17 00:00:00 2001 From: maotovisk Date: Sat, 18 Jul 2026 22:55:56 -0300 Subject: [PATCH] fix: workarround sukiui wayland window resize --- MapWizard.Desktop/Controls/MapWizardWindow.cs | 66 +++++++++++++++++++ MapWizard.Desktop/Views/MainWindow.axaml | 5 +- MapWizard.Desktop/Views/MainWindow.axaml.cs | 4 +- 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 MapWizard.Desktop/Controls/MapWizardWindow.cs diff --git a/MapWizard.Desktop/Controls/MapWizardWindow.cs b/MapWizard.Desktop/Controls/MapWizardWindow.cs new file mode 100644 index 0000000..dd69414 --- /dev/null +++ b/MapWizard.Desktop/Controls/MapWizardWindow.cs @@ -0,0 +1,66 @@ +using System; +using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Interactivity; +using SukiUI.Controls; + +namespace MapWizard.Desktop.Controls; + +/// +/// 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. +/// +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"; + } +} diff --git a/MapWizard.Desktop/Views/MainWindow.axaml b/MapWizard.Desktop/Views/MainWindow.axaml index 24fc498..aeb4ecb 100644 --- a/MapWizard.Desktop/Views/MainWindow.axaml +++ b/MapWizard.Desktop/Views/MainWindow.axaml @@ -1,4 +1,4 @@ - - + diff --git a/MapWizard.Desktop/Views/MainWindow.axaml.cs b/MapWizard.Desktop/Views/MainWindow.axaml.cs index 1989aef..2f362c7 100644 --- a/MapWizard.Desktop/Views/MainWindow.axaml.cs +++ b/MapWizard.Desktop/Views/MainWindow.axaml.cs @@ -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;