Skip to content

Portable Tool for an Ideal Windows Setup

fix titlebar button states via WM_NCLBUTTONDOWN & ref deb v5.4.3

Greedeks2ff83fe48cdc
diff --git a/.Source/GTweak/Core/Base/ViewModelPageBase.cs b/.Source/GTweak/Core/Base/ViewModelPageBase.cs
index 003e73b7..dcd0e8b2 100644
--- a/.Source/GTweak/Core/Base/ViewModelPageBase.cs
+++ b/.Source/GTweak/Core/Base/ViewModelPageBase.cs
@@ -22,7 +22,7 @@ namespace GTweak.Core.Base
public ObservableCollection<TModel> Toggles { get; private set; }
public TModel this[string name] => Toggles.FirstOrDefault(d => d.Name == name);
- protected abstract Dictionary<string, object> GetControlStates();
+ protected abstract IReadOnlyDictionary<string, object> GetControlStates();
protected abstract void Analyze(TTweaksClass tweaks);
protected ViewModelPageBase()
diff --git a/.Source/GTweak/Core/ViewModel/ConfidentialityViewModel.cs b/.Source/GTweak/Core/ViewModel/ConfidentialityViewModel.cs
index f9f70dad..b1316e6e 100644
--- a/.Source/GTweak/Core/ViewModel/ConfidentialityViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/ConfidentialityViewModel.cs
@@ -7,7 +7,7 @@ namespace GTweak.Core.ViewModel
{
internal class ConfidentialityViewModel : ViewModelPageBase<ConfidentialityModel, ConfidentialityTweaks>
{
- protected override Dictionary<string, object> GetControlStates() => ConfidentialityTweaks.ControlStates;
+ protected override IReadOnlyDictionary<string, object> GetControlStates() => ConfidentialityTweaks.ControlStates;
protected override void Analyze(ConfidentialityTweaks tweaks) => tweaks?.AnalyzeAndUpdate();
}
diff --git a/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs b/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs
index 104bc83e..9d837032 100644
--- a/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/InterfaceViewModel.cs
@@ -14,7 +14,7 @@ namespace GTweak.Core.ViewModel
public Visibility Win11FeatureAvailable => HardwareData.OS.IsWin11 && HardwareData.OS.Build.CompareTo(22621.2361m) >= 0 ? Visibility.Visible : Visibility.Collapsed;
public bool IsBlockWithoutLicense => WinLicenseHandler.IsWindowsActivated;
- protected override Dictionary<string, object> GetControlStates() => InterfaceTweaks.ControlStates;
+ protected override IReadOnlyDictionary<string, object> GetControlStates() => InterfaceTweaks.ControlStates;
protected override void Analyze(InterfaceTweaks tweaks) => tweaks?.AnalyzeAndUpdate();
}
diff --git a/.Source/GTweak/Core/ViewModel/ServicesViewModel.cs b/.Source/GTweak/Core/ViewModel/ServicesViewModel.cs
index 94df4405..00ffda92 100644
--- a/.Source/GTweak/Core/ViewModel/ServicesViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/ServicesViewModel.cs
@@ -7,7 +7,7 @@ namespace GTweak.Core.ViewModel
{
internal class ServicesViewModel : ViewModelPageBase<ServicesModel, ServicesTweaks>
{
- protected override Dictionary<string, object> GetControlStates() => ServicesTweaks.ControlStates;
+ protected override IReadOnlyDictionary<string, object> GetControlStates() => ServicesTweaks.ControlStates;
protected override void Analyze(ServicesTweaks tweaks) => tweaks?.AnalyzeAndUpdate();
}
diff --git a/.Source/GTweak/Core/ViewModel/SystemViewModel.cs b/.Source/GTweak/Core/ViewModel/SystemViewModel.cs
index 0be4e609..933f9df6 100644
--- a/.Source/GTweak/Core/ViewModel/SystemViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/SystemViewModel.cs
@@ -11,7 +11,7 @@ namespace GTweak.Core.ViewModel
{
public Visibility RealtekSupportAvailable => HardwareData.VendorDetection.Realtek ? Visibility.Visible : Visibility.Collapsed;
- protected override Dictionary<string, object> GetControlStates() => SystemTweaks.ControlStates;
+ protected override IReadOnlyDictionary<string, object> GetControlStates() => SystemTweaks.ControlStates;
protected override void Analyze(SystemTweaks tweaks) => tweaks?.AnalyzeAndUpdate();
}
diff --git a/.Source/GTweak/Properties/AssemblyInfo.cs b/.Source/GTweak/Properties/AssemblyInfo.cs
index 89baa203..a3a7dd40 100644
--- a/.Source/GTweak/Properties/AssemblyInfo.cs
+++ b/.Source/GTweak/Properties/AssemblyInfo.cs
@@ -5,11 +5,11 @@ using System.Windows;
[assembly: AssemblyTitle("GTweak")]
[assembly: AssemblyDescription("Portable Tool for an Ideal Windows Setup")]
[assembly: AssemblyProduct("GTweak")]
-[assembly: AssemblyCopyright("© 2024-2026 Greedeks")]
+[assembly: AssemblyCopyright("� 2024-2026 Greedeks")]
[assembly: AssemblyTrademark("Greedeks")]
-[assembly: AssemblyInformationalVersion("Build: 5.4.2")]
-[assembly: AssemblyVersion("5.4.31.921")]
-[assembly: AssemblyFileVersion("5.4.31.921")]
+[assembly: AssemblyInformationalVersion("Build: 5.4.3")]
+[assembly: AssemblyVersion("5.4.19.279")]
+[assembly: AssemblyFileVersion("5.4.19.279")]
[assembly: ComVisible(false)]
diff --git a/.Source/GTweak/Properties/AssemblyInfo.tt b/.Source/GTweak/Properties/AssemblyInfo.tt
index 4053991d..ea3d94f1 100644
--- a/.Source/GTweak/Properties/AssemblyInfo.tt
+++ b/.Source/GTweak/Properties/AssemblyInfo.tt
@@ -22,7 +22,7 @@ using System.Windows;
[assembly: AssemblyMetadata("RepositoryType", "git")]
<#+
- private const string majorVersion = "Build: 5.4.2";
+ private const string majorVersion = "Build: 5.4.3";
private string GenerateVersion()
{
diff --git a/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
index 8cd11075..48027a99 100644
--- a/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
@@ -13,7 +13,7 @@ namespace GTweak.Utilities.Tweaks
{
internal sealed class ConfidentialityTweaks : FirewallManager
{
- internal static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
+ internal readonly static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
private readonly ControlWriterManager _сontrolWriter = new ControlWriterManager(ControlStates);
internal void AnalyzeAndUpdate()
diff --git a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
index 25cc9355..2bccb94e 100644
--- a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
@@ -13,7 +13,7 @@ namespace GTweak.Utilities.Tweaks
{
internal sealed class InterfaceTweaks
{
- internal static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
+ internal readonly static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
private readonly ControlWriterManager _сontrolWriter = new ControlWriterManager(ControlStates);
internal void AnalyzeAndUpdate()
diff --git a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
index d26a10c6..708a6c4e 100644
--- a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
@@ -12,7 +12,7 @@ namespace GTweak.Utilities.Tweaks
{
internal sealed class ServicesTweaks : FirewallManager
{
- internal static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
+ internal readonly static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
private readonly ControlWriterManager _сontrolWriter = new ControlWriterManager(ControlStates);
private readonly (string Normal, string Block)[] _updateFiles = new[] { PathLocator.Executable.UsoClient, PathLocator.Executable.WorkerCore, PathLocator.Executable.WuauClient, PathLocator.Executable.WaaSMedic, PathLocator.Executable.MoNotificationUx };
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index 609723c4..778e348c 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -32,7 +32,7 @@ namespace GTweak.Utilities.Tweaks
private static bool _isNetshState = false, _isBluetoothStatus = false, _isTickState = false;
private static string _currentPowerGuid = string.Empty;
- internal static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
+ internal readonly static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
private readonly ControlWriterManager _сontrolWriter = new ControlWriterManager(ControlStates);
public SystemTweaks() => _currentPowerGuid = RegistryHelp.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes", "ActivePowerScheme", string.Empty);
diff --git a/.Source/GTweak/Windows/MainWindow.xaml b/.Source/GTweak/Windows/MainWindow.xaml
index ffd1faf7..4acb40ba 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml
+++ b/.Source/GTweak/Windows/MainWindow.xaml
@@ -20,7 +20,7 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
- <Grid x:Name="TitleBar" Grid.Row="0" Background="Transparent" MouseDown="TitleBar_MouseDown" MouseMove="TitleBar_MouseMove" MouseLeftButtonUp="TitleBar_MouseLeftButtonUp" PreviewMouseLeftButtonDown="TitleBar_PreviewMouseLeftButtonDown">
+ <Grid x:Name="TitleBar" Grid.Row="0" Background="Transparent" MouseLeftButtonDown="TitleBar_MouseLeftButtonDown">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
@@ -67,7 +67,7 @@
</TextBlock>
</Grid>
- <StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
+ <StackPanel x:Name="TitleButtonsPanel" Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
<ToggleButton x:Name="ButtonTheme" IsChecked="{Binding StateButtonTheme}" Style="{StaticResource TglThemeSwitch}" Margin="0,0,0,2" Click="TitleButton_Click"/>
<Button x:Name="ButtonSettings" Style="{StaticResource TitleButtonSettings}" Margin="0,0,10,2" Click="TitleButton_Click"/>
<Button x:Name="ButtonMinimize" Style="{StaticResource TitleButtonMinimize}" Margin="0,0,0,2" Click="TitleButton_Click"/>
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index 20aa2994..25049675 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -1,9 +1,11 @@
using System;
using System.Diagnostics;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
+using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using GTweak.Utilities.Animation;
@@ -15,10 +17,14 @@ namespace GTweak.Windows
{
public partial class MainWindow : FluentWindow
{
- private bool _settingsOpen = false, _draggingFromMaximized = false, _ignoreMouseClick = false;
- private Point? _lastNormalPosition;
- private Size? _lastNormalSize;
- private Point _mouseDownWindowPoint;
+ [DllImport("user32.dll")]
+ private static extern bool ReleaseCapture();
+
+ [DllImport("user32.dll")]
+ private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
+
+ private const int WM_NCLBUTTONDOWN = 0xA1, HTCAPTION = 0x2;
+ private bool _settingsOpen = false, _ignoreMouseClick = false;
public MainWindow()
{
@@ -35,85 +41,11 @@ namespace GTweak.Windows
}
#region TitleBar
- private void HandleWindowState()
- {
- if (WindowState == WindowState.Normal)
- {
- _lastNormalPosition = new Point(Left, Top);
- _lastNormalSize = new Size(Width, Height);
- WindowState = WindowState.Maximized;
- }
- else
- {
- WindowState = WindowState.Normal;
- }
- }
-
- private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if (e?.ChangedButton == MouseButton.Left && e?.ClickCount != 2)
- {
- if (WindowState == WindowState.Maximized)
- {
- if (e != null)
- {
- _mouseDownWindowPoint = e.GetPosition(this);
- _draggingFromMaximized = true;
- }
- }
- else
- {
- DragMove();
- }
- }
- }
+ private void HandleWindowState() => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
- private void TitleBar_MouseMove(object sender, MouseEventArgs e)
+ private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
- if (_draggingFromMaximized)
- {
- if (e?.LeftButton != MouseButtonState.Pressed)
- {
- _draggingFromMaximized = false;
- return;
- }
-
- Point currentScreen = PointToScreen(e.GetPosition(this));
- Vector delta = currentScreen - PointToScreen(_mouseDownWindowPoint);
-
- if (Math.Abs(delta.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(delta.Y) > SystemParameters.MinimumVerticalDragDistance)
- {
- _draggingFromMaximized = false;
-
- Size restoreSize = _lastNormalSize ?? new Size(RestoreBounds.Width, RestoreBounds.Height);
- double restoreWidth = restoreSize.Width;
- double restoreHeight = restoreSize.Height;
-
- double relX = ActualWidth > 0 ? _mouseDownWindowPoint.X / ActualWidth : 0.5;
-
- WindowState = WindowState.Normal;
- Width = restoreWidth;
- Height = restoreHeight;
-
- double left = currentScreen.X - restoreWidth * relX;
- double top = currentScreen.Y - _mouseDownWindowPoint.Y;
-
- left = Math.Max(0, Math.Min(Math.Max(0, SystemParameters.PrimaryScreenWidth - restoreWidth), left));
- top = Math.Max(0, Math.Min(Math.Max(0, SystemParameters.PrimaryScreenHeight - restoreHeight), top));
-
- Left = left;
- Top = top;
-
- Dispatcher.BeginInvoke((Action)(() => { DragMove(); }));
- }
- }
- }
-
- private void TitleBar_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) => _draggingFromMaximized = false;
-
- private async void TitleBar_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (e?.ChangedButton == MouseButton.Left && e?.ClickCount == 2)
+ if (e?.ChangedButton == MouseButton.Left)
{
if (e?.OriginalSource is DependencyObject source)
{
@@ -130,23 +62,19 @@ namespace GTweak.Windows
}
_ignoreMouseClick = true;
- HandleWindowState();
+ TitleButtonsPanel.IsHitTestVisible = false;
- if (WindowState == WindowState.Maximized && _lastNormalPosition.HasValue && _lastNormalSize.HasValue)
+ if (e?.ClickCount == 2)
{
- Point pos = _lastNormalPosition.Value;
- Size sz = _lastNormalSize.Value;
-
- Left = pos.X;
- Top = pos.Y;
- Width = sz.Width;
- Height = sz.Height;
+ HandleWindowState();
+ return;
}
- await Task.Delay(100).ConfigureAwait(false);
- _ignoreMouseClick = false;
+ IntPtr hwnd = new WindowInteropHelper(this).Handle;
+ ReleaseCapture();
+ SendMessage(hwnd, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero);
- e.Handled = true;
+ Dispatcher.BeginInvoke((Action)(() => { _ignoreMouseClick = false; TitleButtonsPanel.IsHitTestVisible = true; }));
}
}