Skip to content

Commit 58eb40d

Browse files
rtoumazetocornut
authored andcommitted
Backends: GLFW: Fixed leftover static variable preventing from changing or reinitializing backend while application is running. (#4616, #5434)
1 parent 9cd9c2e commit 58eb40d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

backends/imgui_impl_glfw.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ struct ImGui_ImplGlfw_Data
123123
GLFWwindow* KeyOwnerWindows[GLFW_KEY_LAST];
124124
bool InstalledCallbacks;
125125
bool WantUpdateMonitors;
126+
#ifdef _WIN32
127+
WNDPROC GlfwWndProc;
128+
#endif
126129

127130
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
128131
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
@@ -937,9 +940,9 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
937940
// We have submitted https://github.com/glfw/glfw/pull/1568 to allow GLFW to support "transparent inputs".
938941
// In the meanwhile we implement custom per-platform workarounds here (FIXME-VIEWPORT: Implement same work-around for Linux/OSX!)
939942
#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)
940-
static WNDPROC g_GlfwWndProc = NULL;
941943
static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
942944
{
945+
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
943946
if (msg == WM_NCHITTEST)
944947
{
945948
// 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
950953
if (viewport->Flags & ImGuiViewportFlags_NoInputs)
951954
return HTTRANSPARENT;
952955
}
953-
return ::CallWindowProc(g_GlfwWndProc, hWnd, msg, wParam, lParam);
956+
return ::CallWindowProc(bd->GlfwWndProc, hWnd, msg, wParam, lParam);
954957
}
955958
#endif
956959

@@ -971,9 +974,10 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
971974

972975
// GLFW hack: install hook for WM_NCHITTEST message handler
973976
#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)
977+
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
974978
::SetPropA(hwnd, "IMGUI_VIEWPORT", viewport);
975-
if (g_GlfwWndProc == NULL)
976-
g_GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC);
979+
if (bd->GlfwWndProc == NULL)
980+
bd->GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC);
977981
::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProcNoInputs);
978982
#endif
979983

docs/CHANGELOG.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ Other changes:
9898
Note that Linux/Mac still have inconsistent support for multi-viewports. If you want to help see https://github.com/ocornut/imgui/issues/2117.
9999

100100

101+
-----------------------------------------------------------------------
102+
VERSION 1.89 WIP (In Progress)
103+
-----------------------------------------------------------------------
104+
105+
Breaking changes:
106+
107+
Other Changes:
108+
109+
Docking+Viewports Branch:
110+
111+
- Backends: GLFW: Fixed leftover static variable preventing from changing or
112+
reinitializing backend while application is running. (#4616, #5434) [@rtoumazet]
113+
114+
101115
-----------------------------------------------------------------------
102116
VERSION 1.88 (Released 2022-06-21)
103117
-----------------------------------------------------------------------

0 commit comments

Comments
 (0)