summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--old-makefile1
-rw-r--r--video/out/vo.c103
-rw-r--r--video/out/win_state.c123
-rw-r--r--video/out/win_state.h30
-rw-r--r--wscript_build.py1
5 files changed, 173 insertions, 85 deletions
diff --git a/old-makefile b/old-makefile
index 1cc0d20a15..9e8321a073 100644
--- a/old-makefile
+++ b/old-makefile
@@ -299,6 +299,7 @@ SOURCES = audio/audio.c \
video/out/vo.c \
video/out/vo_null.c \
video/out/vo_image.c \
+ video/out/win_state.c \
osdep/$(GETCH) \
osdep/$(TIMER) \
$(SOURCES-yes)
diff --git a/video/out/vo.c b/video/out/vo.c
index 43e5d08fa2..dd65552ec0 100644
--- a/video/out/vo.c
+++ b/video/out/vo.c
@@ -36,6 +36,7 @@
#include "bstr/bstr.h"
#include "vo.h"
#include "aspect.h"
+#include "win_state.h"
#include "input/input.h"
#include "options/m_config.h"
#include "common/msg.h"
@@ -234,78 +235,6 @@ void vo_destroy(struct vo *vo)
talloc_free(vo);
}
-static void calc_monitor_aspect(struct mp_vo_opts *opts, int scr_w, int scr_h,
- float *pixelaspect, int *w, int *h)
-{
- *pixelaspect = 1.0 / opts->monitor_pixel_aspect;
-
- if (scr_w > 0 && scr_h > 0 && opts->force_monitor_aspect)
- *pixelaspect = opts->force_monitor_aspect * scr_h / scr_w;
-
- if (*pixelaspect < 1) {
- *h /= *pixelaspect;
- } else {
- *w *= *pixelaspect;
- }
-}
-
-// Fit *w/*h into the size specified by geo.
-static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
- struct m_geometry *geo, bool allow_upscale)
-{
- if (!geo->wh_valid)
- return;
-
- int dummy;
- int n_w = *w, n_h = *h;
- m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
-
- if (!allow_upscale && *w <= n_w && *h <= n_h)
- return;
-
- // If aspect mismatches, always make the window smaller than the fit box
- double asp = (double)*w / *h;
- double n_asp = (double)n_w / n_h;
- if (n_asp <= asp) {
- *w = n_w;
- *h = n_w / asp;
- } else {
- *w = n_h * asp;
- *h = n_h;
- }
-}
-
-// Set window size (vo->dwidth/dheight) and position (vo->dx/dy) according to
-// the video display size d_w/d_h.
-// NOTE: currently, all GUI backends do their own handling of window geometry
-// additional to this code. This is to deal with initial window placement,
-// fullscreen handling, avoiding resize on config() with no size change,
-// multi-monitor stuff, and possibly more.
-static void determine_window_geometry(struct vo *vo, int d_w, int d_h)
-{
- struct mp_vo_opts *opts = vo->opts;
-
- int scr_w = opts->screenwidth;
- int scr_h = opts->screenheight;
-
- MP_DBG(vo, "screen size: %dx%d\n", scr_w, scr_h);
-
- calc_monitor_aspect(opts, scr_w, scr_h, &vo->monitor_par, &d_w, &d_h);
-
- apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true);
- apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false);
-
- vo->dx = (int)(opts->screenwidth - d_w) / 2;
- vo->dy = (int)(opts->screenheight - d_h) / 2;
- m_geometry_apply(&vo->dx, &vo->dy, &d_w, &d_h, scr_w, scr_h,
- &opts->geometry);
-
- vo->dx += vo->xinerama_x;
- vo->dy += vo->xinerama_y;
- vo->dwidth = d_w;
- vo->dheight = d_h;
-}
-
static void check_vo_caps(struct vo *vo)
{
int rot = vo->params->rotate;
@@ -320,23 +249,27 @@ static void check_vo_caps(struct vo *vo)
int vo_reconfig(struct vo *vo, struct mp_image_params *params, int flags)
{
- int d_width = params->d_w;
- int d_height = params->d_h;
-
- if (vo_control(vo, VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
- int w = params->d_w, h = params->d_h;
- if ((vo->driver->caps & VO_CAP_ROTATE90) && params->rotate % 180 == 90)
- MPSWAP(int, w, h);
- determine_window_geometry(vo, w, h);
- d_width = vo->dwidth;
- d_height = vo->dheight;
- }
- vo->dwidth = d_width;
- vo->dheight = d_height;
+ vo->dwidth = params->d_w;
+ vo->dheight = params->d_h;
talloc_free(vo->params);
vo->params = talloc_memdup(vo, params, sizeof(*params));
+ // Emulate the old way of calculating the window geometry settings.
+ if (vo_control(vo, VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
+ struct mp_rect rc = {
+ vo->xinerama_x,
+ vo->xinerama_y,
+ vo->xinerama_x + vo->opts->screenwidth,
+ vo->xinerama_y + vo->opts->screenheight,
+ };
+ struct vo_win_geometry geo;
+ vo_calc_window_geometry(vo, &rc, &geo);
+ vo_apply_window_geometry(vo, &geo);
+ vo->dx = geo.win.x0;
+ vo->dy = geo.win.y0;
+ }
+
int ret = vo->driver->reconfig(vo, vo->params, flags);
vo->config_ok = ret >= 0;
if (vo->config_ok) {
diff --git a/video/out/win_state.c b/video/out/win_state.c
new file mode 100644
index 0000000000..7b9f0c7bcd
--- /dev/null
+++ b/video/out/win_state.c
@@ -0,0 +1,123 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "win_state.h"
+#include "vo.h"
+
+#include "video/mp_image.h"
+
+static void calc_monitor_aspect(struct mp_vo_opts *opts, int scr_w, int scr_h,
+ double *pixelaspect, int *w, int *h)
+{
+ *pixelaspect = 1.0 / opts->monitor_pixel_aspect;
+
+ if (scr_w > 0 && scr_h > 0 && opts->force_monitor_aspect)
+ *pixelaspect = opts->force_monitor_aspect * scr_h / scr_w;
+
+ if (*pixelaspect < 1) {
+ *h /= *pixelaspect;
+ } else {
+ *w *= *pixelaspect;
+ }
+}
+
+// Fit *w/*h into the size specified by geo.
+static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
+ struct m_geometry *geo, bool allow_upscale)
+{
+ if (!geo->wh_valid)
+ return;
+
+ int dummy;
+ int n_w = *w, n_h = *h;
+ m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
+
+ if (!allow_upscale && *w <= n_w && *h <= n_h)
+ return;
+
+ // If aspect mismatches, always make the window smaller than the fit box
+ double asp = (double)*w / *h;
+ double n_asp = (double)n_w / n_h;
+ if (n_asp <= asp) {
+ *w = n_w;
+ *h = n_w / asp;
+ } else {
+ *w = n_h * asp;
+ *h = n_h;
+ }
+}
+
+// Compute the "suggested" window size and position and return it in *out_geo.
+// screen is the bounding box of the current screen within the virtual desktop.
+// Does not change *vo.
+// Use vo_apply_window_geometry() to copy the result into the vo.
+// NOTE: currently, all windowing backends do their own handling of window
+// geometry additional to this code. This is to deal with initial window
+// placement, fullscreen handling, avoiding resize on reconfig() with no
+// size change, multi-monitor stuff, and possibly more.
+void vo_calc_window_geometry(struct vo *vo, const struct mp_rect *screen,
+ struct vo_win_geometry *out_geo)
+{
+ struct mp_vo_opts *opts = vo->opts;
+
+ *out_geo = (struct vo_win_geometry){0};
+
+ // The case of calling this function even though no video was configured
+ // yet (i.e. vo->params==NULL) happens when vo_opengl creates a hidden
+ // window in order to create an OpenGL context.
+ struct mp_image_params params = { .d_w = 320, .d_h = 200 };
+ if (vo->params)
+ params = *vo->params;
+
+ int d_w = params.d_w;
+ int d_h = params.d_h;
+ if ((vo->driver->caps & VO_CAP_ROTATE90) && params.rotate % 180 == 90)
+ MPSWAP(int, d_w, d_h);
+
+ int scr_w = screen->x1 - screen->x0;
+ int scr_h = screen->y1 - screen->y0;
+
+ MP_DBG(vo, "screen size: %dx%d\n", scr_w, scr_h);
+
+ calc_monitor_aspect(opts, scr_w, scr_h, &out_geo->monitor_par, &d_w, &d_h);
+
+ apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true);
+ apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false);
+
+ out_geo->win.x0 = (int)(scr_w - d_w) / 2;
+ out_geo->win.y0 = (int)(scr_h - d_h) / 2;
+ m_geometry_apply(&out_geo->win.x0, &out_geo->win.y0, &d_w, &d_h,
+ scr_w, scr_h, &opts->geometry);
+
+ out_geo->win.x0 += screen->x0;
+ out_geo->win.y0 += screen->y0;
+ out_geo->win.x1 = out_geo->win.x0 + d_w;
+ out_geo->win.y1 = out_geo->win.y0 + d_h;
+
+ if (opts->geometry.xy_valid || opts->force_window_position)
+ out_geo->flags |= VO_WIN_FORCE_POS;
+}
+
+// Copy the parameters in *geo to the vo fields.
+// (Doesn't do anything else - windowing backends should trigger VO_EVENT_RESIZE
+// to ensure that the VO reinitializes rendering properly.)
+void vo_apply_window_geometry(struct vo *vo, const struct vo_win_geometry *geo)
+{
+ vo->dwidth = geo->win.x1 - geo->win.x0;
+ vo->dheight = geo->win.y1 - geo->win.y0;
+ vo->monitor_par = geo->monitor_par;
+}
diff --git a/video/out/win_state.h b/video/out/win_state.h
new file mode 100644
index 0000000000..6c3988b42b
--- /dev/null
+++ b/video/out/win_state.h
@@ -0,0 +1,30 @@
+#ifndef MP_WIN_STATE_H_
+#define MP_WIN_STATE_H_
+
+#include "common/common.h"
+
+struct vo;
+
+enum {
+ // By user settings, the window manager's chosen window position should
+ // be overridden.
+ VO_WIN_FORCE_POS = (1 << 0),
+};
+
+struct vo_win_geometry {
+ // Bitfield of VO_WIN_* flags
+ int flags;
+ // Position & size of the window. In xinerama coordinates, i.e. they're
+ // relative to the virtual desktop encompassing all screens, not the
+ // current screen.
+ struct mp_rect win;
+ // Aspect ratio of the current monitor.
+ // (calculated from screen size and options.)
+ double monitor_par;
+};
+
+void vo_calc_window_geometry(struct vo *vo, const struct mp_rect *screen,
+ struct vo_win_geometry *out_geo);
+void vo_apply_window_geometry(struct vo *vo, const struct vo_win_geometry *geo);
+
+#endif
diff --git a/wscript_build.py b/wscript_build.py
index 82a0b12344..c8058b6fe6 100644
--- a/wscript_build.py
+++ b/wscript_build.py
@@ -360,6 +360,7 @@ def build(ctx):
( "video/out/vo_xv.c", "xv" ),
( "video/out/w32_common.c", "gdi" ),
( "video/out/wayland_common.c", "wayland" ),
+ ( "video/out/win_state.c"),
( "video/out/x11_common.c", "x11" ),
## osdep