Merge e0d466b5004ebc884f6bb485af165701b8d8c7fa into 1f3ee75ee40c7f224714cd6896f152a902e81652

This commit is contained in:
The Loki 2026-11-05 11:45:34 +01:00 committed by GitHub
commit c095e43dba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -309,6 +309,7 @@ static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData(GLFWwindow* window)
// Forward Declarations
static void ImGui_ImplGlfw_UpdateMonitors();
static void ImGui_ImplGlfw_UpdateViewports();
static void ImGui_ImplGlfw_InitMultiViewportSupport();
static void ImGui_ImplGlfw_ShutdownMultiViewportSupport();
@ -1217,6 +1218,7 @@ void ImGui_ImplGlfw_NewFrame()
bd->Time = current_time;
bd->MouseIgnoreButtonUp = false;
ImGui_ImplGlfw_UpdateViewports();
ImGui_ImplGlfw_UpdateMouseData();
ImGui_ImplGlfw_UpdateMouseCursor();
@ -1298,6 +1300,7 @@ struct ImGui_ImplGlfw_ViewportData
{
GLFWwindow* Window; // Stored in ImGuiViewport::PlatformHandle
bool WindowOwned;
bool PlatformRequestResizeNextFrame;
int IgnoreWindowPosEventFrame;
int IgnoreWindowSizeEventFrame;
#ifdef _WIN32
@ -1308,6 +1311,25 @@ struct ImGui_ImplGlfw_ViewportData
~ImGui_ImplGlfw_ViewportData() { IM_ASSERT(Window == nullptr); }
};
static void ImGui_ImplGlfw_UpdateViewports()
{
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
for (int n = 0; n < platform_io.Viewports.Size; n++)
{
ImGuiViewport* viewport = platform_io.Viewports[n];
if (ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData){
if(vd->PlatformRequestResizeNextFrame){
// The previous frame's windowSizeCallback was invoked when glfwSetWindowPos was used, not triggered by glfwPollEvent.
// At this point, some critical operations that depend on PlatformRequestResize have already been completed.
// The PlatformRequestResize flag is cleared at the end of the frame,
// so we delay the operation to the current frame to ensure that the PlatformRequestResize behavior is fully completed.
viewport->PlatformRequestResize = true;
vd->PlatformRequestResizeNextFrame = false;
}
}
}
}
static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window)
{
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
@ -1345,6 +1367,15 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
//data->IgnoreWindowSizeEventFrame = -1;
if (ignore_event)
return;
bool delay_to_next_frame = (ImGui::GetFrameCount() <= vd->IgnoreWindowPosEventFrame + 1);
if(delay_to_next_frame){
// glfwSetWindowPos and glfwSetWindowSizeCallback are called in the same frame
// we should not process the resize event in this frame
vd->PlatformRequestResizeNextFrame = true;
return;
}
}
viewport->PlatformRequestResize = true;
}