@@ -8406,15 +8406,15 @@ static bool IsKeyChordPotentiallyCharInput(ImGuiKeyChord key_chord)
84068406// - Routes and key ownership are attributed at the beginning of next frame based on best score and mod state.
84078407// (Conceptually this does a "Submit for next frame" + "Test for current frame".
84088408// As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.)
8409- // - Using 'owner_id == ImGuiKeyOwner_Any/0': auto-assign an owner based on current focus scope (each window has its focus scope by default)
8410- // - Using 'owner_id == ImGuiKeyOwner_None': allows disabling/locking a shortcut.
84118409bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
84128410{
84138411 ImGuiContext& g = *GImGui;
84148412 if ((flags & ImGuiInputFlags_RouteMask_) == 0)
84158413 flags |= ImGuiInputFlags_RouteGlobalHigh; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut()
84168414 else
84178415 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteMask_)); // Check that only 1 routing flag is used
8416+ IM_ASSERT(owner_id != ImGuiKeyOwner_Any && owner_id != ImGuiKeyOwner_None);
8417+
84188418 if (key_chord & ImGuiMod_Shortcut)
84198419 key_chord = ConvertShortcutMod(key_chord);
84208420
@@ -8454,18 +8454,17 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiI
84548454 // Submit routing for NEXT frame (assuming score is sufficient)
84558455 // FIXME: Could expose a way to use a "serve last" policy for same score resolution (using <= instead of <).
84568456 ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord);
8457- const ImGuiID routing_id = GetRoutingIdFromOwnerId(owner_id);
84588457 //const bool set_route = (flags & ImGuiInputFlags_ServeLast) ? (score <= routing_data->RoutingNextScore) : (score < routing_data->RoutingNextScore);
84598458 if (score < routing_data->RoutingNextScore)
84608459 {
8461- routing_data->RoutingNext = routing_id ;
8460+ routing_data->RoutingNext = owner_id ;
84628461 routing_data->RoutingNextScore = (ImU8)score;
84638462 }
84648463
84658464 // Return routing state for CURRENT frame
8466- if (routing_data->RoutingCurr == routing_id )
8465+ if (routing_data->RoutingCurr == owner_id )
84678466 IMGUI_DEBUG_LOG_INPUTROUTING("--> granting current route\n");
8468- return routing_data->RoutingCurr == routing_id ;
8467+ return routing_data->RoutingCurr == owner_id ;
84698468}
84708469
84718470// Currently unused by core (but used by tests)
@@ -9428,6 +9427,13 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags
94289427 // When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
94299428 if ((flags & ImGuiInputFlags_RouteMask_) == 0)
94309429 flags |= ImGuiInputFlags_RouteFocused;
9430+
9431+ // Using 'owner_id == ImGuiKeyOwner_Any/0': auto-assign an owner based on current focus scope (each window has its focus scope by default)
9432+ // Effectively makes Shortcut() always input-owner aware.
9433+ if (owner_id == ImGuiKeyOwner_Any || owner_id == ImGuiKeyOwner_None)
9434+ owner_id = GetRoutingIdFromOwnerId(owner_id);
9435+
9436+ // Submit route
94319437 if (!SetShortcutRouting(key_chord, owner_id, flags))
94329438 return false;
94339439
0 commit comments