Skip to content

Commit d2818db

Browse files
committed
- Fix Keyboard Navigation Control for Tray Menu
- Add Focus Style for toggle
1 parent a9b4187 commit d2818db

File tree

3 files changed

+59
-31
lines changed

3 files changed

+59
-31
lines changed

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Flow.Launcher.Infrastructure
77
public static class Constant
88
{
99
public const string FlowLauncher = "Flow.Launcher";
10+
public const string FlowLauncherFullName = "Flow Launcher";
1011
public const string Plugins = "Plugins";
1112
public const string PluginMetadataFileName = "plugin.json";
1213

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@
2727
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
2828
using DataObject = System.Windows.DataObject;
2929
using System.Windows.Media;
30+
using System.Windows.Interop;
31+
using System.Runtime.InteropServices;
3032

3133
namespace Flow.Launcher
3234
{
3335
public partial class MainWindow
3436
{
3537
#region Private Fields
3638

39+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
40+
public static extern IntPtr SetForegroundWindow(IntPtr hwnd);
41+
3742
private readonly Storyboard _progressBarStoryboard = new Storyboard();
3843
private bool isProgressBarStoryboardPaused;
3944
private Settings _settings;
4045
private NotifyIcon _notifyIcon;
41-
private ContextMenu contextMenu;
46+
private ContextMenuStrip contextMenu;
4247
private MainViewModel _viewModel;
4348
private bool _animating;
4449
MediaPlayer animationSound = new MediaPlayer();
@@ -258,64 +263,69 @@ private void InitializePosition()
258263
private void UpdateNotifyIconText()
259264
{
260265
var menu = contextMenu;
261-
((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
262-
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
263-
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
264-
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
265-
((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
266+
//((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")";
267+
//((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode");
268+
//((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset");
269+
//((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
270+
//((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
266271

267272
}
268273

269274
private void InitializeNotifyIcon()
270275
{
271276
_notifyIcon = new NotifyIcon
272277
{
273-
Text = Infrastructure.Constant.FlowLauncher,
278+
Text = Infrastructure.Constant.FlowLauncherFullName,
274279
Icon = Properties.Resources.app,
275280
Visible = !_settings.HideNotifyIcon
276281
};
277282

278-
contextMenu = new ContextMenu();
283+
var contextMenu = new ContextMenu();
279284

280285
var openIcon = new FontIcon
281286
{
282287
Glyph = "\ue71e"
283288
};
284289
var open = new MenuItem
285290
{
286-
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", Icon = openIcon
291+
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
292+
Icon = openIcon
287293
};
288294
var gamemodeIcon = new FontIcon
289295
{
290296
Glyph = "\ue7fc"
291297
};
292298
var gamemode = new MenuItem
293299
{
294-
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
300+
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
301+
Icon = gamemodeIcon
295302
};
296303
var positionresetIcon = new FontIcon
297304
{
298305
Glyph = "\ue73f"
299306
};
300307
var positionreset = new MenuItem
301308
{
302-
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon
309+
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
310+
Icon = positionresetIcon
303311
};
304312
var settingsIcon = new FontIcon
305313
{
306314
Glyph = "\ue713"
307315
};
308316
var settings = new MenuItem
309317
{
310-
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon
318+
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
319+
Icon = settingsIcon
311320
};
312321
var exitIcon = new FontIcon
313322
{
314323
Glyph = "\ue7e8"
315324
};
316325
var exit = new MenuItem
317326
{
318-
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
327+
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
328+
Icon = exitIcon
319329
};
320330

321331
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
@@ -333,17 +343,22 @@ private void InitializeNotifyIcon()
333343
contextMenu.Items.Add(settings);
334344
contextMenu.Items.Add(exit);
335345

336-
_notifyIcon.ContextMenuStrip = new ContextMenuStrip(); // it need for close the context menu. if not, context menu can't close.
337346
_notifyIcon.MouseClick += (o, e) =>
338347
{
339348
switch (e.Button)
340349
{
341350
case MouseButtons.Left:
342351
_viewModel.ToggleFlowLauncher();
343352
break;
344-
345353
case MouseButtons.Right:
354+
346355
contextMenu.IsOpen = true;
356+
// Get context menu handle and bring it to the foreground
357+
if (PresentationSource.FromVisual(contextMenu) is HwndSource hwndSource)
358+
{
359+
_ = SetForegroundWindow(hwndSource.Handle);
360+
}
361+
contextMenu.Focus();
347362
break;
348363
}
349364
};

Flow.Launcher/SettingWindow.xaml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@
6767
</Setter.Value>
6868
</Setter>
6969
</Style>
70+
<Style x:Key="SwitchFocusVisualStyleKey">
71+
<Setter Property="Control.Template">
72+
<Setter.Value>
73+
<ControlTemplate>
74+
<Rectangle
75+
Margin="-8,-4,-8,-4"
76+
RadiusX="5"
77+
RadiusY="5"
78+
Stroke="{DynamicResource Color05B}"
79+
StrokeThickness="2" />
80+
</ControlTemplate>
81+
</Setter.Value>
82+
</Setter>
83+
</Style>
7084
<Style x:Key="SettingGrid" TargetType="ItemsControl">
7185
<Setter Property="Focusable" Value="False" />
7286
<Setter Property="Margin" Value="0" />
@@ -137,6 +151,7 @@
137151
<Setter Property="Grid.Column" Value="2" />
138152
<Setter Property="FocusVisualMargin" Value="5" />
139153
<Setter Property="Width" Value="Auto" />
154+
<Setter Property="FocusVisualStyle" Value="{DynamicResource SwitchFocusVisualStyleKey}" />
140155
<Setter Property="HorizontalAlignment" Value="Right" />
141156
<Setter Property="HorizontalContentAlignment" Value="Right" />
142157
<Setter Property="OffContent" Value="{DynamicResource disable}" />
@@ -447,7 +462,10 @@
447462
IsItemsHost="true"
448463
LastChildFill="False" />
449464
<Border Grid.Column="1">
450-
<ContentPresenter Grid.Column="1" ContentSource="SelectedContent" />
465+
<ContentPresenter
466+
x:Name="PART_SelectedContentHost"
467+
Grid.Column="1"
468+
ContentSource="SelectedContent" />
451469
</Border>
452470
</Grid>
453471
</ControlTemplate>
@@ -693,7 +711,7 @@
693711
</ItemsControl>
694712
</Border>
695713

696-
<Border
714+
<Border
697715
Margin="0,30,0,0"
698716
Padding="0"
699717
Style="{DynamicResource SettingGroupBox}">
@@ -720,7 +738,7 @@
720738
<ComboBox
721739
x:Name="SelectScreen"
722740
MinWidth="160"
723-
Margin="0,0,18,0"
741+
Margin="0,0,18,0"
724742
VerticalAlignment="Center"
725743
FontSize="14"
726744
ItemsSource="{Binding ScreenNumbers}"
@@ -738,14 +756,12 @@
738756
</ComboBox>
739757
</StackPanel>
740758
<TextBlock Style="{StaticResource Glyph}">
741-
&#xe7f4;
759+
&#xe7f4;
742760
</TextBlock>
743761
</ItemsControl>
744762
</Border>
745763

746-
<Separator
747-
Width="Auto"
748-
BorderThickness="1">
764+
<Separator Width="Auto" BorderThickness="1">
749765
<Separator.Style>
750766
<Style BasedOn="{StaticResource SettingSeparatorStyle}" TargetType="Separator">
751767
<Setter Property="Visibility" Value="Visible" />
@@ -758,9 +774,7 @@
758774
</Separator.Style>
759775
</Separator>
760776

761-
<Border
762-
Margin="0"
763-
BorderThickness="0">
777+
<Border Margin="0" BorderThickness="0">
764778
<Border.Style>
765779
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
766780
<Setter Property="Visibility" Value="Visible" />
@@ -786,8 +800,7 @@
786800
FontSize="14"
787801
ItemsSource="{Binding SearchWindowAligns}"
788802
SelectedValue="{Binding Settings.SearchWindowAlign}"
789-
SelectedValuePath="Value">
790-
</ComboBox>
803+
SelectedValuePath="Value" />
791804
<StackPanel Margin="0,0,18,0" Orientation="Horizontal">
792805
<StackPanel.Style>
793806
<Style TargetType="StackPanel">
@@ -817,7 +830,7 @@
817830
</StackPanel>
818831
</StackPanel>
819832
<TextBlock Style="{StaticResource Glyph}">
820-
&#xe7f4;
833+
&#xe7f4;
821834
</TextBlock>
822835
</ItemsControl>
823836
</Border>
@@ -2446,8 +2459,7 @@
24462459
FontSize="14"
24472460
ItemsSource="{Binding AnimationSpeeds}"
24482461
SelectedValue="{Binding Settings.AnimationSpeed}"
2449-
SelectedValuePath="Value">
2450-
</ComboBox>
2462+
SelectedValuePath="Value" />
24512463
<StackPanel Margin="0,0,18,0" Orientation="Horizontal">
24522464
<StackPanel.Style>
24532465
<Style TargetType="StackPanel">
@@ -2543,7 +2555,7 @@
25432555
TickFrequency="1"
25442556
Value="{Binding SoundEffectVolume, Mode=TwoWay}" />
25452557
</StackPanel>
2546-
<TextBlock Style="{StaticResource Glyph}">
2558+
<TextBlock Style="{StaticResource Glyph}">
25472559
&#xe994;
25482560
</TextBlock>
25492561
</ItemsControl>

0 commit comments

Comments
 (0)