Skip to content

Commit

Permalink
Merge pull request #13 from unchihugo/enhancement-issue-#3-lock-keys-…
Browse files Browse the repository at this point in the history
…flyout

Add lock keys flyout and refactor animations
  • Loading branch information
unchihugo authored Nov 4, 2024
2 parents 1719870 + 74ed597 commit cb855b9
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 74 deletions.
6 changes: 6 additions & 0 deletions FluentFlyoutWPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<setting name="FlyoutAnimationEasingStyle" serializeAs="String">
<value>2</value>
</setting>
<setting name="LockKeysEnabled" serializeAs="String">
<value>False</value>
</setting>
<setting name="LockKeysDuration" serializeAs="String">
<value>2000</value>
</setting>
</FluentFlyout.Properties.Settings>
</userSettings>
</configuration>
4 changes: 4 additions & 0 deletions FluentFlyoutWPF/FluentFlyout.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<None Remove="Resources\FluentFlyout2.ico" />
<None Remove="Resources\FluentFlyoutDemo3.1.png" />
<None Remove="Resources\FluentFlyoutDemo4.1.png" />
<None Remove="Resources\FluentFlyoutDemo5.1.png" />
</ItemGroup>

<ItemGroup>
Expand All @@ -38,6 +39,9 @@
<Content Include="Resources\FluentFlyoutDemo4.1.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\FluentFlyoutDemo5.1.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
143 changes: 86 additions & 57 deletions FluentFlyoutWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
using System.Windows.Media.Imaging;
using Windows.Storage.Streams;
using MicaWPF.Controls;
using System.IO;
using System.Windows.Media.Animation;
using FluentFlyout;
using FluentFlyout.Properties;
using Microsoft.Win32;
using System.Reflection;
using System.Drawing;
using System.Windows.Controls;
using Wpf.Ui.Controls;
using Wpf.Ui.Appearance;
using FluentFlyout.Classes;
using MicaWPF.Core.Extensions;
using MicaWPF.Core.Services;
using Windows.UI.Composition;
using FluentFlyout.Windows;
using System.Windows.Input;


namespace FluentFlyoutWPF
Expand Down Expand Up @@ -54,6 +51,8 @@ public partial class MainWindow : MicaWindow
private NextUpWindow? nextUpWindow = null; // to prevent multiple instances of NextUpWindow
private string currentTitle = ""; // to prevent NextUpWindow from showing the same song

private LockWindow lockWindow;

public MainWindow()
{
WindowHelper.SetNoActivate(this); // prevents some fullscreen apps from minimizing
Expand Down Expand Up @@ -120,51 +119,61 @@ public EasingFunctionBase getEasingStyle(bool easeOut)
return easingStyle;
}

public void OpenAnimation(MicaWindow window)
public void OpenAnimation(MicaWindow window, bool alwaysBottom = false)
{

var eventTriggers = window.Triggers[0] as EventTrigger;
var beginStoryboard = eventTriggers.Actions[0] as BeginStoryboard;
var storyboard = beginStoryboard.Storyboard;

DoubleAnimation moveAnimation = (DoubleAnimation)storyboard.Children[0];
_position = Settings.Default.Position;
if (_position == 0)

if (alwaysBottom == false)
{
window.Left = 16;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height + 4;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 16;
_position = Settings.Default.Position;
if (_position == 0)
{
window.Left = 16;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height + 4;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 16;
}
else if (_position == 1)
{
window.Left = SystemParameters.WorkArea.Width / 2 - window.Width / 2;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 60;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 80;
}
else if (_position == 2)
{
window.Left = SystemParameters.WorkArea.Width - window.Width - 16;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height + 4;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 16;
}
else if (_position == 3)
{
window.Left = 16;
moveAnimation.From = -4;
moveAnimation.To = 16;
}
else if (_position == 4)
{
window.Left = SystemParameters.WorkArea.Width / 2 - window.Width / 2;
moveAnimation.From = -4;
moveAnimation.To = 16;
}
else if (_position == 5)
{
window.Left = SystemParameters.WorkArea.Width - window.Width - 16;
moveAnimation.From = -4;
moveAnimation.To = 16;
}
}
else if (_position == 1)
else
{
window.Left = SystemParameters.WorkArea.Width / 2 - window.Width / 2;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 60;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 80;
}
else if (_position == 2)
{
window.Left = SystemParameters.WorkArea.Width - window.Width - 16;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height + 4;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 16;
}
else if (_position == 3)
{
window.Left = 16;
moveAnimation.From = -4;
moveAnimation.To = 16;
}
else if (_position == 4)
{
window.Left = SystemParameters.WorkArea.Width / 2 - window.Width / 2;
moveAnimation.From = -4;
moveAnimation.To = 16;
}
else if (_position == 5)
{
window.Left = SystemParameters.WorkArea.Width - window.Width - 16;
moveAnimation.From = -4;
moveAnimation.To = 16;
}

int msDuration = getDuration();

DoubleAnimation opacityAnimation = (DoubleAnimation)storyboard.Children[1];
Expand All @@ -179,29 +188,39 @@ public void OpenAnimation(MicaWindow window)
storyboard.Begin(window);
}

