From 187a8cef8dc7655ead72e0f91acfb82e57421502 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Fri, 21 Oct 2022 17:26:46 +0200 Subject: [PATCH 1/4] try to fix linux drag --- .../Controls/HostWindow.axaml.cs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs index 40efd701c..149248098 100644 --- a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs +++ b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs @@ -88,6 +88,25 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { MoveDrag(args); }; + + //On linux, OnPointerReleased is not called after the drag completed. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + //Activated gets called once the drag starts and once the drag ends. This way we can detect when the drag has finished. + var activatedSwitch = false; + + Activated += (o, i) => + { + if (!_draggingWindow) return; + if (activatedSwitch) + { + EndDrag(Position.ToPoint(1.0)); + activatedSwitch = false; + return; + } + activatedSwitch = true; + }; + } } } } @@ -108,16 +127,16 @@ private void MoveDrag(PointerPressedEventArgs e) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - EndDrag(e); + EndDrag(e.GetPosition(this)); } } - private void EndDrag(PointerEventArgs e) + private void EndDrag(Point point) { PseudoClasses.Set(":dragging", false); Window?.Factory?.OnWindowMoveDragEnd(Window); - _hostWindowState.Process(e.GetPosition(this), EventType.Released); + _hostWindowState.Process(point, EventType.Released); _mouseDown = false; _draggingWindow = false; } @@ -143,7 +162,7 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) if (_draggingWindow) { - EndDrag(e); + EndDrag(e.GetPosition(this)); } } From f8a650ec9cfdcece4be42eab2a6d46e3486f3fb6 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Sun, 23 Oct 2022 12:55:20 +0200 Subject: [PATCH 2/4] don't attach grip on linux hostwindow --- .../Controls/HostWindow.axaml.cs | 19 ------------------- .../Controls/ToolChromeControl.axaml.cs | 4 +++- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs index 149248098..cbaf2ee28 100644 --- a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs +++ b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs @@ -88,25 +88,6 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { MoveDrag(args); }; - - //On linux, OnPointerReleased is not called after the drag completed. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - //Activated gets called once the drag starts and once the drag ends. This way we can detect when the drag has finished. - var activatedSwitch = false; - - Activated += (o, i) => - { - if (!_draggingWindow) return; - if (activatedSwitch) - { - EndDrag(Position.ToPoint(1.0)); - activatedSwitch = false; - return; - } - activatedSwitch = true; - }; - } } } } diff --git a/src/Dock.Avalonia/Controls/ToolChromeControl.axaml.cs b/src/Dock.Avalonia/Controls/ToolChromeControl.axaml.cs index d211d95e4..9cba050bd 100644 --- a/src/Dock.Avalonia/Controls/ToolChromeControl.axaml.cs +++ b/src/Dock.Avalonia/Controls/ToolChromeControl.axaml.cs @@ -1,3 +1,4 @@ +using System.Runtime.InteropServices; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; @@ -79,7 +80,8 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); - if (VisualRoot is HostWindow window) + //On linux we dont attach to the HostWindow because of inconsistent drag behaviour + if (VisualRoot is HostWindow window && !RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Grip = e.NameScope.Find("PART_Grip"); CloseButton = e.NameScope.Find