Skip to content

Commit

Permalink
FocusWindow should not set platform focus unless an explicit user cod…
Browse files Browse the repository at this point in the history
…e call to prevent loss of mouse focus during move/resize
  • Loading branch information
dougbinks committed Sep 16, 2021
1 parent 9b8efc6 commit 7e03bd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6327,7 +6327,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasCollapsed)
SetWindowCollapsed(window, g.NextWindowData.CollapsedVal, g.NextWindowData.CollapsedCond);
if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasFocus)
FocusWindow(window);
FocusWindow(window,true);
if (window->Appearing)
SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false);

Expand Down Expand Up @@ -7032,7 +7032,7 @@ void ImGui::BringWindowToFocusFront(ImGuiWindow* window)
window->FocusOrder = (short)new_order;
}

void ImGui::BringWindowToDisplayFront(ImGuiWindow* window)
void ImGui::BringWindowToDisplayFront(ImGuiWindow* window, bool platform_front)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* current_front_window = g.Windows.back();
Expand All @@ -7047,7 +7047,7 @@ void ImGui::BringWindowToDisplayFront(ImGuiWindow* window)
}
}
// Even if window is front it may not be brought to front at OS level, so always do this
if (g.PlatformIO.Platform_SetWindowFocus && window->Viewport && window->Viewport->PlatformWindowCreated )
if (platform_front && g.PlatformIO.Platform_SetWindowFocus && window->Viewport && window->Viewport->PlatformWindowCreated )
g.PlatformIO.Platform_SetWindowFocus(window->Viewport);
}

Expand All @@ -7066,7 +7066,7 @@ void ImGui::BringWindowToDisplayBack(ImGuiWindow* window)
}

// Moving window to front of display and set focus (which happens to be back of our sorted list)
void ImGui::FocusWindow(ImGuiWindow* window)
void ImGui::FocusWindow(ImGuiWindow* window, bool platform_front)
{
ImGuiContext& g = *GImGui;

Expand Down Expand Up @@ -7114,7 +7114,7 @@ void ImGui::FocusWindow(ImGuiWindow* window)
// Bring to front
BringWindowToFocusFront(focus_front_window);
if (((window->Flags | focus_front_window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0)
BringWindowToDisplayFront(display_front_window);
BringWindowToDisplayFront(display_front_window,platform_front);
}

void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window)
Expand Down Expand Up @@ -7525,11 +7525,11 @@ void ImGui::SetWindowFocus(const char* name)
if (name)
{
if (ImGuiWindow* window = FindWindowByName(name))
FocusWindow(window);
FocusWindow(window,true);
}
else
{
FocusWindow(NULL);
FocusWindow(NULL,true);
}
}

Expand Down
4 changes: 2 additions & 2 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2568,10 +2568,10 @@ namespace ImGui
IMGUI_API void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size);

// Windows: Display Order and Focus Order
IMGUI_API void FocusWindow(ImGuiWindow* window);
IMGUI_API void FocusWindow(ImGuiWindow* window, bool platform_front = false);
IMGUI_API void FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window);
IMGUI_API void BringWindowToFocusFront(ImGuiWindow* window);
IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window);
IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window, bool platform_front = false);
IMGUI_API void BringWindowToDisplayBack(ImGuiWindow* window);

// Fonts, drawing
Expand Down

0 comments on commit 7e03bd4

Please sign in to comment.