Skip to content

Commit

Permalink
win32: fix window size restore after maximize state
Browse files Browse the repository at this point in the history
This remembers and sets window-scale when exiting maximized state. Also
fixes not staying in maximized state when exiting fullscreen mode.

Fixes: mpv-player#14126
  • Loading branch information
kasper93 committed May 12, 2024
1 parent 64ae539 commit b4b558b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions video/out/w32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,15 @@ static void update_fullscreen_state(struct vo_w32_state *w32)
m_config_cache_write_opt(w32->opts_cache,
&w32->opts->fullscreen);

if (toggle_fs) {
if (toggle_fs && !w32->opts->window_maximized) {
if (w32->current_fs) {
// Save window rect when switching to fullscreen.
// Save window rect when switching to fullscreen or maximizing.
w32->prev_windowrc = w32->windowrc;
MP_VERBOSE(w32, "save window bounds: %d:%d:%d:%d\n",
(int)w32->windowrc.left, (int)w32->windowrc.top,
(int)rect_w(w32->windowrc), (int)rect_h(w32->windowrc));
} else {
// Restore window rect when switching from fullscreen.
// Restore window rect when switching from fullscreen or maximized.
w32->windowrc = w32->prev_windowrc;
}
}
Expand All @@ -1116,6 +1116,8 @@ static void update_minimized_state(struct vo_w32_state *w32)
}
}

static void update_window_state(struct vo_w32_state *w32);

static void update_maximized_state(struct vo_w32_state *w32, bool leaving_fullscreen)
{
if (w32->parent)
Expand All @@ -1127,6 +1129,8 @@ static void update_maximized_state(struct vo_w32_state *w32, bool leaving_fullsc
if (w32->current_fs && !leaving_fullscreen)
return;

bool toggle = !w32->opts->window_maximized && IsMaximized(w32->window);

WINDOWPLACEMENT wp = { .length = sizeof wp };
GetWindowPlacement(w32->window, &wp);

Expand All @@ -1146,6 +1150,11 @@ static void update_maximized_state(struct vo_w32_state *w32, bool leaving_fullsc
ShowWindow(w32->window, SW_SHOWNOACTIVATE);
}
}

if (toggle && !w32->current_fs) {
w32->windowrc = w32->prev_windowrc;
update_window_state(w32);
}
}

static bool is_visible(HWND window)
Expand Down Expand Up @@ -2291,7 +2300,8 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
if (!w32->window_bounds_initialized)
return VO_FALSE;

RECT *rc = w32->current_fs ? &w32->prev_windowrc : &w32->windowrc;
RECT *rc = (w32->current_fs || w32->opts->window_maximized)
? &w32->prev_windowrc : &w32->windowrc;
s[0] = rect_w(*rc);
s[1] = rect_h(*rc);
return VO_TRUE;
Expand All @@ -2305,7 +2315,7 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
RECT *rc = w32->current_fs ? &w32->prev_windowrc : &w32->windowrc;
resize_and_move_rect(w32, rc, s[0], s[1]);

if (w32->opts->window_maximized) {
if (w32->opts->window_maximized && !w32->current_fs) {
w32->unmaximize = true;
}
w32->fit_on_screen = true;
Expand Down

0 comments on commit b4b558b

Please sign in to comment.