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.
This commit is contained in:
alexei-zebra 2026-10-11 22:04:20 +03:00
parent b6f6235249
commit 2c8fd60870
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
3 changed files with 36 additions and 10 deletions

View file

@ -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<NCCALCSIZE_PARAMS*>(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<int>(LOWORD(lparam)),
static_cast<int>(HIWORD(lparam))
);
}
return result;
}

View file

@ -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

View file

@ -405,8 +405,17 @@ public:
inRefreshCallback = false;
}
static void frame_refresh_thunk(void* userdata) {
static_cast<GLFWWindow*>(userdata)->drawRefreshFrame();
static void frame_refresh_thunk(void* userdata, int width, int height) {
auto* self = static_cast<GLFWWindow*>(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