From 2c8fd6087012156108b4a60b7369e74aaf6b03e6 Mon Sep 17 00:00:00 2001 From: alexei-zebra Date: Sun, 11 Oct 2026 22:04:20 +0300 Subject: [PATCH] Keep the windows frame free of the native frame leftovers Windows leaves a strip of the native frame behind when WM_NCCALCSIZE returns without correcting the rectangle it proposes, and that strip stays black because nothing paints it. The client area is now set to the window rectangle explicitly, the resize borders still come from WS_THICKFRAME and from the frame hit test. WM_SIZE also carries the new client size, which the platform may not have reported to the engine yet. The frame used to be drawn for the previous size and was then skipped by the one frame per size check, so the window seemed to change its size only after the drag was over. The size is passed to the refresh callback and applied before the frame is drawn. --- src/window/detail/FrameOperations.cpp | 29 ++++++++++++++++++++------- src/window/detail/FrameOperations.hpp | 4 +++- src/window/detail/GLFWWindow.cpp | 13 ++++++++++-- 3 files changed, 36 insertions(+), 10 deletions(-) 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