Begin: Simplified code and fixed a bug where appending into a window a second time (from a remote window) would incorrectly overwrite RootWindow with the current window in the stack. Our docking code uses this pattern.
window->RootNonPopupWindow=g.CurrentWindowStack[root_non_popup_idx];// Used to display TitleBgActive color and for selecting which window to use for NavWindowing
// When reusing window again multiple times a frame, just append content (don't need to setup again)
window->RootNonPopupWindow=!(flags&(ImGuiWindowFlags_ChildWindow|ImGuiWindowFlags_Popup))||(flags&ImGuiWindowFlags_Modal)?window:parent_window->RootNonPopupWindow;// Used to display TitleBgActive color and for selecting which window to use for NavWindowing