fix: begin drag was triggered when double click on the title bar

This commit is contained in:
leo 2024-06-13 17:55:22 +08:00
parent b77ed6520c
commit 762ec1f702
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
8 changed files with 119 additions and 16 deletions

View file

@ -28,7 +28,9 @@
Background="{DynamicResource Brush.TitleBar}" Background="{DynamicResource Brush.TitleBar}"
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}"
DoubleTapped="MaximizeOrRestoreWindow" DoubleTapped="MaximizeOrRestoreWindow"
PointerPressed="BeginMoveWindow"/> PointerPressed="BeginMoveWindow"
PointerMoved="MoveWindow"
PointerReleased="EndMoveWindow"/>
<!-- Caption Buttons (macOS) --> <!-- Caption Buttons (macOS) -->
<Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}"> <Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}">

View file

@ -343,7 +343,29 @@ namespace SourceGit.Views
private void BeginMoveWindow(object sender, PointerPressedEventArgs e) 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) protected override void OnClosed(EventArgs e)
@ -361,5 +383,7 @@ namespace SourceGit.Views
} }
e.Handled = true; e.Handled = true;
} }
private bool _pressedTitleBar = false;
} }
} }

View file

@ -28,7 +28,9 @@
Background="{DynamicResource Brush.TitleBar}" Background="{DynamicResource Brush.TitleBar}"
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}"
DoubleTapped="MaximizeOrRestoreWindow" DoubleTapped="MaximizeOrRestoreWindow"
PointerPressed="BeginMoveWindow"/> PointerPressed="BeginMoveWindow"
PointerMoved="MoveWindow"
PointerReleased="EndMoveWindow"/>
<!-- Caption Buttons (macOS) --> <!-- Caption Buttons (macOS) -->
<Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}"> <Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}">

View file

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
@ -22,7 +23,29 @@ namespace SourceGit.Views
private void BeginMoveWindow(object sender, PointerPressedEventArgs e) 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) private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
@ -43,5 +66,7 @@ namespace SourceGit.Views
e.Handled = true; e.Handled = true;
} }
private bool _pressedTitleBar = false;
} }
} }

View file

@ -26,7 +26,9 @@
Background="{DynamicResource Brush.TitleBar}" Background="{DynamicResource Brush.TitleBar}"
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
DoubleTapped="MaximizeOrRestoreWindow" DoubleTapped="MaximizeOrRestoreWindow"
PointerPressed="BeginMoveWindow"/> PointerPressed="BeginMoveWindow"
PointerMoved="MoveWindow"
PointerReleased="EndMoveWindow"/>
<!-- Caption Buttons (macOS) --> <!-- Caption Buttons (macOS) -->
<Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}"> <Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}">

View file

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
@ -22,7 +23,31 @@ namespace SourceGit.Views
private void BeginMoveWindow(object sender, PointerPressedEventArgs e) 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;
} }
} }

View file

@ -31,7 +31,9 @@
Background="{DynamicResource Brush.TitleBar}" Background="{DynamicResource Brush.TitleBar}"
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
DoubleTapped="OnTitleBarDoubleTapped" DoubleTapped="OnTitleBarDoubleTapped"
PointerPressed="BeginMoveWindow"/> PointerPressed="BeginMoveWindow"
PointerMoved="MoveWindow"
PointerReleased="EndMoveWindow"/>
<!-- Caption Buttons (macOS) --> <!-- Caption Buttons (macOS) -->
<Border Grid.Column="0" VerticalAlignment="Stretch" Margin="2,0,8,3" IsVisible="{OnPlatform False, macOS=True}"> <Border Grid.Column="0" VerticalAlignment="Stretch" Margin="2,0,8,3" IsVisible="{OnPlatform False, macOS=True}">
@ -81,10 +83,9 @@
<ScrollViewer Grid.Column="1" <ScrollViewer Grid.Column="1"
x:Name="launcherTabsScroller" x:Name="launcherTabsScroller"
HorizontalAlignment="Left"
HorizontalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"
DoubleTapped="OnTitleBarDoubleTapped"
PointerPressed="BeginMoveWindow"
PointerWheelChanged="ScrollTabs" PointerWheelChanged="ScrollTabs"
ScrollChanged="OnTabsScrollChanged"> ScrollChanged="OnTabsScrollChanged">
<StackPanel x:Name="launcherTabsBar" Orientation="Horizontal" SizeChanged="UpdateScrollIndicator"> <StackPanel x:Name="launcherTabsBar" Orientation="Horizontal" SizeChanged="UpdateScrollIndicator">

View file

@ -172,7 +172,28 @@ namespace SourceGit.Views
private void BeginMoveWindow(object sender, PointerPressedEventArgs e) private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
{ {
if (e.ClickCount != 2) 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) private void ScrollTabs(object sender, PointerWheelEventArgs e)
@ -236,26 +257,26 @@ namespace SourceGit.Views
private void OnPointerPressedTab(object sender, PointerPressedEventArgs e) private void OnPointerPressedTab(object sender, PointerPressedEventArgs e)
{ {
_pressedTab = true; _pressedTab = true;
_startDrag = false; _startDragTab = false;
_pressedTabPosition = e.GetPosition(sender as Border); _pressedTabPosition = e.GetPosition(sender as Border);
} }
private void OnPointerReleasedTab(object sender, PointerReleasedEventArgs e) private void OnPointerReleasedTab(object sender, PointerReleasedEventArgs e)
{ {
_pressedTab = false; _pressedTab = false;
_startDrag = false; _startDragTab = false;
} }
private void OnPointerMovedOverTab(object sender, PointerEventArgs e) 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 delta = e.GetPosition(border) - _pressedTabPosition;
var sizeSquired = delta.X * delta.X + delta.Y * delta.Y; var sizeSquired = delta.X * delta.X + delta.Y * delta.Y;
if (sizeSquired < 64) if (sizeSquired < 64)
return; return;
_startDrag = true; _startDragTab = true;
var data = new DataObject(); var data = new DataObject();
data.Set("MovedTab", border.DataContext); data.Set("MovedTab", border.DataContext);
@ -277,7 +298,7 @@ namespace SourceGit.Views
} }
_pressedTab = false; _pressedTab = false;
_startDrag = false; _startDragTab = false;
e.Handled = true; e.Handled = true;
} }
@ -304,8 +325,9 @@ namespace SourceGit.Views
OnPopupCancel(sender, e); OnPopupCancel(sender, e);
} }
private bool _pressedTitleBar = false;
private bool _pressedTab = false; private bool _pressedTab = false;
private Point _pressedTabPosition = new Point(); private Point _pressedTabPosition = new Point();
private bool _startDrag = false; private bool _startDragTab = false;
} }
} }