- Fix Keyboard Navigation Control for Tray Menu

- Add Focus Style for toggle
This commit is contained in:
DB p 2024-04-24 04:48:31 +09:00
parent a9b4187969
commit d2818db6bf
3 changed files with 59 additions and 31 deletions

View file

@ -7,6 +7,7 @@ namespace Flow.Launcher.Infrastructure
public static class Constant
{
public const string FlowLauncher = "Flow.Launcher";
public const string FlowLauncherFullName = "Flow Launcher";
public const string Plugins = "Plugins";
public const string PluginMetadataFileName = "plugin.json";

View file

@ -27,6 +27,8 @@ using System.Media;
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
using DataObject = System.Windows.DataObject;
using System.Windows.Media;
using System.Windows.Interop;
using System.Runtime.InteropServices;
namespace Flow.Launcher
{
@ -34,11 +36,14 @@ namespace Flow.Launcher
{
#region Private Fields
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr SetForegroundWindow(IntPtr hwnd);
private readonly Storyboard _progressBarStoryboard = new Storyboard();
private bool isProgressBarStoryboardPaused;
private Settings _settings;
private NotifyIcon _notifyIcon;
private ContextMenu contextMenu;
private ContextMenuStrip contextMenu;
private MainViewModel _viewModel;
private bool _animating;
MediaPlayer animationSound = new MediaPlayer();
@ -258,11 +263,11 @@ namespace Flow.Launcher
private void UpdateNotifyIconText()
{
var menu = contextMenu;
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
//((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
//((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
//((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
//((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
//((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
}
@ -270,12 +275,12 @@ namespace Flow.Launcher
{
_notifyIcon = new NotifyIcon
{
Text = Infrastructure.Constant.FlowLauncher,
Text = Infrastructure.Constant.FlowLauncherFullName,
Icon = Properties.Resources.app,
Visible = !_settings.HideNotifyIcon
};
contextMenu = new ContextMenu();
var contextMenu = new ContextMenu();
var openIcon = new FontIcon
{
@ -283,7 +288,8 @@ namespace Flow.Launcher
};
var open = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", Icon = openIcon
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
Icon = openIcon
};
var gamemodeIcon = new FontIcon
{
@ -291,7 +297,8 @@ namespace Flow.Launcher
};
var gamemode = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
Icon = gamemodeIcon
};
var positionresetIcon = new FontIcon
{
@ -299,7 +306,8 @@ namespace Flow.Launcher
};
var positionreset = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
Icon = positionresetIcon
};
var settingsIcon = new FontIcon
{
@ -307,7 +315,8 @@ namespace Flow.Launcher
};
var settings = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
Icon = settingsIcon
};
var exitIcon = new FontIcon
{
@ -315,7 +324,8 @@ namespace Flow.Launcher
};
var exit = new MenuItem
{
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
Icon = exitIcon
};
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
@ -333,7 +343,6 @@ namespace Flow.Launcher
contextMenu.Items.Add(settings);
contextMenu.Items.Add(exit);
_notifyIcon.ContextMenuStrip = new ContextMenuStrip(); // it need for close the context menu. if not, context menu can't close.
_notifyIcon.MouseClick += (o, e) =>
{
switch (e.Button)
@ -341,9 +350,15 @@ namespace Flow.Launcher
case MouseButtons.Left:
_viewModel.ToggleFlowLauncher();
break;
case MouseButtons.Right:
contextMenu.IsOpen = true;
// Get context menu handle and bring it to the foreground
if (PresentationSource.FromVisual(contextMenu) is HwndSource hwndSource)
{
_ = SetForegroundWindow(hwndSource.Handle);
}
contextMenu.Focus();
break;
}
};

View file

@ -67,6 +67,20 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SwitchFocusVisualStyleKey">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle
Margin="-8,-4,-8,-4"
RadiusX="5"
RadiusY="5"
Stroke="{DynamicResource Color05B}"
StrokeThickness="2" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SettingGrid" TargetType="ItemsControl">
<Setter Property="Focusable" Value="False" />
<Setter Property="Margin" Value="0" />
@ -137,6 +151,7 @@
<Setter Property="Grid.Column" Value="2" />
<Setter Property="FocusVisualMargin" Value="5" />
<Setter Property="Width" Value="Auto" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource SwitchFocusVisualStyleKey}" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="OffContent" Value="{DynamicResource disable}" />
@ -447,7 +462,10 @@
IsItemsHost="true"
LastChildFill="False" />
<Border Grid.Column="1">
<ContentPresenter Grid.Column="1" ContentSource="SelectedContent" />
<ContentPresenter
x:Name="PART_SelectedContentHost"
Grid.Column="1"
ContentSource="SelectedContent" />
</Border>
</Grid>
</ControlTemplate>
@ -693,7 +711,7 @@
</ItemsControl>
</Border>
<Border
<Border
Margin="0,30,0,0"
Padding="0"
Style="{DynamicResource SettingGroupBox}">
@ -720,7 +738,7 @@
<ComboBox
x:Name="SelectScreen"
MinWidth="160"
Margin="0,0,18,0"
Margin="0,0,18,0"
VerticalAlignment="Center"
FontSize="14"
ItemsSource="{Binding ScreenNumbers}"
@ -738,14 +756,12 @@
</ComboBox>
</StackPanel>
<TextBlock Style="{StaticResource Glyph}">
&#xe7f4;
&#xe7f4;
</TextBlock>
</ItemsControl>
</Border>
<Separator
Width="Auto"
BorderThickness="1">
<Separator Width="Auto" BorderThickness="1">
<Separator.Style>
<Style BasedOn="{StaticResource SettingSeparatorStyle}" TargetType="Separator">
<Setter Property="Visibility" Value="Visible" />
@ -758,9 +774,7 @@
</Separator.Style>
</Separator>
<Border
Margin="0"
BorderThickness="0">
<Border Margin="0" BorderThickness="0">
<Border.Style>
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
<Setter Property="Visibility" Value="Visible" />
@ -786,8 +800,7 @@
FontSize="14"
ItemsSource="{Binding SearchWindowAligns}"
SelectedValue="{Binding Settings.SearchWindowAlign}"
SelectedValuePath="Value">
</ComboBox>
SelectedValuePath="Value" />
<StackPanel Margin="0,0,18,0" Orientation="Horizontal">
<StackPanel.Style>
<Style TargetType="StackPanel">
@ -817,7 +830,7 @@
</StackPanel>
</StackPanel>
<TextBlock Style="{StaticResource Glyph}">
&#xe7f4;
&#xe7f4;
</TextBlock>
</ItemsControl>
</Border>
@ -2446,8 +2459,7 @@
FontSize="14"
ItemsSource="{Binding AnimationSpeeds}"
SelectedValue="{Binding Settings.AnimationSpeed}"
SelectedValuePath="Value">
</ComboBox>
SelectedValuePath="Value" />
<StackPanel Margin="0,0,18,0" Orientation="Horizontal">
<StackPanel.Style>
<Style TargetType="StackPanel">
@ -2543,7 +2555,7 @@
TickFrequency="1"
Value="{Binding SoundEffectVolume, Mode=TwoWay}" />
</StackPanel>
<TextBlock Style="{StaticResource Glyph}">
<TextBlock Style="{StaticResource Glyph}">
&#xe994;
</TextBlock>
</ItemsControl>