|
@@ -8406,8 +8406,6 @@ static bool IsKeyChordPotentiallyCharInput(ImGuiKeyChord key_chord)
|
|
// - Routes and key ownership are attributed at the beginning of next frame based on best score and mod state.
|
|
// - Routes and key ownership are attributed at the beginning of next frame based on best score and mod state.
|
|
// (Conceptually this does a "Submit for next frame" + "Test for current frame".
|
|
// (Conceptually this does a "Submit for next frame" + "Test for current frame".
|
|
// As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.)
|
|
// As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.)
|
|
-// - Using 'owner_id == ImGuiKeyOwner_Any/0': auto-assign an owner based on current focus scope (each window has its focus scope by default)
|
|
|
|
-// - Using 'owner_id == ImGuiKeyOwner_None': allows disabling/locking a shortcut.
|
|
|
|
bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
|
|
bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
|
|
{
|
|
{
|
|
ImGuiContext& g = *GImGui;
|
|
ImGuiContext& g = *GImGui;
|
|
@@ -8415,6 +8413,8 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiI
|
|
flags |= ImGuiInputFlags_RouteGlobalHigh; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut()
|
|
flags |= ImGuiInputFlags_RouteGlobalHigh; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut()
|
|
else
|
|
else
|
|
IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteMask_)); // Check that only 1 routing flag is used
|
|
IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteMask_)); // Check that only 1 routing flag is used
|
|
|
|
+ IM_ASSERT(owner_id != ImGuiKeyOwner_Any && owner_id != ImGuiKeyOwner_None);
|
|
|
|
+
|
|
if (key_chord & ImGuiMod_Shortcut)
|
|
if (key_chord & ImGuiMod_Shortcut)
|
|
key_chord = ConvertShortcutMod(key_chord);
|
|
key_chord = ConvertShortcutMod(key_chord);
|
|
|
|
|
|
@@ -8454,18 +8454,17 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiI
|
|
// Submit routing for NEXT frame (assuming score is sufficient)
|
|
// Submit routing for NEXT frame (assuming score is sufficient)
|
|
// FIXME: Could expose a way to use a "serve last" policy for same score resolution (using <= instead of <).
|
|
// FIXME: Could expose a way to use a "serve last" policy for same score resolution (using <= instead of <).
|
|
ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord);
|
|
ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord);
|
|
- const ImGuiID routing_id = GetRoutingIdFromOwnerId(owner_id);
|
|
|
|
//const bool set_route = (flags & ImGuiInputFlags_ServeLast) ? (score <= routing_data->RoutingNextScore) : (score < routing_data->RoutingNextScore);
|
|
//const bool set_route = (flags & ImGuiInputFlags_ServeLast) ? (score <= routing_data->RoutingNextScore) : (score < routing_data->RoutingNextScore);
|
|
if (score < routing_data->RoutingNextScore)
|
|
if (score < routing_data->RoutingNextScore)
|
|
{
|
|
{
|
|
- routing_data->RoutingNext = routing_id;
|
|
|
|
|
|
+ routing_data->RoutingNext = owner_id;
|
|
routing_data->RoutingNextScore = (ImU8)score;
|
|
routing_data->RoutingNextScore = (ImU8)score;
|
|
}
|
|
}
|
|
|
|
|
|
// Return routing state for CURRENT frame
|
|
// Return routing state for CURRENT frame
|
|
- if (routing_data->RoutingCurr == routing_id)
|
|
|
|
|
|
+ if (routing_data->RoutingCurr == owner_id)
|
|
IMGUI_DEBUG_LOG_INPUTROUTING("--> granting current route\n");
|
|
IMGUI_DEBUG_LOG_INPUTROUTING("--> granting current route\n");
|
|
- return routing_data->RoutingCurr == routing_id;
|
|
|
|
|
|
+ return routing_data->RoutingCurr == owner_id;
|
|
}
|
|
}
|
|
|
|
|
|
// Currently unused by core (but used by tests)
|
|
// Currently unused by core (but used by tests)
|
|
@@ -9428,6 +9427,13 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags
|
|
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
|
|
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
|
|
if ((flags & ImGuiInputFlags_RouteMask_) == 0)
|
|
if ((flags & ImGuiInputFlags_RouteMask_) == 0)
|
|
flags |= ImGuiInputFlags_RouteFocused;
|
|
flags |= ImGuiInputFlags_RouteFocused;
|
|
|
|
+
|
|
|
|
+ // Using 'owner_id == ImGuiKeyOwner_Any/0': auto-assign an owner based on current focus scope (each window has its focus scope by default)
|
|
|
|
+ // Effectively makes Shortcut() always input-owner aware.
|
|
|
|
+ if (owner_id == ImGuiKeyOwner_Any || owner_id == ImGuiKeyOwner_None)
|
|
|
|
+ owner_id = GetRoutingIdFromOwnerId(owner_id);
|
|
|
|
+
|
|
|
|
+ // Submit route
|
|
if (!SetShortcutRouting(key_chord, owner_id, flags))
|
|
if (!SetShortcutRouting(key_chord, owner_id, flags))
|
|
return false;
|
|
return false;
|
|
|
|
|