Skip to content

Commit

Permalink
win32: fix maximize state with --border=no
Browse files Browse the repository at this point in the history
WS_POPUP windows cannot be maximized, so instead of forcing it with
unavoidable side-effects, change the window style before maximizing to
make it work correctly.
  • Loading branch information
kasper93 committed May 5, 2024
1 parent 646f31f commit 4cc9e6f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions video/out/w32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static inline int get_system_metrics(struct vo_w32_state *w32, int metric)

static void adjust_window_rect(struct vo_w32_state *w32, HWND hwnd, RECT *rc)
{
if (!w32->opts->border)
if (!w32->opts->border && !IsMaximized(w32->window))
return;

if (w32->api.pAdjustWindowRectExForDpi) {
Expand Down Expand Up @@ -244,7 +244,7 @@ static bool check_windows10_build(DWORD build)
// Get adjusted title bar height, only relevant for --title-bar=no
static int get_title_bar_height(struct vo_w32_state *w32)
{
assert(!w32->opts->title_bar && w32->opts->border);
assert(w32->opts->border ? !w32->opts->title_bar : IsMaximized(w32->window));
UINT visible_border = 0;
// Only available on Windows 11, check in case it's backported and breaks
// WM_NCCALCSIZE exception for Windows 10.
Expand Down Expand Up @@ -957,7 +957,7 @@ static DWORD update_style(struct vo_w32_state *w32, DWORD style)
if (w32->current_fs) {
style |= FULLSCREEN;
} else {
style |= w32->opts->border ? FRAME : NO_FRAME;
style |= (w32->opts->border || w32->opts->window_maximized) ? FRAME : NO_FRAME;
if (!w32->opts->title_bar && is_high_contrast())
style &= ~WS_CAPTION;
}
Expand Down Expand Up @@ -1121,6 +1121,8 @@ static void update_maximized_state(struct vo_w32_state *w32, bool leaving_fullsc
if (w32->parent)
return;

update_window_style(w32);

// Apply the maximized state on leaving fullscreen.
if (w32->current_fs && !leaving_fullscreen)
return;
Expand Down Expand Up @@ -1467,6 +1469,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
(wp.flags & WPF_RESTORETOMAXIMIZED));
if (w32->opts->window_maximized != is_maximized) {
w32->opts->window_maximized = is_maximized;
update_window_style(w32);
m_config_cache_write_opt(w32->opts_cache,
&w32->opts->window_maximized);
}
Expand Down Expand Up @@ -1701,12 +1704,13 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
update_window_state(w32);
break;
case WM_NCCALCSIZE:
if (!w32->opts->border)
if (!w32->opts->border && !IsMaximized(w32->window))
return 0;

// Apparently removing WS_CAPTION disables some window animation, instead
// just reduce non-client size to remove title bar.
if (wParam && lParam && w32->opts->border && !w32->opts->title_bar &&
!w32->current_fs && !w32->parent &&
if (wParam && lParam && !w32->current_fs && !w32->parent &&
(w32->opts->border ? !w32->opts->title_bar : IsMaximized(w32->window)) &&
(GetWindowLongPtrW(w32->window, GWL_STYLE) & WS_CAPTION))
{
// Remove all NC area on Windows 10 due to inability to control the
Expand Down

0 comments on commit 4cc9e6f

Please sign in to comment.