Shortcut routing for an active item #7618

Closed
opened 2024-05-24 10:57:20 +00:00 by nikitablack · 0 comments
nikitablack commented 2024-05-24 10:57:20 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version 1.90.1, Branch: docking

Back-ends:

imgui_impl_glfw.cpp

Compiler, OS:

Ubuntu 20.04, imgui_impl_glfw

Full config/build information:

No response

Details:

In this scenario:

shortcut

I want to achieve the following:

  1. Register a global shortcut, which is activated when nothing is in focus or the same shortcut was not intercepted by other windows.
  2. Register the same shortcut for a docking window (not shown on the picture).
  3. The text input should intercept the shortcut.

According to the docs, the routing is organized like this:

GlobalHigh > Focused (when owner is active item) > Global > Focused (when focused window) > GlobalLow

Following this logic I added to my main.cpp:

if (ImGui::Shortcut(ImGuiKey_M, 0, ImGuiInputFlags_RouteGlobalLow)) {
    std::cout << "Global M" << std::endl;
}

And for the text input:

ImGui::InputText("##Address", ...);
ImGui::Shortcut(ImGuiKey_M, ImGui::GetID("##Address"), ImGuiInputFlags_RouteFocused);

While preventing to fire a global shortcut during text input usage, it also intercepts the shortcut when the text not in focus, but the window where this text is a child is in focus. In other words, the line ImGui::SetShortcutRouting(ImGuiKey_M, ImGui::GetID("##Address"), ImGuiInputFlags_RouteFocused) returns true even when the text input not focused, but the parent window is.

### Version/Branch of Dear ImGui: Version 1.90.1, Branch: docking ### Back-ends: imgui_impl_glfw.cpp ### Compiler, OS: Ubuntu 20.04, imgui_impl_glfw ### Full config/build information: _No response_ ### Details: In this scenario: ![shortcut](https://github.com/ocornut/imgui/assets/6390092/15fe975c-a882-4fd3-a65b-4cc0db844c14) I want to achieve the following: 1. Register a global shortcut, which is activated when nothing is in focus or the same shortcut was not intercepted by other windows. 2. Register the same shortcut for a docking window (not shown on the picture). 3. The text input should intercept the shortcut. According to the docs, the routing is organized like this: > GlobalHigh > Focused (when owner is active item) > Global > Focused (when focused window) > GlobalLow Following this logic I added to my `main.cpp`: ``` if (ImGui::Shortcut(ImGuiKey_M, 0, ImGuiInputFlags_RouteGlobalLow)) { std::cout << "Global M" << std::endl; } ``` And for the text input: ``` ImGui::InputText("##Address", ...); ImGui::Shortcut(ImGuiKey_M, ImGui::GetID("##Address"), ImGuiInputFlags_RouteFocused); ``` While preventing to fire a global shortcut during text input usage, it also intercepts the shortcut when the text not in focus, but the window where this text is a child is in focus. In other words, the line `ImGui::SetShortcutRouting(ImGuiKey_M, ImGui::GetID("##Address"), ImGuiInputFlags_RouteFocused)` returns `true` even when the text input not focused, but the parent window is.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#7618
No description provided.