summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-09 18:54:44 +0200
committerwm4 <wm4@nowhere>2014-09-10 00:48:07 +0200
commit670f965f1acef64069821df38edad1e64c289075 (patch)
tree45d75f8c3edbcf664986b883d47f4ea1653033a2 /video/out
parente1e8b07cfa04584000f7d203e5a8b71cb7b3f0a8 (diff)
downloadmpv-670f965f1acef64069821df38edad1e64c289075.tar.bz2
mpv-670f965f1acef64069821df38edad1e64c289075.tar.xz
win32: don't request window size larger than the screen
An attempt at fixing #1070. Apparently something goes wrong if the video size is equal to the screen size. Since the window decorations add to the window size, it must actually be larger than the screen. Actually I don't know what exactly is going wrong, but since this commit also slightly improves the behavior otherwise, it's a win anyway. Try to keep the window size strictly below screen size, even accounting for window decorations. Size it down and center the window so that it fits (by either touching the left/right or top/bottom screen borders). I haven't found any information on what is the maximum allowed size and position of a window so that it doesn't collide with the task bar, so assume that we can use the entire screen, minus 1 pixel to avoid triggering fullscreen semantics (if that is even possible).
Diffstat (limited to 'video/out')
-rw-r--r--video/out/w32_common.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/video/out/w32_common.c b/video/out/w32_common.c
index 4090200810..c106a386c5 100644
--- a/video/out/w32_common.c
+++ b/video/out/w32_common.c
@@ -824,6 +824,9 @@ static int reinit_window_state(struct vo_w32_state *w32)
// xxx not sure if this can trigger any unwanted messages (WM_MOVE/WM_SIZE)
updateScreenProperties(w32);
+ int screen_w = w32->screenrc.x1 - w32->screenrc.x0;
+ int screen_h = w32->screenrc.y1 - w32->screenrc.y0;
+
if (w32->opts->fullscreen) {
// Save window position and size when switching to fullscreen.
if (toggle_fs) {
@@ -837,9 +840,8 @@ static int reinit_window_state(struct vo_w32_state *w32)
w32->window_x = w32->screenrc.x0;
w32->window_y = w32->screenrc.y0;
- w32->dw = w32->screenrc.x1 - w32->screenrc.x0;
- w32->dh = w32->screenrc.y1 - w32->screenrc.y0;
- style &= ~WS_OVERLAPPEDWINDOW;
+ w32->dw = screen_w;
+ w32->dh = screen_h;
} else {
if (toggle_fs) {
// Restore window position and size when switching from fullscreen.
@@ -858,8 +860,37 @@ static int reinit_window_state(struct vo_w32_state *w32)
r.bottom = r.top + w32->dh;
SetWindowLong(w32->window, GWL_STYLE, style);
+
+ RECT cr = r;
add_window_borders(w32->window, &r);
+ if (!w32->opts->fullscreen &&
+ ((r.right - r.left) >= screen_w || (r.bottom - r.top) >= screen_h))
+ {
+ MP_VERBOSE(w32, "requested window size larger than the screen\n");
+ // Use the aspect of the client area, not the full window size.
+ // Basically, try to compute the maximum window size.
+ long n_w = screen_w - (r.right - cr.right) - (cr.left - r.left) - 1;
+ long n_h = screen_h - (r.bottom - cr.bottom) - (cr.top - r.top) - 1;
+ // Letterbox
+ double asp = (cr.right - cr.left) / (double)(cr.bottom - cr.top);
+ double s_asp = n_w / (double)n_h;
+ if (asp > s_asp) {
+ n_h = n_w / asp;
+ } else {
+ n_w = n_h * asp;
+ }
+ r = (RECT){.right = n_w, .bottom = n_h};
+ add_window_borders(w32->window, &r);
+ // Center the final window
+ n_w = r.right - r.left;
+ n_h = r.bottom - r.top;
+ r.left = screen_w / 2 - n_w / 2;
+ r.top = screen_h / 2 - n_h / 2;
+ r.right = r.left + n_w;
+ r.bottom = r.top + n_h;
+ }
+
MP_VERBOSE(w32, "reset window bounds: %d:%d:%d:%d\n",
(int) r.left, (int) r.top, (int)(r.right - r.left),
(int)(r.bottom - r.top));