mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3568 from onesounds/20250522-FixWinR
Fix: Ensure QueryTextBox receives focus after Win+R
This commit is contained in:
commit
2beab53131
4 changed files with 32 additions and 3 deletions
|
|
@ -88,6 +88,11 @@ namespace Flow.Launcher.Plugin
|
|||
/// Show the MainWindow when hiding
|
||||
/// </summary>
|
||||
void ShowMainWindow();
|
||||
|
||||
/// <summary>
|
||||
/// Focus the query text box in the main window
|
||||
/// </summary>
|
||||
void FocusQueryTextBox();
|
||||
|
||||
/// <summary>
|
||||
/// Hide MainWindow
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -10,6 +11,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core;
|
||||
|
|
@ -32,7 +34,6 @@ using Flow.Launcher.ViewModel;
|
|||
using JetBrains.Annotations;
|
||||
using Squirrel;
|
||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -93,6 +94,8 @@ namespace Flow.Launcher
|
|||
|
||||
public void ShowMainWindow() => _mainVM.Show();
|
||||
|
||||
public void FocusQueryTextBox() => _mainVM.FocusQueryTextBox();
|
||||
|
||||
public void HideMainWindow() => _mainVM.Hide();
|
||||
|
||||
public bool IsMainWindowVisible() => _mainVM.MainWindowVisibilityStatus;
|
||||
|
|
|
|||
|
|
@ -1926,6 +1926,21 @@ namespace Flow.Launcher.ViewModel
|
|||
Results.AddResults(resultsForUpdates, token, reSelect);
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
|
||||
public void FocusQueryTextBox()
|
||||
{
|
||||
// When application is exiting, the Application.Current will be null
|
||||
Application.Current?.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// When application is exiting, the Application.Current will be null
|
||||
if (Application.Current?.MainWindow is MainWindow window)
|
||||
{
|
||||
window.QueryTextBox.Focus();
|
||||
Keyboard.Focus(window.QueryTextBox);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
|
|
|||
|
|
@ -378,11 +378,17 @@ namespace Flow.Launcher.Plugin.Shell
|
|||
|
||||
private void OnWinRPressed()
|
||||
{
|
||||
Context.API.ShowMainWindow();
|
||||
// show the main window and set focus to the query box
|
||||
_ = Task.Run(() =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
Context.API.ShowMainWindow();
|
||||
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
|
||||
|
||||
// Win+R is a system-reserved shortcut, and though the plugin intercepts the keyboard event and
|
||||
// shows the main window, Windows continues to process the Win key and briefly reclaims focus.
|
||||
// So we need to wait until the keyboard event processing is completed and then set focus
|
||||
await Task.Delay(50);
|
||||
Context.API.FocusQueryTextBox();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue