mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Shortcut(): always test ownership.
- It doesn't sense to test route without ownership (which may be overrided by code not using routing) - It also wouldn't be possible to call Shortcut() with _None anyway, since successful routing sets ownership. Tangential to experiments for #7237
This commit is contained in:
		
							
								
								
									
										18
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -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.
 | 
			
		||||
//   (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.)
 | 
			
		||||
// - 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)
 | 
			
		||||
{
 | 
			
		||||
    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()
 | 
			
		||||
    else
 | 
			
		||||
        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)
 | 
			
		||||
        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)
 | 
			
		||||
    // FIXME: Could expose a way to use a "serve last" policy for same score resolution (using <= instead of <).
 | 
			
		||||
    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);
 | 
			
		||||
    if (score < routing_data->RoutingNextScore)
 | 
			
		||||
    {
 | 
			
		||||
        routing_data->RoutingNext = routing_id;
 | 
			
		||||
        routing_data->RoutingNext = owner_id;
 | 
			
		||||
        routing_data->RoutingNextScore = (ImU8)score;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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");
 | 
			
		||||
    return routing_data->RoutingCurr == routing_id;
 | 
			
		||||
    return routing_data->RoutingCurr == owner_id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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.
 | 
			
		||||
    if ((flags & ImGuiInputFlags_RouteMask_) == 0)
 | 
			
		||||
        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))
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user