From 74a28cebe57da0f1b527ee453284604671768f22 Mon Sep 17 00:00:00 2001 From: alexei-zebra Date: Sat, 10 Oct 2026 23:04:27 +0300 Subject: [PATCH] Fix the windows frame hang and center new windows The frame is set up again after every window mode change, but it subclassed the window procedure each time and stored our own procedure as the original one. Every message we do not handle then went through CallWindowProc straight back into ourselves: the window hung, and repaint messages were lost with it, which is what broke the live rendering during a resize. The subclass is installed once now, while the window style is still re-applied on every mode change. New windows are also placed at the center of the monitor work area instead of the top left corner. This only happens where the platform lets the client place its window, which wayland does not. --- src/window/detail/FrameOperations.cpp | 12 +++++++++--- src/window/detail/GLFWWindow.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/window/detail/FrameOperations.cpp b/src/window/detail/FrameOperations.cpp index 530869769..76effe5f8 100644 --- a/src/window/detail/FrameOperations.cpp +++ b/src/window/detail/FrameOperations.cpp @@ -277,9 +277,15 @@ void frame_setup_native( style |= WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU; style &= ~WS_CAPTION; SetWindowLongPtr(hwnd, GWL_STYLE, style); - original_window_proc = reinterpret_cast(SetWindowLongPtr( - hwnd, GWLP_WNDPROC, reinterpret_cast(frame_window_proc) - )); + // Only subclass once: storing our own procedure as the original one + // would send every unhandled message back into it, forever. + const LONG_PTR current = GetWindowLongPtr(hwnd, GWLP_WNDPROC); + if (current != reinterpret_cast(frame_window_proc)) { + original_window_proc = reinterpret_cast(current); + SetWindowLongPtr( + hwnd, GWLP_WNDPROC, reinterpret_cast(frame_window_proc) + ); + } SetWindowPos( hwnd, nullptr, diff --git a/src/window/detail/GLFWWindow.cpp b/src/window/detail/GLFWWindow.cpp index 28a753269..633af93b1 100644 --- a/src/window/detail/GLFWWindow.cpp +++ b/src/window/detail/GLFWWindow.cpp @@ -56,6 +56,16 @@ static bool use_engine_frame() { #endif } +/// @brief Whether the platform lets the client place its own window +static bool can_place_window() { +#if GLFW_VERSION_MAJOR > 3 || \ + (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4) + return glfwGetPlatform() != GLFW_PLATFORM_WAYLAND; +#else + return true; +#endif +} + static std::unordered_set supported_gl_extensions; static void window_size_callback(GLFWwindow* window, int width, int height); @@ -980,6 +990,22 @@ std::tuple< glfwTerminate(); return {nullptr, nullptr}; } + if (can_place_window()) { + int areaX = 0, areaY = 0, areaWidth = 0, areaHeight = 0; + glfwGetMonitorWorkarea( + glfwGetPrimaryMonitor(), + &areaX, + &areaY, + &areaWidth, + &areaHeight + ); + glfwSetWindowPos( + window, + areaX + (areaWidth - width) / 2, + areaY + (areaHeight - height) / 2 + ); + } + glfwMakeContextCurrent(window); glewExperimental = GL_TRUE;