Keep keys away from the 3D view while ImGui has the keyboard (#16673)

The 3D view decided whether to run its shortcuts from ImGui's "wants the
keyboard" flag, which is updated a frame late. The first key typed after
clicking into a field could still reach the canvas.

The canvas now leaves every key to ImGui while an ImGui text field is
active, while a popup (dropdown, menu or modal) is open, or while a
slider or button is held with the mouse. A focused sidebar text field
works the same way. Global shortcuts still run unless they edit text.
Every key still goes to ImGui.

- ImGuiWrapper::claim_key_event() decides on the key-down. The key's
  repeats, char event and release follow that decision, so a key never
  both runs a shortcut and types.
- Esc closes an open dropdown or menu before the gizmo.
- Esc and Tab during a slider drag no longer close the gizmo or switch
  views.
- text_input_active() reads ImGui's text input request, so a slider
  that once had a value typed into it no longer counts as a text field
  when dragged.
- A modifier whose key-up went to a dialog no longer stays stuck. The
  canvas releases held modifiers when it loses the focus, and ImGui
  takes its modifiers from each mouse event.
- The macOS Edit menu's key equivalents follow the same rule.
This commit is contained in:
Kris Austin authored and GitHub committed 2026-10-22 10:22:23 -05:00
1 parent f92f75e0fa
commit 3f8ff53e65
8 files changed
+343 -37

No files matched your search

+8 -5
View File
@@ -3136,12 +3136,15 @@ void MainFrame::init_menubar_as_editor()
{
editMenu = new wxMenu();
// Feeds the key to ImGui instead when ImGui has the focused canvas's keyboard, since the menu
// handles its key equivalents before the canvas receives the key.
auto handle_key_event = [](wxKeyEvent& evt) {
if (wxGetApp().imgui()->update_key_data(evt)) {
wxGetApp().plater()->get_current_canvas3D()->render();
return true;
}
return false;
const ImGuiWrapper* imgui = focused_canvas_imgui(wxWindow::FindFocus());
if (imgui == nullptr || !imgui->owns_keyboard())
return false;
wxGetApp().imgui()->update_key_data(evt);
wxGetApp().plater()->get_current_canvas3D()->render();
return true;
};
#ifndef __APPLE__
// BBS undo