From 81ec9319904d24e4cebd9a6c03b4ae4d22ee99be Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Thu, 15 Oct 2026 15:29:56 +0800 Subject: [PATCH] Keep global shortcuts out of in-canvas ImGui text fields Space opened the Speed Dial and Ctrl+P the Preferences while the text tool's box or a sketch value field was being typed into. Those fields are ImGui drawn on the GL canvas, so the canvas is the focused wx window and focus_keeps_space() cannot see them; the CHAR_HOOK handler took the chord first and the field never saw the key. Skip the global shortcut dispatch while ImGui reports that one of its items owns the keyboard and the focused window is not a wxControl. --- src/slic3r/GUI/MainFrame.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index a06ee98bbf..a36f322066 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -816,6 +816,18 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ bool MainFrame::handle_global_shortcut(const KeyChord& chord) { + // ImGui draws its text fields (the text tool's box, a sketch value field) on the GL canvas, so + // while one of them is typed into the focused wx window is that canvas or an in-canvas frame: + // neither is a wxControl, so focus_keeps_space() cannot see it and CHAR_HOOK takes the chord + // here first -- Space opened the Speed Dial, Ctrl+P the Preferences, and the field never saw + // the key. ImGui raises WantCaptureKeyboard while one of its items owns the keyboard, so leave + // the key to it then. A focused wxControl (text field, list, web view) is untouched: those + // keep their own keys, and ImGui's flag can outlive the focus moving to one of them. + wxWindow* const focus = wxWindow::FindFocus(); + ImGuiWrapper* const imgui = wxGetApp().imgui(); + if (focus != nullptr && imgui != nullptr && imgui->want_keyboard() && dynamic_cast(focus) == nullptr) + return false; + const std::optional shortcut = wxGetApp().shortcuts().lookup(ShortcutContext::Global, chord); if (!shortcut.has_value()) return false;