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

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"
mc:Ignorable="d"
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"
d:DataContext="{d:DesignInstance Type=viewmodel:AppData}"
Title="GeekDesk"
@@ -18,12 +18,13 @@
Background="Transparent"
ShowInTaskbar="False"
Opacity="0"
Deactivated="App_LostFocus"
Deactivated="AppWindow_Deactivated"
SizeChanged="Window_SizeChanged"
KeyDown="OnKeyDown"
Focusable="True"
MouseDown="MainWindow_MouseDown"
MouseEnter="MainWindow_MouseEnter"
GotFocus="Window_GotFocus"
>
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="15"/>
@@ -140,7 +141,6 @@
TextChanged="SearchBox_TextChanged"
/>
<uc:RightCardControl x:Name="RightCard" Grid.Row="1" Grid.Column="1"/>
<hc:NotifyIcon Icon="/Taskbar.ico" Click="NotifyIcon_Click" x:Name="BarIcon"

View File

@@ -81,9 +81,13 @@ namespace GeekDesk
/// <param name="e"></param>
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;
}
@@ -118,11 +122,14 @@ namespace GeekDesk
public void HidedSearchBox()
{
RunTimeStatus.SEARCH_BOX_SHOW = false;
SearchBox.TextChanged -= SearchBox_TextChanged;
SearchBox.Clear();
SearchBox.TextChanged += SearchBox_TextChanged;
SearchBox.Width = 0;
App.DoEvents();
SearchIconList.IconList.Clear();
RightCard.VisibilitySearchCard(Visibility.Collapsed);
SearchBox.Text = "";
Keyboard.Focus(SearchBox);
App.DoEvents();
}
@@ -415,9 +422,11 @@ namespace GeekDesk
// return;
//}
//修改贴边隐藏状态为未隐藏
MainWindow.mainWindow.Activate();
if (MarginHide.ON_HIDE)
{
//修改贴边隐藏状态为未隐藏
MarginHide.IS_HIDE = false;
if (!CommonCode.MouseInWindow(mainWindow))
{
@@ -432,7 +441,7 @@ namespace GeekDesk
}
FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible);
Keyboard.Focus(mainWindow);
Keyboard.Focus(mainWindow.SearchBox);
}
@@ -440,6 +449,8 @@ namespace GeekDesk
{
if (!MarginHide.IS_HIDE)
{
//关闭锁定
RunTimeStatus.LOCK_APP_PANEL = false;
if (RunTimeStatus.SEARCH_BOX_SHOW)
{
mainWindow.HidedSearchBox();
@@ -586,10 +597,11 @@ namespace GeekDesk
SettingButton.ContextMenu = null;
}
private void App_LostFocus(object sender, EventArgs e)
private void AppWindowLostFocus()
{
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))
@@ -599,6 +611,7 @@ namespace GeekDesk
}
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (this.DataContext != null)
@@ -657,7 +670,7 @@ namespace GeekDesk
public void OnKeyDown(object sender, KeyEventArgs e)
{
char c = (char)e.Key;
//char c = (char)e.Key;
if (e.Key == Key.Escape)
{
@@ -719,5 +732,15 @@ namespace GeekDesk
{
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.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Threading;
@@ -77,8 +77,9 @@ namespace GeekDesk.Util
#region
private static void HideWindow(object o, EventArgs e)
{
if (window.Visibility != Visibility.Visible
|| RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW) return;
if (window.Visibility != Visibility.Visible
|| RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW
|| RunTimeStatus.LOCK_APP_PANEL) return;
double screenLeft = SystemParameters.VirtualScreenLeft;
double screenTop = SystemParameters.VirtualScreenTop;
@@ -220,6 +221,7 @@ namespace GeekDesk.Util
private static void HideAnimation(double from, double to, DependencyProperty property, HideType hideType)
{
new Thread(() =>
{
App.Current.Dispatcher.Invoke(() =>
@@ -229,7 +231,7 @@ namespace GeekDesk.Util
if ((int)hideType <= 3)
{
animalTime = showTime;
animalTime = showTime;
} else
{
animalTime = hideTime;
@@ -284,7 +286,6 @@ namespace GeekDesk.Util
window.Top = to - 20;
break;
}
//double toTemp = to;
//double leftT = 0;
//double topT = 0;