From ef67e5df0e2166fda574cc2b2d71dd96f687fc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Korczy=C5=84ski?= Date: Sun, 10 Mar 2024 22:03:37 +0000 Subject: [PATCH] Fixed mixed screen/client position usage --- src/Dock.Avalonia/Controls/HostWindow.axaml.cs | 14 +++++++++++--- src/Dock.Avalonia/Internal/HostWindowState.cs | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs index 5957bcd68..3def25e9c 100644 --- a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs +++ b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs @@ -87,6 +87,14 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) } } + private PixelPoint ClientPointToScreenRelativeToWindow(Point clientPoint) + { + var absScreenPoint = this.PointToScreen(clientPoint); + var absScreenWindowPoint = this.PointToScreen(new Point(0, 0)); + var relativeScreenDiff = absScreenPoint - absScreenWindowPoint; + return relativeScreenDiff; + } + private void MoveDrag(PointerPressedEventArgs e) { if (Window?.Factory?.OnWindowMoveDragBegin(Window) != true) @@ -95,7 +103,7 @@ private void MoveDrag(PointerPressedEventArgs e) } _mouseDown = true; - _hostWindowState.Process(e.GetPosition(this), EventType.Pressed); + _hostWindowState.Process(ClientPointToScreenRelativeToWindow(e.GetPosition(this)), EventType.Pressed); PseudoClasses.Set(":dragging", true); _draggingWindow = true; @@ -112,7 +120,7 @@ private void EndDrag(PointerEventArgs e) PseudoClasses.Set(":dragging", false); Window?.Factory?.OnWindowMoveDragEnd(Window); - _hostWindowState.Process(e.GetPosition(this), EventType.Released); + _hostWindowState.Process(ClientPointToScreenRelativeToWindow(e.GetPosition(this)), EventType.Released); _mouseDown = false; _draggingWindow = false; } @@ -153,7 +161,7 @@ private void HostWindow_PositionChanged(object? sender, PixelPointEventArgs e) && _mouseDown) { Window.Factory?.OnWindowMoveDrag(Window); - _hostWindowState.Process(Position.ToPoint(1.0), EventType.Moved); + _hostWindowState.Process(Position, EventType.Moved); } } } diff --git a/src/Dock.Avalonia/Internal/HostWindowState.cs b/src/Dock.Avalonia/Internal/HostWindowState.cs index f3d126926..6806ac21a 100644 --- a/src/Dock.Avalonia/Internal/HostWindowState.cs +++ b/src/Dock.Avalonia/Internal/HostWindowState.cs @@ -10,7 +10,7 @@ namespace Dock.Avalonia.Internal; internal class WindowDragState { - public Point DragStartPoint { get; set; } + public PixelPoint DragStartPoint { get; set; } public bool PointerPressed { get; set; } public bool DoDragDrop { get; set; } public DockControl? TargetDockControl { get; set; } @@ -18,7 +18,7 @@ internal class WindowDragState public Control? TargetDropControl { get; set; } public DragAction DragAction { get; set; } - public void Start(Point point) + public void Start(PixelPoint point) { DragStartPoint = point; PointerPressed = true; @@ -162,7 +162,7 @@ private void Execute(Point point, DockOperation operation, DragAction dragAction } } - private bool IsMinimumDragDistance(Vector diff) + private bool IsMinimumDragDistance(PixelPoint diff) { return (Math.Abs(diff.X) > DockSettings.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > DockSettings.MinimumVerticalDragDistance); @@ -173,7 +173,7 @@ private bool IsMinimumDragDistance(Vector diff) /// /// The pointer position. /// The pointer event type. - public void Process(Point point, EventType eventType) + public void Process(PixelPoint point, EventType eventType) { switch (eventType) { @@ -219,7 +219,7 @@ public void Process(Point point, EventType eventType) if (_state.DoDragDrop == false) { - Vector diff = _state.DragStartPoint - point; + var diff = _state.DragStartPoint - point; var haveMinimumDragDistance = IsMinimumDragDistance(diff); if (haveMinimumDragDistance) {