Fix window clipping when maximized

This commit is contained in:
Mohit Sethi 2022-12-13 14:57:46 +05:30
parent 32af069108
commit db92674a9e

View File

@ -491,8 +491,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam) WPARAM wParam, LPARAM lParam)
{ {
static RECT border_thickness = { 0, 0, 0, 0 }; static RECT border_thickness = { 0, 0, 0, 0 };
if (!_glfw.hints.window.titlebar) BOOL hasThickFrame = GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME;
SetRect(&border_thickness, 8, 8, 8, 8);
_GLFWwindow* window = GetPropW(hWnd, L"GLFW"); _GLFWwindow* window = GetPropW(hWnd, L"GLFW");
if (!window) if (!window)
@ -550,8 +549,21 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; break;
MARGINS margins = { 0 }; if (hasThickFrame)
DwmExtendFrameIntoClientArea(hWnd, &margins); {
RECT size_rect;
GetWindowRect(hWnd, &size_rect);
// Inform the application of the frame change to force redrawing with the new
// client area that is extended into the title bar
SetWindowPos(
hWnd, NULL,
size_rect.left, size_rect.top,
size_rect.right - size_rect.left, size_rect.bottom - size_rect.top,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE
);
break;
}
break; break;
} }
@ -561,9 +573,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; break;
MARGINS margins = { 0 }; RECT title_bar_rect = {0};
DwmExtendFrameIntoClientArea(hWnd, &margins); InvalidateRect(hWnd, &title_bar_rect, FALSE);
break; break;
} }
} }
@ -995,16 +1006,28 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
} }
case WM_NCCALCSIZE: case WM_NCCALCSIZE:
{ {
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar || !hasThickFrame || !wParam)
break; break;
if (lParam) UINT dpi = GetDpiForWindow(hWnd);
return 0;
int frame_x = GetSystemMetricsForDpi(SM_CXFRAME, dpi);
int frame_y = GetSystemMetricsForDpi(SM_CYFRAME, dpi);
int padding = GetSystemMetricsForDpi(92, dpi);
NCCALCSIZE_PARAMS* params = (NCCALCSIZE_PARAMS*)lParam;
RECT* requested_client_rect = params->rgrc;
requested_client_rect->right -= frame_x + padding;
requested_client_rect->left += frame_x + padding;
requested_client_rect->bottom -= frame_y + padding;
requested_client_rect->top += frame_y + (window->win32.maximized ? 1.0f : -1.0f) * padding;
return 0;
}
break;
}
case WM_SIZE: case WM_SIZE:
{ {
const int width = LOWORD(lParam); const int width = LOWORD(lParam);
@ -1045,6 +1068,18 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
window->win32.iconified = iconified; window->win32.iconified = iconified;
window->win32.maximized = maximized; window->win32.maximized = maximized;
RECT size_rect;
GetWindowRect(hWnd, &size_rect);
// Inform the application of the frame change to force redrawing with the new
// client area that is extended into the title bar
SetWindowPos(
hWnd, NULL,
size_rect.left, size_rect.top,
size_rect.right - size_rect.left, size_rect.bottom - size_rect.top,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE
);
return 0; return 0;
} }
@ -1253,10 +1288,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; break;
// Extend the frame into the client area. RECT title_bar_rect = { 0 };
MARGINS margins = { 0 }; InvalidateRect(hWnd, &title_bar_rect, FALSE);
DwmExtendFrameIntoClientArea(hWnd, &margins);
break; break;
} }
case WM_NCHITTEST: case WM_NCHITTEST:
@ -1264,28 +1297,26 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; break;
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME) if (hasThickFrame)
{ {
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ScreenToClient(hWnd, &pt); ScreenToClient(hWnd, &pt);
RECT rc;
GetClientRect(hWnd, &rc); if (!window->win32.maximized)
int titlebarHittest = 0;
_glfwInputTitleBarHitTest(window, pt.x, pt.y, &titlebarHittest);
if (titlebarHittest)
{
return HTCAPTION;
}
else
{ {
RECT rc;
GetClientRect(hWnd, &rc);
UINT dpi = GetDpiForWindow(hWnd);
int frame_y = GetSystemMetricsForDpi(SM_CYFRAME, dpi);
int padding = GetSystemMetricsForDpi(92, dpi);
enum { left = 1, top = 2, right = 4, bottom = 8 }; enum { left = 1, top = 2, right = 4, bottom = 8 };
int hit = 0; int hit = 0;
if (pt.x < border_thickness.left) hit |= left; if (pt.x < border_thickness.left) hit |= left;
if (pt.x > rc.right - border_thickness.right) hit |= right; if (pt.x > rc.right - border_thickness.right) hit |= right;
if (pt.y < border_thickness.top) hit |= top; if (pt.y < border_thickness.top || pt.y < frame_y + padding) hit |= top;
if (pt.y > rc.bottom - border_thickness.bottom) hit |= bottom; if (pt.y > rc.bottom - border_thickness.bottom) hit |= bottom;
if (hit & top && hit & left) return HTTOPLEFT; if (hit & top && hit & left) return HTTOPLEFT;
if (hit & top && hit & right) return HTTOPRIGHT; if (hit & top && hit & right) return HTTOPRIGHT;
@ -1295,9 +1326,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (hit & top) return HTTOP; if (hit & top) return HTTOP;
if (hit & right) return HTRIGHT; if (hit & right) return HTRIGHT;
if (hit & bottom) return HTBOTTOM; if (hit & bottom) return HTBOTTOM;
return HTCLIENT;
} }
int titlebarHittest = 0;
_glfwInputTitleBarHitTest(window, pt.x, pt.y, &titlebarHittest);
if (titlebarHittest)
return HTCAPTION;
return HTCLIENT;
} }
} }
} }