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;