🐛 修复面板未激活无法失焦的问题

This commit is contained in:
liufei
2022-05-25 15:58:37 +08:00
parent 5d51b0dbe9
commit e0824f3067
3 changed files with 41 additions and 17 deletions

View File

@@ -7,7 +7,7 @@
xmlns:cn="clr-namespace:GeekDesk.Constant" xmlns:cn="clr-namespace:GeekDesk.Constant"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:cvt="clr-namespace:GeekDesk.Converts" xmlns:cvt="clr-namespace:GeekDesk.Converts"
x:Name="window" x:Name="AppWindow"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel"
d:DataContext="{d:DesignInstance Type=viewmodel:AppData}" d:DataContext="{d:DesignInstance Type=viewmodel:AppData}"
Title="GeekDesk" Title="GeekDesk"
@@ -18,12 +18,13 @@
Background="Transparent" Background="Transparent"
ShowInTaskbar="False" ShowInTaskbar="False"
Opacity="0" Opacity="0"
Deactivated="App_LostFocus" Deactivated="AppWindow_Deactivated"
SizeChanged="Window_SizeChanged" SizeChanged="Window_SizeChanged"
KeyDown="OnKeyDown" KeyDown="OnKeyDown"
Focusable="True" Focusable="True"
MouseDown="MainWindow_MouseDown" MouseDown="MainWindow_MouseDown"
MouseEnter="MainWindow_MouseEnter" MouseEnter="MainWindow_MouseEnter"
GotFocus="Window_GotFocus"
> >
<WindowChrome.WindowChrome> <WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="15"/> <WindowChrome CaptionHeight="0" ResizeBorderThickness="15"/>
@@ -140,7 +141,6 @@
TextChanged="SearchBox_TextChanged" TextChanged="SearchBox_TextChanged"
/> />
<uc:RightCardControl x:Name="RightCard" Grid.Row="1" Grid.Column="1"/> <uc:RightCardControl x:Name="RightCard" Grid.Row="1" Grid.Column="1"/>
<hc:NotifyIcon Icon="/Taskbar.ico" Click="NotifyIcon_Click" x:Name="BarIcon" <hc:NotifyIcon Icon="/Taskbar.ico" Click="NotifyIcon_Click" x:Name="BarIcon"

View File