public void CloseAnimation(MicaWindow window)
public void CloseAnimation(MicaWindow window, bool alwaysBottom = false)
{
var eventTriggers = window.Triggers[0] as EventTrigger;
var beginStoryboard = eventTriggers.Actions[0] as BeginStoryboard;
var storyboard = beginStoryboard.Storyboard;

DoubleAnimation moveAnimation = (DoubleAnimation)storyboard.Children[0];
_position = Settings.Default.Position;
if (_position == 0 || _position == 2)
{
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 16;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height + 4;
}
else if (_position == 1)

if (alwaysBottom == false)
{
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 80;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 60;
_position = Settings.Default.Position;
if (_position == 0 || _position == 2)
{
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 16;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height + 4;
}
else if (_position == 1)
{
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 80;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height - 60;
}
else if (_position == 3 || _position == 4 || _position == 5)
{
moveAnimation.From = 16;
moveAnimation.To = -4;
}
}
else if (_position == 3 || _position == 4 || _position == 5)
else
{
moveAnimation.From = 16;
moveAnimation.To = -4;
moveAnimation.From = SystemParameters.WorkArea.Height - window.Height - 16;
moveAnimation.To = SystemParameters.WorkArea.Height - window.Height + 4;
}

int msDuration = getDuration();

DoubleAnimation opacityAnimation = (DoubleAnimation)storyboard.Children[1];
Expand Down Expand Up @@ -285,15 +304,25 @@ private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
ShowMediaFlyout();
}

if (vkCode == 0x14) // Caps Lock
{

}

if (vkCode == 0x90) // Num Lock
if (Settings.Default.LockKeysEnabled == true)
{
if (vkCode == 0x14) // Caps Lock
{
lockWindow ??= new LockWindow();
lockWindow.ShowLockFlyout("Caps Lock", Keyboard.IsKeyToggled(Key.CapsLock));
}

}
if (vkCode == 0x90) // Num Lock
{
lockWindow ??= new LockWindow();
lockWindow.ShowLockFlyout("Num Lock", Keyboard.IsKeyToggled(Key.NumLock));
}
if (vkCode == 0x91) // Scroll Lock
{
lockWindow ??= new LockWindow();
lockWindow.ShowLockFlyout("Scroll Lock", Keyboard.IsKeyToggled(Key.Scroll));
}
}
}
return CallNextHookEx(_hookId, nCode, wParam, lParam);
}
Expand Down
24 changes: 24 additions & 0 deletions FluentFlyoutWPF/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions FluentFlyoutWPF/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@
<Setting Name="FlyoutAnimationEasingStyle" Type="System.Int32" Scope="User">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="LockKeysEnabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="LockKeysDuration" Type="System.Int32" Scope="User">
<Value Profile="(Default)">2000</Value>
</Setting>
</Settings>
</SettingsFile>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions FluentFlyoutWPF/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,44 @@
</ui:CardControl>
</Grid>

<TextBlock Text="Lock Keys Customization" FontSize="20" FontWeight="SemiBold" FontFamily="Segoe UI Variable" Margin="0,36,0,0"/>
<Grid Margin="0,12,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="0,0,0,12">
<ui:Image Source="/Resources/FluentFlyoutDemo5.1.png" Width="128"/>
<TextBlock FontSize="14" FontWeight="Regular" HorizontalAlignment="Stretch" Opacity="0.75" Margin="12,0,0,0">
Check your lock key status at a glance.<LineBreak />
Appears after pressing Caps Lock, Num Lock or Scroll Lock.<LineBreak />
Convenient for laptops/keyboards without lock key indicators.
</TextBlock>
</StackPanel>
<ui:CardControl Grid.Row="1" Icon="{ui:SymbolIcon LockMultiple24}" Margin="0,0,0,3">
<ui:CardControl.Header>
<StackPanel Orientation="Vertical">
<TextBlock Text="Enable Lock Keys Flyout" FontSize="14" FontWeight="Regular" VerticalAlignment="Center"/>
<TextBlock Text="Displays whether the specified lock key is on or off" FontSize="12" Opacity="0.5"/>
</StackPanel>
</ui:CardControl.Header>
<controls:ToggleSwitch Name="LockKeysSwitch" Click="LockKeysSwitch_Click"/>
</ui:CardControl>
<ui:CardControl Grid.Row="2" Icon="{ui:SymbolIcon Timer24}" Margin="0,0,0,3">
<ui:CardControl.Header>
<StackPanel Orientation="Vertical">
<TextBlock Text="Lock Keys Stay Duration" FontSize="14" FontWeight="Regular" VerticalAlignment="Center"/>
<TextBlock Text="(default: 2000 ms)" FontSize="12" Opacity="0.5"/>
</StackPanel>
</ui:CardControl.Header>
<StackPanel Orientation="Horizontal">
<ui:TextBox Name="LockKeysDurationTextBox" Width="60" ClearButtonEnabled="False" TextChanged="LockKeysDurationTextBox_TextChanged"/>
<TextBlock Text="ms" FontSize="14" FontWeight="Regular" Margin="10,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
</ui:CardControl>
</Grid>

<TextBlock Text="System" FontSize="18" FontWeight="SemiBold" Margin="0,36,0,0"/>
<Grid Margin="0,12,0,0">
<Grid.RowDefinitions>
Expand Down
Loading

0 comments on commit cb855b9

Please sign in to comment.