From 58eb40db76783f5da09e592ca3eb421f4f2197e3 Mon Sep 17 00:00:00 2001 From: Runik Date: Wed, 29 Jun 2022 15:46:13 +0200 Subject: [PATCH] Backends: GLFW: Fixed leftover static variable preventing from changing or reinitializing backend while application is running. (#4616, #5434) --- backends/imgui_impl_glfw.cpp | 12 ++++++++---- docs/CHANGELOG.txt | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index e996fa63425d..bc2d778190da 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -123,6 +123,9 @@ struct ImGui_ImplGlfw_Data GLFWwindow* KeyOwnerWindows[GLFW_KEY_LAST]; bool InstalledCallbacks; bool WantUpdateMonitors; +#ifdef _WIN32 + WNDPROC GlfwWndProc; +#endif // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. GLFWwindowfocusfun PrevUserCallbackWindowFocus; @@ -937,9 +940,9 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport) // We have submitted https://github.com/glfw/glfw/pull/1568 to allow GLFW to support "transparent inputs". // In the meanwhile we implement custom per-platform workarounds here (FIXME-VIEWPORT: Implement same work-around for Linux/OSX!) #if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32) -static WNDPROC g_GlfwWndProc = NULL; static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (msg == WM_NCHITTEST) { // Let mouse pass-through the window. This will allow the backend to call io.AddMouseViewportEvent() properly (which is OPTIONAL). @@ -950,7 +953,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR if (viewport->Flags & ImGuiViewportFlags_NoInputs) return HTTRANSPARENT; } - return ::CallWindowProc(g_GlfwWndProc, hWnd, msg, wParam, lParam); + return ::CallWindowProc(bd->GlfwWndProc, hWnd, msg, wParam, lParam); } #endif @@ -971,9 +974,10 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport) // GLFW hack: install hook for WM_NCHITTEST message handler #if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32) + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ::SetPropA(hwnd, "IMGUI_VIEWPORT", viewport); - if (g_GlfwWndProc == NULL) - g_GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC); + if (bd->GlfwWndProc == NULL) + bd->GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC); ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProcNoInputs); #endif diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 09b4ce43cff5..caaf6315c6a4 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -98,6 +98,20 @@ Other changes: Note that Linux/Mac still have inconsistent support for multi-viewports. If you want to help see https://github.com/ocornut/imgui/issues/2117. +----------------------------------------------------------------------- + VERSION 1.89 WIP (In Progress) +----------------------------------------------------------------------- + +Breaking changes: + +Other Changes: + +Docking+Viewports Branch: + +- Backends: GLFW: Fixed leftover static variable preventing from changing or + reinitializing backend while application is running. (#4616, #5434) [@rtoumazet] + + ----------------------------------------------------------------------- VERSION 1.88 (Released 2022-06-21) -----------------------------------------------------------------------