@@ -81,9 +81,13 @@ namespace GeekDesk
/// <param name="e"></param> /// <param name="e"></param>
private void SearchBox_TextChanged(object sender, TextChangedEventArgs e) private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
{ {
if (!RunTimeStatus.SEARCH_BOX_SHOW && appData.AppConfig.SearchType != SearchType.KEY_DOWN) if (!RunTimeStatus.SEARCH_BOX_SHOW
&& appData.AppConfig.SearchType != SearchType.KEY_DOWN
)
{ {
SearchBox.Text = ""; SearchBox.TextChanged -= SearchBox_TextChanged;
SearchBox.Clear();
SearchBox.TextChanged += SearchBox_TextChanged;
return; return;
} }
@@ -118,11 +122,14 @@ namespace GeekDesk
public void HidedSearchBox() public void HidedSearchBox()
{ {
RunTimeStatus.SEARCH_BOX_SHOW = false; RunTimeStatus.SEARCH_BOX_SHOW = false;
SearchBox.TextChanged -= SearchBox_TextChanged;
SearchBox.Clear();
SearchBox.TextChanged += SearchBox_TextChanged;
SearchBox.Width = 0; SearchBox.Width = 0;
App.DoEvents();
SearchIconList.IconList.Clear(); SearchIconList.IconList.Clear();
RightCard.VisibilitySearchCard(Visibility.Collapsed); RightCard.VisibilitySearchCard(Visibility.Collapsed);
SearchBox.Text = ""; Keyboard.Focus(SearchBox);
App.DoEvents();
} }
@@ -415,9 +422,11 @@ namespace GeekDesk
// return; // return;
//} //}
//修改贴边隐藏状态为未隐藏 MainWindow.mainWindow.Activate();
if (MarginHide.ON_HIDE) if (MarginHide.ON_HIDE)
{ {
//修改贴边隐藏状态为未隐藏
MarginHide.IS_HIDE = false; MarginHide.IS_HIDE = false;
if (!CommonCode.MouseInWindow(mainWindow)) if (!CommonCode.MouseInWindow(mainWindow))
{ {
@@ -432,7 +441,7 @@ namespace GeekDesk
} }
FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible); FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible);
Keyboard.Focus(mainWindow);
Keyboard.Focus(mainWindow.SearchBox); Keyboard.Focus(mainWindow.SearchBox);
} }
@@ -440,6 +449,8 @@ namespace GeekDesk
{ {
if (!MarginHide.IS_HIDE) if (!MarginHide.IS_HIDE)
{ {
//关闭锁定
RunTimeStatus.LOCK_APP_PANEL = false;
if (RunTimeStatus.SEARCH_BOX_SHOW) if (RunTimeStatus.SEARCH_BOX_SHOW)
{ {
mainWindow.HidedSearchBox(); mainWindow.HidedSearchBox();
@@ -586,10 +597,11 @@ namespace GeekDesk
SettingButton.ContextMenu = null; SettingButton.ContextMenu = null;
} }
private void App_LostFocus(object sender, EventArgs e)
private void AppWindowLostFocus()
{ {
if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS
&& this.Opacity == 1) && this.Opacity == 1 && !RunTimeStatus.LOCK_APP_PANEL)
{ {
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (!appData.AppConfig.MarginHide || (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE)) if (!appData.AppConfig.MarginHide || (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE))
@@ -599,6 +611,7 @@ namespace GeekDesk
} }
} }
private void Window_SizeChanged(object sender, SizeChangedEventArgs e) private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
if (this.DataContext != null) if (this.DataContext != null)
@@ -657,7 +670,7 @@ namespace GeekDesk
public void OnKeyDown(object sender, KeyEventArgs e) public void OnKeyDown(object sender, KeyEventArgs e)
{ {
char c = (char)e.Key; //char c = (char)e.Key;
if (e.Key == Key.Escape) if (e.Key == Key.Escape)
{ {
@@ -719,5 +732,15 @@ namespace GeekDesk
{ {
TaskbarContextMenu.Visibility = Visibility.Visible; TaskbarContextMenu.Visibility = Visibility.Visible;
} }
private void Window_GotFocus(object sender, RoutedEventArgs e)
{
Keyboard.Focus(SearchBox);
}
private void AppWindow_Deactivated(object sender, EventArgs e)
{
AppWindowLostFocus();
}
} }
} }

View File

@@ -3,7 +3,7 @@ using GeekDesk.MyThread;
using System; using System;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Threading; using System.Windows.Threading;
@@ -77,8 +77,9 @@ namespace GeekDesk.Util
#region #region
private static void HideWindow(object o, EventArgs e) private static void HideWindow(object o, EventArgs e)
{ {
if (window.Visibility != Visibility.Visible if (window.Visibility != Visibility.Visible
|| RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW) return; || RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW
|| RunTimeStatus.LOCK_APP_PANEL) return;
double screenLeft = SystemParameters.VirtualScreenLeft; double screenLeft = SystemParameters.VirtualScreenLeft;
double screenTop = SystemParameters.VirtualScreenTop; double screenTop = SystemParameters.VirtualScreenTop;
@@ -220,6 +221,7 @@ namespace GeekDesk.Util
private static void HideAnimation(double from, double to, DependencyProperty property, HideType hideType) private static void HideAnimation(double from, double to, DependencyProperty property, HideType hideType)
{ {
new Thread(() => new Thread(() =>
{ {
App.Current.Dispatcher.Invoke(() => App.Current.Dispatcher.Invoke(() =>
@@ -229,7 +231,7 @@ namespace GeekDesk.Util
if ((int)hideType <= 3) if ((int)hideType <= 3)
{ {
animalTime = showTime; animalTime = showTime;
} else } else
{ {
animalTime = hideTime; animalTime = hideTime;
@@ -284,7 +286,6 @@ namespace GeekDesk.Util
window.Top = to - 20; window.Top = to - 20;
break; break;
} }
//double toTemp = to; //double toTemp = to;
//double leftT = 0; //double leftT = 0;
//double topT = 0; //double topT = 0;