win32: remove all NC area on Windows 10 with --title-bar=no

Windows 10 top bar height cannot be adjusted individually when
WS_CAPTION is enabled due to buggy DWM NC drawing behavior. The issue is
fixed in Windows 11.

To keep consistent window look remove the border on each side, but only
on Windows 10.
This commit is contained in:
Kacper Michajłow 2023-12-07 15:08:01 +01:00 committed by Dudemanguy
parent e8b085fbb5
commit c155c18023
1 changed files with 12 additions and 3 deletions

View File

@ -241,9 +241,12 @@ static int get_title_bar_height(struct vo_w32_state *w32)
{
assert(!w32->opts->title_bar && w32->opts->border);
UINT visible_border = 0;
// Only available on Windows 11
DwmGetWindowAttribute(w32->window, DWMWA_VISIBLE_FRAME_BORDER_THICKNESS,
&visible_border, sizeof(visible_border));
// Only available on Windows 11, check in case it's backported and breaks
// WM_NCCALCSIZE exception for Windows 10.
if (check_windows10_build(22000)) {
DwmGetWindowAttribute(w32->window, DWMWA_VISIBLE_FRAME_BORDER_THICKNESS,
&visible_border, sizeof(visible_border));
}
int top_bar = IsMaximized(w32->window)
? get_system_metrics(w32, SM_CYFRAME) +
get_system_metrics(w32, SM_CXPADDEDBORDER)
@ -271,6 +274,8 @@ static void add_window_borders(struct vo_w32_state *w32, HWND hwnd, RECT *rc)
if (w32->opts->border && !w32->opts->title_bar && !w32->current_fs &&
(GetWindowLongPtrW(w32->window, GWL_STYLE) & WS_CAPTION))
{
if (!check_windows10_build(22000) && !IsMaximized(w32->window))
*rc = win;
rc->top = win.top - get_title_bar_height(w32);
}
}
@ -1650,6 +1655,10 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
!w32->current_fs && !w32->parent &&
(GetWindowLongPtrW(w32->window, GWL_STYLE) & WS_CAPTION))
{
// Remove all NC area on Windows 10 due to inability to control the
// top bar height before Windows 11.
if (!check_windows10_build(22000) && !IsMaximized(w32->window))
return 0;
RECT r = {0};
adjust_window_rect(w32, w32->window, &r);
NCCALCSIZE_PARAMS *p = (LPNCCALCSIZE_PARAMS)lParam;