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

Method FocusWindow

imgui_tiny_app/imgui/imgui.cpp:13643–13710  ·  view source on GitHub ↗

Moving window to front of display and set focus (which happens to be back of our sorted list)

Source from the content-addressed store, hash-verified

13641
13642// Moving window to front of display and set focus (which happens to be back of our sorted list)
13643void ImGui::FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags)
13644{
13645 ImGuiContext& g = *GImGui;
13646
13647 // Modal check?
13648 if ((flags & ImGuiFocusRequestFlags_UnlessBelowModal) && (g.NavWindow != window)) // Early out in common case.
13649 if (ImGuiWindow* blocking_modal = FindBlockingModal(window))
13650 {
13651 // This block would typically be reached in two situations:
13652 // - API call to FocusWindow() with a window under a modal and ImGuiFocusRequestFlags_UnlessBelowModal flag.
13653 // - User clicking on void or anything behind a modal while a modal is open (window == NULL)
13654 IMGUI_DEBUG_LOG_FOCUS("[focus] FocusWindow(\"%s\", UnlessBelowModal): prevented by \"%s\".\n", window ? window->Name : "<NULL>", blocking_modal->Name);
13655 if (window && window == window->RootWindow && (window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0)
13656 BringWindowToDisplayBehind(window, blocking_modal); // Still bring right under modal. (FIXME: Could move in focus list too?)
13657 ClosePopupsOverWindow(GetTopMostPopupModal(), false); // Note how we need to use GetTopMostPopupModal() aad NOT blocking_modal, to handle nested modals
13658 return;
13659 }
13660
13661 // Find last focused child (if any) and focus it instead.
13662 if ((flags & ImGuiFocusRequestFlags_RestoreFocusedChild) && window != NULL)
13663 window = NavRestoreLastChildNavWindow(window);
13664
13665 // Apply focus
13666 if (g.NavWindow != window)
13667 {
13668 SetNavWindow(window);
13669 if (window && g.NavHighlightItemUnderNav)
13670 g.NavMousePosDirty = true;
13671 g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId
13672 g.NavLayer = ImGuiNavLayer_Main;
13673 SetNavFocusScope(window ? window->NavRootFocusScopeId : 0);
13674 g.NavIdIsAlive = false;
13675 g.NavLastValidSelectionUserData = ImGuiSelectionUserData_Invalid;
13676
13677 // Close popups if any
13678 ClosePopupsOverWindow(window, false);
13679 }
13680
13681 // Move the root window to the top of the pile
13682 IM_ASSERT(window == NULL || window->RootWindowDockTree != NULL);
13683 ImGuiWindow* focus_front_window = window ? window->RootWindow : NULL;
13684 ImGuiWindow* display_front_window = window ? window->RootWindowDockTree : NULL;
13685 ImGuiDockNode* dock_node = window ? window->DockNode : NULL;
13686 bool active_id_window_is_dock_node_host = (g.ActiveIdWindow && dock_node && dock_node->HostWindow == g.ActiveIdWindow);
13687
13688 // Steal active widgets. Some of the cases it triggers includes:
13689 // - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run.
13690 // - When using Nav to activate menu items (due to timing of activating on press->new window appears->losing ActiveId)
13691 // - Using dock host items (tab, collapse button) can trigger this before we redirect the ActiveIdWindow toward the child window.
13692 if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != focus_front_window)
13693 if (!g.ActiveIdNoClearOnFocusLoss && !active_id_window_is_dock_node_host)
13694 ClearActiveID();
13695
13696 // Passing NULL allow to disable keyboard focus
13697 if (!window)
13698 return;
13699 window->LastFrameJustFocused = g.FrameCount;
13700

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected