From 762ec1f702538dd51dfb474c1197d48910352a2d Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 13 Jun 2024 17:55:22 +0800 Subject: [PATCH] fix: begin drag was triggered when double click on the title bar --- src/Views/Blame.axaml | 4 +++- src/Views/Blame.axaml.cs | 26 ++++++++++++++++++++++- src/Views/BranchCompare.axaml | 4 +++- src/Views/BranchCompare.axaml.cs | 27 +++++++++++++++++++++++- src/Views/FileHistories.axaml | 4 +++- src/Views/FileHistories.axaml.cs | 27 +++++++++++++++++++++++- src/Views/Launcher.axaml | 7 ++++--- src/Views/Launcher.axaml.cs | 36 +++++++++++++++++++++++++------- 8 files changed, 119 insertions(+), 16 deletions(-) diff --git a/src/Views/Blame.axaml b/src/Views/Blame.axaml index fdd4b7bc..a7e850fb 100644 --- a/src/Views/Blame.axaml +++ b/src/Views/Blame.axaml @@ -28,7 +28,9 @@ Background="{DynamicResource Brush.TitleBar}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}" DoubleTapped="MaximizeOrRestoreWindow" - PointerPressed="BeginMoveWindow"/> + PointerPressed="BeginMoveWindow" + PointerMoved="MoveWindow" + PointerReleased="EndMoveWindow"/> diff --git a/src/Views/Blame.axaml.cs b/src/Views/Blame.axaml.cs index dc876612..8a6ffee9 100644 --- a/src/Views/Blame.axaml.cs +++ b/src/Views/Blame.axaml.cs @@ -343,7 +343,29 @@ namespace SourceGit.Views private void BeginMoveWindow(object sender, PointerPressedEventArgs e) { - BeginMoveDrag(e); + if (e.ClickCount != 2) + _pressedTitleBar = true; + } + + private void MoveWindow(object sender, PointerEventArgs e) + { + if (!_pressedTitleBar) + return; + + var visual = (Visual)e.Source; + BeginMoveDrag(new PointerPressedEventArgs( + e.Source, + e.Pointer, + visual, + e.GetPosition(visual), + e.Timestamp, + new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed), + e.KeyModifiers)); + } + + private void EndMoveWindow(object sender, PointerReleasedEventArgs e) + { + _pressedTitleBar = false; } protected override void OnClosed(EventArgs e) @@ -361,5 +383,7 @@ namespace SourceGit.Views } e.Handled = true; } + + private bool _pressedTitleBar = false; } } diff --git a/src/Views/BranchCompare.axaml b/src/Views/BranchCompare.axaml index 2733b11c..9ad7db03 100644 --- a/src/Views/BranchCompare.axaml +++ b/src/Views/BranchCompare.axaml @@ -28,7 +28,9 @@ Background="{DynamicResource Brush.TitleBar}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}" DoubleTapped="MaximizeOrRestoreWindow" - PointerPressed="BeginMoveWindow"/> + PointerPressed="BeginMoveWindow" + PointerMoved="MoveWindow" + PointerReleased="EndMoveWindow"/> diff --git a/src/Views/BranchCompare.axaml.cs b/src/Views/BranchCompare.axaml.cs index 717b0812..9d506ef3 100644 --- a/src/Views/BranchCompare.axaml.cs +++ b/src/Views/BranchCompare.axaml.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Input; @@ -22,7 +23,29 @@ namespace SourceGit.Views private void BeginMoveWindow(object sender, PointerPressedEventArgs e) { - BeginMoveDrag(e); + if (e.ClickCount != 2) + _pressedTitleBar = true; + } + + private void MoveWindow(object sender, PointerEventArgs e) + { + if (!_pressedTitleBar) + return; + + var visual = (Visual)e.Source; + BeginMoveDrag(new PointerPressedEventArgs( + e.Source, + e.Pointer, + visual, + e.GetPosition(visual), + e.Timestamp, + new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed), + e.KeyModifiers)); + } + + private void EndMoveWindow(object sender, PointerReleasedEventArgs e) + { + _pressedTitleBar = false; } private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e) @@ -43,5 +66,7 @@ namespace SourceGit.Views e.Handled = true; } + + private bool _pressedTitleBar = false; } } diff --git a/src/Views/FileHistories.axaml b/src/Views/FileHistories.axaml index 9c3b1fd9..bcbc02b0 100644 --- a/src/Views/FileHistories.axaml +++ b/src/Views/FileHistories.axaml @@ -26,7 +26,9 @@ Background="{DynamicResource Brush.TitleBar}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}" DoubleTapped="MaximizeOrRestoreWindow" - PointerPressed="BeginMoveWindow"/> + PointerPressed="BeginMoveWindow" + PointerMoved="MoveWindow" + PointerReleased="EndMoveWindow"/> diff --git a/src/Views/FileHistories.axaml.cs b/src/Views/FileHistories.axaml.cs index c1a534ef..2c45ab9f 100644 --- a/src/Views/FileHistories.axaml.cs +++ b/src/Views/FileHistories.axaml.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Input; @@ -22,7 +23,31 @@ namespace SourceGit.Views private void BeginMoveWindow(object sender, PointerPressedEventArgs e) { - BeginMoveDrag(e); + if (e.ClickCount != 2) + _pressedTitleBar = true; } + + private void MoveWindow(object sender, PointerEventArgs e) + { + if (!_pressedTitleBar) + return; + + var visual = (Visual)e.Source; + BeginMoveDrag(new PointerPressedEventArgs( + e.Source, + e.Pointer, + visual, + e.GetPosition(visual), + e.Timestamp, + new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed), + e.KeyModifiers)); + } + + private void EndMoveWindow(object sender, PointerReleasedEventArgs e) + { + _pressedTitleBar = false; + } + + private bool _pressedTitleBar = false; } } diff --git a/src/Views/Launcher.axaml b/src/Views/Launcher.axaml index 496fec4b..9da3fe76 100644 --- a/src/Views/Launcher.axaml +++ b/src/Views/Launcher.axaml @@ -31,7 +31,9 @@ Background="{DynamicResource Brush.TitleBar}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}" DoubleTapped="OnTitleBarDoubleTapped" - PointerPressed="BeginMoveWindow"/> + PointerPressed="BeginMoveWindow" + PointerMoved="MoveWindow" + PointerReleased="EndMoveWindow"/> @@ -81,10 +83,9 @@ diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 96f006d4..60ac7d97 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -172,7 +172,28 @@ namespace SourceGit.Views private void BeginMoveWindow(object sender, PointerPressedEventArgs e) { if (e.ClickCount != 2) - BeginMoveDrag(e); + _pressedTitleBar = true; + } + + private void MoveWindow(object sender, PointerEventArgs e) + { + if (!_pressedTitleBar) + return; + + var visual = (Visual)e.Source; + BeginMoveDrag(new PointerPressedEventArgs( + e.Source, + e.Pointer, + visual, + e.GetPosition(visual), + e.Timestamp, + new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed), + e.KeyModifiers)); + } + + private void EndMoveWindow(object sender, PointerReleasedEventArgs e) + { + _pressedTitleBar = false; } private void ScrollTabs(object sender, PointerWheelEventArgs e) @@ -236,26 +257,26 @@ namespace SourceGit.Views private void OnPointerPressedTab(object sender, PointerPressedEventArgs e) { _pressedTab = true; - _startDrag = false; + _startDragTab = false; _pressedTabPosition = e.GetPosition(sender as Border); } private void OnPointerReleasedTab(object sender, PointerReleasedEventArgs e) { _pressedTab = false; - _startDrag = false; + _startDragTab = false; } private void OnPointerMovedOverTab(object sender, PointerEventArgs e) { - if (_pressedTab && !_startDrag && sender is Border border) + if (_pressedTab && !_startDragTab && sender is Border border) { var delta = e.GetPosition(border) - _pressedTabPosition; var sizeSquired = delta.X * delta.X + delta.Y * delta.Y; if (sizeSquired < 64) return; - _startDrag = true; + _startDragTab = true; var data = new DataObject(); data.Set("MovedTab", border.DataContext); @@ -277,7 +298,7 @@ namespace SourceGit.Views } _pressedTab = false; - _startDrag = false; + _startDragTab = false; e.Handled = true; } @@ -304,8 +325,9 @@ namespace SourceGit.Views OnPopupCancel(sender, e); } + private bool _pressedTitleBar = false; private bool _pressedTab = false; private Point _pressedTabPosition = new Point(); - private bool _startDrag = false; + private bool _startDragTab = false; } }