LibGUI: CommandPalette: Fix key event capture for actions

This patch fixes an issue for applications that contain actions without
a modifier (e.g. PixelPaint). Previously when pressing any key bound to
an action while the CommandPalette was visible the action was forwarded
to the parent instead of the CommandPalette.
This commit is contained in:
faxe1008 2022-09-05 21:17:45 +02:00 committed by Andreas Kling
parent 5ff63a9eb0
commit d91469ebb1
3 changed files with 5 additions and 4 deletions

View file

@ -223,8 +223,8 @@ CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen
m_text_box->set_focus(true);
on_active_window_change = [this](bool is_active_window) {
if (!is_active_window)
on_active_input_change = [this](bool is_active_input) {
if (!is_active_input)
close();
};

View file

@ -164,7 +164,7 @@ static Action* action_for_shortcut(Window& window, Shortcut const& shortcut)
}
// NOTE: Application-global shortcuts are ignored while a blocking modal window is up.
if (!window.is_blocking()) {
if (!window.is_blocking() && !window.is_capturing_input()) {
if (auto* action = Application::the()->action_for_shortcut(shortcut)) {
dbgln_if(KEYBOARD_SHORTCUTS_DEBUG, " > Asked application, got action: {} {} (enabled: {}, shortcut: {}, alt-shortcut: {})", action, action->text(), action->is_enabled(), action->shortcut().to_string(), action->alternate_shortcut().to_string());
return action;
@ -214,7 +214,7 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key,
// FIXME: This shortcut should be configurable.
if (accepts_command_palette && !m_in_command_palette && modifiers == (Mod_Ctrl | Mod_Shift) && key == Key_A) {
auto command_palette = CommandPalette::construct(*window);
command_palette->set_window_mode(GUI::WindowMode::Passive);
command_palette->set_window_mode(GUI::WindowMode::CaptureInput);
TemporaryChange change { m_in_command_palette, true };
if (command_palette->exec() != GUI::Dialog::ExecResult::OK)
return;

View file

@ -36,6 +36,7 @@ public:
bool is_modal() const { return m_window_mode != WindowMode::Modeless; }
bool is_blocking() const { return m_window_mode == WindowMode::Blocking; }
bool is_capturing_input() const { return m_window_mode == WindowMode::CaptureInput; }
bool is_fullscreen() const { return m_fullscreen; }
void set_fullscreen(bool);