Skip to content

Portable Tool for an Ideal Windows Setup

fix TitleBar ignore next MouseUp after window maximize/restore to prevent content click

Greedeks267e19c2744e
diff --git a/.Source/GTweak/Styles/Buttons/Buttons.xaml b/.Source/GTweak/Styles/Buttons/Buttons.xaml
index ca93f3b3..47e2f9d9 100644
--- a/.Source/GTweak/Styles/Buttons/Buttons.xaml
+++ b/.Source/GTweak/Styles/Buttons/Buttons.xaml
@@ -1,5 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
<Style x:Key="TitleButtonBase" TargetType="Button">
<Setter Property="Width" Value="30"/>
diff --git a/.Source/GTweak/Windows/MainWindow.xaml b/.Source/GTweak/Windows/MainWindow.xaml
index 0e6e7f29..617bf78d 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml
+++ b/.Source/GTweak/Windows/MainWindow.xaml
@@ -264,7 +264,7 @@
</ScrollViewer>
</Border>
</Grid>
- <ContentControl Grid.Column="1" Content="{Binding CurrentView}" IsTabStop="False" KeyboardNavigation.TabNavigation="None" Margin="5,5,0,5"/>
+ <ContentControl Grid.Column="1" Content="{Binding CurrentView}" IsTabStop="False" KeyboardNavigation.TabNavigation="None" Margin="5,5,0,5" PreviewMouseLeftButtonUp="ContentControl_PreviewMouseLeftButtonUp"/>
</Grid>
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index ce106a53..6d232ea4 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -5,6 +5,7 @@ using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
+using System.Windows.Threading;
using GTweak.Utilities.Animation;
using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
@@ -14,11 +15,10 @@ namespace GTweak.Windows
{
public partial class MainWindow : FluentWindow
{
- private bool _settingsOpen = false, _prepareDragFromMax = false;
+ private bool _settingsOpen = false, _draggingFromMaximized = false, _ignoreMouseClick = false;
private Point? _lastNormalPosition;
private Size? _lastNormalSize;
private Point _mouseDownWindowPoint;
-
public MainWindow()
{
InitializeComponent();
@@ -34,7 +34,7 @@ namespace GTweak.Windows
}
#region TitleBar
- private void HandleWindowState()
+ private async void HandleWindowState()
{
if (WindowState == WindowState.Normal)
{
@@ -46,9 +46,10 @@ namespace GTweak.Windows
{
WindowState = WindowState.Normal;
}
- }
- private double Clamp(double value, double min, double max) => Math.Max(min, Math.Min(max, value));
+ await Task.Delay(100).ConfigureAwait(false);
+ _ignoreMouseClick = false;
+ }
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
@@ -60,7 +61,7 @@ namespace GTweak.Windows
if (WindowState == WindowState.Maximized)
{
_mouseDownWindowPoint = e.GetPosition(this);
- _prepareDragFromMax = true;
+ _draggingFromMaximized = true;
}
else
{
@@ -70,14 +71,14 @@ namespace GTweak.Windows
private void TitleBar_MouseMove(object sender, MouseEventArgs e)
{
- if (!_prepareDragFromMax)
+ if (!_draggingFromMaximized)
{
return;
}
if (e.LeftButton != MouseButtonState.Pressed)
{
- _prepareDragFromMax = false;
+ _draggingFromMaximized = false;
return;
}
@@ -87,7 +88,7 @@ namespace GTweak.Windows
if (Math.Abs(delta.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(delta.Y) > SystemParameters.MinimumVerticalDragDistance)
{
- _prepareDragFromMax = false;
+ _draggingFromMaximized = false;
Size restoreSize = _lastNormalSize ?? new Size(RestoreBounds.Width, RestoreBounds.Height);
double restoreWidth = restoreSize.Width;
@@ -104,8 +105,8 @@ namespace GTweak.Windows
double screenW = SystemParameters.PrimaryScreenWidth;
double screenH = SystemParameters.PrimaryScreenHeight;
- left = Clamp(left, 0, Math.Max(0, screenW - restoreWidth));
- top = Clamp(top, 0, Math.Max(0, screenH - restoreHeight));
+ left = Math.Max(0, Math.Min(Math.Max(0, screenW - restoreWidth), left));
+ top = Math.Max(0, Math.Min(Math.Max(0, screenH - restoreHeight), top));
Left = left;
Top = top;
@@ -114,7 +115,7 @@ namespace GTweak.Windows
}
}
- private void TitleBar_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => _prepareDragFromMax = false;
+ private void TitleBar_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => _draggingFromMaximized = false;
private void TitleBar_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
@@ -137,6 +138,8 @@ namespace GTweak.Windows
}
}
+ _ignoreMouseClick = true;
+
bool wasMax = WindowState == WindowState.Maximized;
HandleWindowState();
@@ -155,6 +158,7 @@ namespace GTweak.Windows
}));
}
+
e.Handled = true;
}
@@ -230,6 +234,14 @@ namespace GTweak.Windows
Dispatcher.Invoke(() => new UpdateWindow().ShowDialog());
}
+ private void ContentControl_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+ {
+ if (_ignoreMouseClick)
+ {
+ e.Handled = true;
+ }
+ }
+
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
(double screenWidth, double screenHeight) = (SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);