message: Popups: popups can be closed with a right-click anywhere, without altering focus under the popup.(~#439)
diff: @@ -643,7 +643,7 @@ static void MarkIniSettingsDirty(ImGuiWindow* window);
  static ImRect GetVisibleRect();
  -static void CloseInactivePopups();
  +static void CloseInactivePopups(ImGuiWindow* ref_window);
  static void ClosePopupToLevel(int remaining);
  static ImGuiWindow* GetFrontMostModalRootWindow();
  static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size, int* last_dir, const ImRect& rect_to_avoid);
  @@ -2443,7 +2443,7 @@ void ImGui::NewFrame()
  // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  g.CurrentWindowStack.resize(0);
  g.CurrentPopupStack.resize(0);
  - CloseInactivePopups();
  + CloseInactivePopups(g.NavWindow);
  // Create implicit window - we will only render it if the user has added something to it.
  // We don't use "Debug" to avoid colliding with user trying to create a "Debug" window with custom flags.
  @@ -2775,7 +2775,7 @@ void ImGui::EndFrame()
  if (g.ActiveId == 0 && g.HoveredId == 0)
  {
  - if (!g.NavWindow || g.NavWindow->WasActive || !g.NavWindow->Active) // Unless we just made a popup appear
  + if (!g.NavWindow || !g.NavWindow->Appearing) // Unless we just made a window/popup appear
  {
  // Click to focus window and start moving (after we're done with all our widgets)
  if (g.IO.MouseClicked[0])
  @@ -2796,6 +2796,13 @@ void ImGui::EndFrame()
  FocusWindow(NULL);
  }
  }
  +
  + // With right mouse button we close popups without changing focus
  + // (The left mouse button path calls FocusWindow which will lead NewFrame->CloseInactivePopups to trigger)
  + if (g.IO.MouseClicked[1])
  + {
  + CloseInactivePopups(g.HoveredWindow);
  + }
  }
  }
  @@ -3569,7 +3576,7 @@ void ImGui::OpenPopup(const char* str_id)
  OpenPopupEx(g.CurrentWindow->GetID(str_id), false);
  }
  -static void CloseInactivePopups()
  +static void CloseInactivePopups(ImGuiWindow* ref_window)
  {
  ImGuiContext& g = *GImGui;
  if (g.OpenPopupStack.empty())
  @@ -3578,7 +3585,7 @@ static void CloseInactivePopups()
  // When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it.
  // Don't close our own child popup windows
  int n = 0;
  - if (g.NavWindow)
  + if (ref_window)
  {
  for (n = 0; n < g.OpenPopupStack.Size; n++)
  {
  @@ -3591,7 +3598,7 @@ static void CloseInactivePopups()
  bool has_focus = false;
  for (int m = n; m < g.OpenPopupStack.Size && !has_focus; m++)
  - has_focus = (g.OpenPopupStack[m].Window && g.OpenPopupStack[m].Window->RootWindow == g.NavWindow->RootWindow);
  + has_focus = (g.OpenPopupStack[m].Window && g.OpenPopupStack[m].Window->RootWindow == ref_window->RootWindow);
  if (!has_focus)
  break;
  }
  