diff --git a/src/window/detail/FrameOperations.cpp b/src/window/detail/FrameOperations.cpp index 6eed04f7f..25755c7dd 100644 --- a/src/window/detail/FrameOperations.cpp +++ b/src/window/detail/FrameOperations.cpp @@ -36,12 +36,21 @@ namespace { HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { switch (message) { - case WM_NCCALCSIZE: - // the caption is gone, the whole window is the client area - if (wparam == TRUE) { - return 0; + case WM_NCCALCSIZE: { + // The caption is gone and the engine draws the whole frame, + // so the client area has to be the window itself. The + // rectangle Windows proposes here keeps a strip of the native + // frame, and that strip stays black because nothing paints it. + if (lparam == 0) { + break; } - break; + RECT window {}; + if (!GetWindowRect(hwnd, &window)) { + break; + } + reinterpret_cast(lparam)->rgrc[0] = window; + return 0; + } case WM_NCPAINT: // the frame is not drawn by us return 0; @@ -51,12 +60,18 @@ namespace { case WM_SIZE: { // Windows runs its own modal loop while a border is dragged // and never sends WM_PAINT there, so WM_SIZE is the only - // place to draw a frame from during such a resize. + // place to draw a frame from during such a resize. It also + // carries the new client size, which the platform may not + // have reported to the engine yet. const LRESULT result = CallWindowProc( original_window_proc, hwnd, message, wparam, lparam ); if (refresh_callback != nullptr) { - refresh_callback(refresh_userdata); + refresh_callback( + refresh_userdata, + static_cast(LOWORD(lparam)), + static_cast(HIWORD(lparam)) + ); } return result; } diff --git a/src/window/detail/FrameOperations.hpp b/src/window/detail/FrameOperations.hpp index 9cb8ecc0b..625b665ed 100644 --- a/src/window/detail/FrameOperations.hpp +++ b/src/window/detail/FrameOperations.hpp @@ -22,7 +22,9 @@ bool frame_start_move(GLFWwindow* window); bool frame_start_resize(GLFWwindow* window, int edges); /// @brief Called when the windowing system wants the content redrawn -using FrameRefresh = void (*)(void*); +/// @param width new client width, 0 when the system does not know it +/// @param height new client height, 0 when the system does not know it +using FrameRefresh = void (*)(void*, int width, int height); /// @brief Hide the caption of the native frame, keeping the rest of it /// @param hitTest tells what the pointer is over diff --git a/src/window/detail/GLFWWindow.cpp b/src/window/detail/GLFWWindow.cpp index db735d7b1..f8b28fe41 100644 --- a/src/window/detail/GLFWWindow.cpp +++ b/src/window/detail/GLFWWindow.cpp @@ -405,8 +405,17 @@ public: inRefreshCallback = false; } - static void frame_refresh_thunk(void* userdata) { - static_cast(userdata)->drawRefreshFrame(); + static void frame_refresh_thunk(void* userdata, int width, int height) { + auto* self = static_cast(userdata); + // The platform reports the new size from its own message loop, where + // GLFW has not updated the window yet: without this the frame is + // drawn for the previous size and leaves an unpainted strip behind. + if (width > 0 && height > 0 && + self->getSize() != glm::ivec2(width, height)) { + self->setSize(width, height); + self->resetScissor(); + } + self->drawRefreshFrame(); } /// @brief Set while a frame is drawn from the refresh callback