MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / SetShortcutRouting

Method SetShortcutRouting

imgui_tiny_app/imgui/imgui.cpp:10323–10406  ·  view source on GitHub ↗

Request a desired route for an input chord (key + mods). Return true if the route is available this frame. - 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.)

Source from the content-addressed store, hash-verified

10321// (Conceptually this does a "Submit for next frame" + "Test for current frame".
10322// As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.)
10323bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID owner_id)
10324{
10325 ImGuiContext& g = *GImGui;
10326 if ((flags & ImGuiInputFlags_RouteTypeMask_) == 0)
10327 flags |= ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverFocused | ImGuiInputFlags_RouteOverActive; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut()
10328 else
10329 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteTypeMask_)); // Check that only 1 routing flag is used
10330 IM_ASSERT(owner_id != ImGuiKeyOwner_Any && owner_id != ImGuiKeyOwner_NoOwner);
10331 if (flags & (ImGuiInputFlags_RouteOverFocused | ImGuiInputFlags_RouteUnlessBgFocused))
10332 IM_ASSERT(flags & ImGuiInputFlags_RouteGlobal);
10333 if (flags & ImGuiInputFlags_RouteOverActive)
10334 IM_ASSERT(flags & (ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteFocused));
10335
10336 // Add ImGuiMod_XXXX when a corresponding ImGuiKey_LeftXXX/ImGuiKey_RightXXX is specified.
10337 key_chord = FixupKeyChord(key_chord);
10338
10339 // [DEBUG] Debug break requested by user
10340 if (g.DebugBreakInShortcutRouting == key_chord)
10341 IM_DEBUG_BREAK();
10342
10343 if (flags & ImGuiInputFlags_RouteUnlessBgFocused)
10344 if (g.NavWindow == NULL)
10345 return false;
10346
10347 // Note how ImGuiInputFlags_RouteAlways won't set routing and thus won't set owner. May want to rework this?
10348 if (flags & ImGuiInputFlags_RouteAlways)
10349 {
10350 IMGUI_DEBUG_LOG_INPUTROUTING("SetShortcutRouting(%s, flags=%04X, owner_id=0x%08X) -> always, no register\n", GetKeyChordName(key_chord), flags, owner_id);
10351 return true;
10352 }
10353
10354 // Specific culling when there's an active item.
10355 if (g.ActiveId != 0 && g.ActiveId != owner_id)
10356 {
10357 if (flags & ImGuiInputFlags_RouteActive)
10358 return false;
10359
10360 // Cull shortcuts with no modifiers when it could generate a character.
10361 // e.g. Shortcut(ImGuiKey_G) also generates 'g' character, should not trigger when InputText() is active.
10362 // but Shortcut(Ctrl+G) should generally trigger when InputText() is active.
10363 // TL;DR: lettered shortcut with no mods or with only Alt mod will not trigger while an item reading text input is active.
10364 // (We cannot filter based on io.InputQueueCharacters[] contents because of trickling and key<>chars submission order are undefined)
10365 if (g.IO.WantTextInput && IsKeyChordPotentiallyCharInput(key_chord))
10366 {
10367 IMGUI_DEBUG_LOG_INPUTROUTING("SetShortcutRouting(%s, flags=%04X, owner_id=0x%08X) -> filtered as potential char input\n", GetKeyChordName(key_chord), flags, owner_id);
10368 return false;
10369 }
10370
10371 // ActiveIdUsingAllKeyboardKeys trumps all for ActiveId
10372 if ((flags & ImGuiInputFlags_RouteOverActive) == 0 && g.ActiveIdUsingAllKeyboardKeys)
10373 {
10374 ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
10375 if (key == ImGuiKey_None)
10376 key = ConvertSingleModFlagToKey((ImGuiKey)(key_chord & ImGuiMod_Mask_));
10377 if (key >= ImGuiKey_Keyboard_BEGIN && key < ImGuiKey_Keyboard_END)
10378 return false;
10379 }
10380 }

Callers

nothing calls this directly

Calls 4

ImIsPowerOfTwoFunction · 0.85
CalcRoutingScoreFunction · 0.85

Tested by

no test coverage detected