Skip to content

Portable Tool for an Ideal Windows Setup

fix title bar double-click state & ref

Greedeksd6e47008ce7b
diff --git a/.Source/GTweak/Styles/Buttons/Buttons.xaml b/.Source/GTweak/Styles/Buttons/Buttons.xaml
index 45a164c1..38792823 100644
--- a/.Source/GTweak/Styles/Buttons/Buttons.xaml
+++ b/.Source/GTweak/Styles/Buttons/Buttons.xaml
@@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
- <Style x:Key="TitleButtonBase" TargetType="Button">
+ <Style x:Key="TitleButtonBase" TargetType="Control">
<Setter Property="Width" Value="30"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Background" Value="Transparent"/>
@@ -17,50 +17,7 @@
<Setter Property="IsTabStop" Value="False"/>
</Style>
- <Style x:Key="TitleButtonSettings" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="Button">
- <Grid>
- <Border x:Name="BackgroundBorder" Background="Transparent" CornerRadius="4"/>
- <Border x:Name="Icon" Width="16" Height="16" Background="{StaticResource Brush_Inactive}" RenderTransformOrigin="0.5,0.5">
- <Border.RenderTransform>
- <RotateTransform x:Name="RotateTransformSettings" Angle="0"/>
- </Border.RenderTransform>
- </Border>
- </Grid>
- <ControlTemplate.Triggers>
- <Trigger Property="IsEnabled" Value="True">
- <Setter TargetName="Icon" Property="OpacityMask">
- <Setter.Value>
- <ImageBrush ImageSource="{StaticResource Icon_Settings}" />
- </Setter.Value>
- </Setter>
- </Trigger>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="Icon" Property="Background" Value="{StaticResource Brush_Accent}"/>
- </Trigger>
- <Trigger Property="IsPressed" Value="True">
- <Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource Brush_TitleBtnBG_Pressed}"/>
- </Trigger>
- <EventTrigger RoutedEvent="Button.Click">
- <BeginStoryboard>
- <Storyboard Timeline.DesiredFrameRate="120">
- <DoubleAnimation Storyboard.TargetName="RotateTransformSettings" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:0.5" FillBehavior="Stop">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-
- <Style x:Key="TitleButtonMinimize" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
+ <Style x:Key="ButtonMinimize" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
@@ -88,8 +45,7 @@
</Setter>
</Style>
-
- <Style x:Key="TitleButtonMaximize" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
+ <Style x:Key="ButtonMaximize" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
@@ -124,7 +80,7 @@
</Setter>
</Style>
- <Style x:Key="TitleButtonClose" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
+ <Style x:Key="ButtonClose" TargetType="Button" BasedOn="{StaticResource TitleButtonBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
diff --git a/.Source/GTweak/Styles/Buttons/ToggleButtons.xaml b/.Source/GTweak/Styles/Buttons/ToggleButtons.xaml
index 35bc455e..36b23c30 100644
--- a/.Source/GTweak/Styles/Buttons/ToggleButtons.xaml
+++ b/.Source/GTweak/Styles/Buttons/ToggleButtons.xaml
@@ -1,19 +1,102 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- <Style x:Key="TglThemeSwitch" TargetType="{x:Type ToggleButton}">
- <Setter Property="Width" Value="30"/>
- <Setter Property="Height" Value="30"/>
- <Setter Property="Background" Value="Transparent"/>
- <Setter Property="BorderThickness" Value="0"/>
- <Setter Property="Padding" Value="0"/>
- <Setter Property="HorizontalContentAlignment" Value="Center"/>
- <Setter Property="VerticalContentAlignment" Value="Center"/>
+ <Style x:Key="TglIconBase" TargetType="{x:Type ToggleButton}">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Focusable" Value="False"/>
<Setter Property="IsTabStop" Value="False"/>
+ <Setter Property="RenderTransformOrigin" Value=".5,.5"/>
+ <Setter Property="RenderTransform">
+ <Setter.Value>
+ <ScaleTransform ScaleX="1" ScaleY="1" />
+ </Setter.Value>
+ </Setter>
+ <Style.Triggers>
+ <EventTrigger RoutedEvent="Button.MouseEnter">
+ <EventTrigger.Actions>
+ <BeginStoryboard>
+ <Storyboard Timeline.DesiredFrameRate="120">
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="1" To="1.05" Duration="0:0:0.1">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1" To="1.05" Duration="0:0:0.1">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </EventTrigger.Actions>
+ </EventTrigger>
+ <EventTrigger RoutedEvent="Button.MouseLeave">
+ <EventTrigger.Actions>
+ <BeginStoryboard>
+ <Storyboard Timeline.DesiredFrameRate="120">
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="1.05" To="1" Duration="0:0:0.1">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1.05" To="1" Duration="0:0:0.1">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </EventTrigger.Actions>
+ </EventTrigger>
+ </Style.Triggers>
+ </Style>
+
+ <Style x:Key="TglSettings" TargetType="ToggleButton" BasedOn="{StaticResource TitleButtonBase}">
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="ToggleButton">
+ <Grid>
+ <Border x:Name="BackgroundBorder" Background="Transparent" CornerRadius="4"/>
+ <Border x:Name="Icon" Width="16" Height="16" Background="{StaticResource Brush_Inactive}" RenderTransformOrigin="0.5,0.5">
+ <Border.RenderTransform>
+ <RotateTransform x:Name="RotateTransformSettings" Angle="0"/>
+ </Border.RenderTransform>
+ </Border>
+ </Grid>
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsEnabled" Value="True">
+ <Setter TargetName="Icon" Property="OpacityMask">
+ <Setter.Value>
+ <ImageBrush ImageSource="{StaticResource Icon_Settings}" />
+ </Setter.Value>
+ </Setter>
+ </Trigger>
+ <Trigger Property="IsMouseOver" Value="True">
+ <Setter TargetName="Icon" Property="Background" Value="{StaticResource Brush_Accent}"/>
+ </Trigger>
+ <Trigger Property="IsPressed" Value="True">
+ <Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource Brush_TitleBtnBG_Pressed}"/>
+ </Trigger>
+ <EventTrigger RoutedEvent="ToggleButton.Click">
+ <BeginStoryboard>
+ <Storyboard Timeline.DesiredFrameRate="120">
+ <DoubleAnimation Storyboard.TargetName="RotateTransformSettings" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:0.5" FillBehavior="Stop">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </EventTrigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+
+ <Style x:Key="TglThemeSwitch" TargetType="ToggleButton" BasedOn="{StaticResource TitleButtonBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
@@ -81,18 +164,7 @@
</Setter>
</Style>
- <Style x:Key="TglVolume" TargetType="{x:Type ToggleButton}">
- <Setter Property="Cursor" Value="Hand"/>
- <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
- <Setter Property="FocusVisualStyle" Value="{x:Null}" />
- <Setter Property="Focusable" Value="False"/>
- <Setter Property="IsTabStop" Value="False"/>
- <Setter Property="RenderTransformOrigin" Value=".5,.5"/>
- <Setter Property="RenderTransform">
- <Setter.Value>
- <ScaleTransform ScaleX="1" ScaleY="1" />
- </Setter.Value>
- </Setter>
+ <Style x:Key="TglVolume" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource TglIconBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
@@ -142,58 +214,9 @@
</ControlTemplate>
</Setter.Value>
</Setter>
- <Style.Triggers>
- <EventTrigger RoutedEvent="Button.MouseEnter">
- <EventTrigger.Actions>
- <BeginStoryboard>
- <Storyboard Timeline.DesiredFrameRate="120">
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="1" To="1.05" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1" To="1.05" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger.Actions>
- </EventTrigger>
- <EventTrigger RoutedEvent="Button.MouseLeave">
- <EventTrigger.Actions>
- <BeginStoryboard>
- <Storyboard Timeline.DesiredFrameRate="120">
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="1.05" To="1" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1.05" To="1" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger.Actions>
- </EventTrigger>
- </Style.Triggers>
</Style>
- <Style x:Key="TglVision" TargetType="{x:Type ToggleButton}">
- <Setter Property="Cursor" Value="Hand"/>
- <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
- <Setter Property="FocusVisualStyle" Value="{x:Null}" />
- <Setter Property="Focusable" Value="False"/>
- <Setter Property="IsTabStop" Value="False"/>
- <Setter Property="RenderTransformOrigin" Value=".5,.5"/>
- <Setter Property="RenderTransform">
- <Setter.Value>
- <ScaleTransform ScaleX="1" ScaleY="1" />
- </Setter.Value>
- </Setter>
+ <Style x:Key="TglVision" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource TglIconBase}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
@@ -243,44 +266,6 @@
</ControlTemplate>
</Setter.Value>
</Setter>
- <Style.Triggers>
- <EventTrigger RoutedEvent="Button.MouseEnter">
- <EventTrigger.Actions>
- <BeginStoryboard>
- <Storyboard Timeline.DesiredFrameRate="120">
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="1" To="1.05" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1" To="1.05" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger.Actions>
- </EventTrigger>
- <EventTrigger RoutedEvent="Button.MouseLeave">
- <EventTrigger.Actions>
- <BeginStoryboard>
- <Storyboard Timeline.DesiredFrameRate="120">
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" From="1.05" To="1" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" From="1.05" To="1" Duration="0:0:0.1">
- <DoubleAnimation.EasingFunction>
- <CubicEase/>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger.Actions>
- </EventTrigger>
- </Style.Triggers>
</Style>
<Style x:Key="TglPackagesStyle" TargetType="{x:Type ToggleButton}">
diff --git a/.Source/GTweak/Windows/MainWindow.xaml b/.Source/GTweak/Windows/MainWindow.xaml
index 39dc82a9..67c3e22c 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml
+++ b/.Source/GTweak/Windows/MainWindow.xaml
@@ -76,12 +76,12 @@
</TextBlock>
</Grid>
- <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"/>
- <Button x:Name="ButtonMaximize" Style="{StaticResource TitleButtonMaximize}" Margin="0,0,0,2" Click="TitleButton_Click"/>
- <Button x:Name="ButtonClose" Style="{StaticResource TitleButtonClose}" Margin="0,0,5,2" Click="TitleButton_Click"/>
+ <StackPanel x:Name="TitleButtonsPanel" Grid.Column="2" Margin="0,0,0,2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
+ <ToggleButton x:Name="TglButtonTheme" IsChecked="{Binding StateButtonTheme}" Style="{StaticResource TglThemeSwitch}" Click="TitleButton_Click"/>
+ <ToggleButton x:Name="TglButtonSettings" IsChecked="False" Style="{StaticResource TglSettings}" Margin="0,0,10,0" Click="TitleButton_Click"/>
+ <Button x:Name="ButtonMinimize" Style="{StaticResource ButtonMinimize}" Click="TitleButton_Click"/>
+ <Button x:Name="ButtonMaximize" Style="{StaticResource ButtonMaximize}" Click="TitleButton_Click"/>
+ <Button x:Name="ButtonClose" Style="{StaticResource ButtonClose}" Margin="0,0,5,0" Click="TitleButton_Click"/>
</StackPanel>
</Grid>
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index c2237011..47315fc1 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -39,7 +39,7 @@ namespace GTweak.Windows
}
private const int WM_NCLBUTTONDOWN = 0xA1, HTCAPTION = 0x2;
- private bool _settingsOpen = false, _ignoreMouseClick = false;
+ private bool _ignoreMouseClick = false;
private RadioButton _activeBtnCache;
public MainWindow()
@@ -69,17 +69,9 @@ namespace GTweak.Windows
Top = area.Top + (area.Height - Height) / 2;
}
- private void AnimateSettings()
- {
- TranslateTransform transform = (TranslateTransform)SettingsPanel.RenderTransform;
- double toX = _settingsOpen ? 400 : 0;
- _settingsOpen = !_settingsOpen;
- transform.BeginAnimation(TranslateTransform.XProperty, FactoryAnimation.CreateIn(transform.X, toX, 0.5, useCubicEase: true));
- }
-
- private void HandleWindowState() => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
-
#region TitleBar
+ private void HandleWindowState(bool isMinimized = false) => WindowState = isMinimized ? WindowState.Minimized : WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
+
private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e?.ChangedButton == MouseButton.Left)
@@ -98,18 +90,18 @@ namespace GTweak.Windows
}
}
- _ignoreMouseClick = true;
- TitleButtonsPanel.IsHitTestVisible = false;
+ Dispatcher.BeginInvoke((Action)(() => { _ignoreMouseClick = true; TitleButtonsPanel.IsHitTestVisible = false; }));
if (e?.ClickCount == 2)
{
HandleWindowState();
- return;
}
-
- IntPtr hwnd = new WindowInteropHelper(this).Handle;
- ReleaseCapture();
- SendMessage(hwnd, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero);
+ else
+ {
+ IntPtr hwnd = new WindowInteropHelper(this).Handle;
+ ReleaseCapture();
+ SendMessage(hwnd, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero);
+ }
Dispatcher.BeginInvoke((Action)(() => { _ignoreMouseClick = false; TitleButtonsPanel.IsHitTestVisible = true; }));
}
@@ -126,12 +118,13 @@ namespace GTweak.Windows
HandleWindowState();
break;
case nameof(ButtonMinimize):
- WindowState = WindowState.Minimized;
+ HandleWindowState(true);
break;
- case nameof(ButtonSettings):
- AnimateSettings();
+ case nameof(TglButtonSettings):
+ TranslateTransform transform = (TranslateTransform)SettingsPanel.RenderTransform;
+ transform.BeginAnimation(TranslateTransform.XProperty, FactoryAnimation.CreateIn(transform.X, TglButtonSettings.IsChecked.Value ? 0 : 400, 0.5, useCubicEase: true));
break;
- case nameof(ButtonTheme):
+ case nameof(TglButtonTheme):
SettingsEngine.SelfReboot();
Visibility = Visibility.Collapsed;
break;
diff --git a/.Source/GTweak/Windows/NotificationWindow.xaml b/.Source/GTweak/Windows/NotificationWindow.xaml
index a498f388..27ca89c9 100644
--- a/.Source/GTweak/Windows/NotificationWindow.xaml
+++ b/.Source/GTweak/Windows/NotificationWindow.xaml
@@ -17,7 +17,7 @@
<Grid Grid.Row="0">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
- <Button x:Name="ButtonClose" Style="{StaticResource TitleButtonClose}" Margin="0,2.5,2.5,0" HorizontalAlignment="Right" VerticalAlignment="Center" PreviewMouseLeftButtonUp="ButtonClose_PreviewMouseLeftButtonUp"/>
+ <Button x:Name="ButtonClose" Style="{StaticResource ButtonClose}" Margin="0,2.5,2.5,0" HorizontalAlignment="Right" VerticalAlignment="Center" PreviewMouseLeftButtonUp="ButtonClose_PreviewMouseLeftButtonUp"/>
</StackPanel>
<DockPanel VerticalAlignment="Center" HorizontalAlignment="Left" LastChildFill="True">