summaryrefslogtreecommitdiffstats
path: root/video/out/x11_common.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-09-30 23:31:34 +0200
committerwm4 <wm4@nowhere>2015-09-30 23:31:34 +0200
commit7c5f41ff5f00a823f4c75b7d9799729a05f943c9 (patch)
treefddccdae40ceacd75e886d5c665ad1bb34d2d746 /video/out/x11_common.c
parenta2a2cdb5bc7788012d3976a4d2f3650e58f9f466 (diff)
downloadmpv-7c5f41ff5f00a823f4c75b7d9799729a05f943c9.tar.bz2
mpv-7c5f41ff5f00a823f4c75b7d9799729a05f943c9.tar.xz
x11: separate window creation and configuration
This gets rid of an old hack, VOFLAG_HIDDEN. Although handling of it has been sane for a while, it used to cause much pain, and is still unintuitive and weird even today. The main reason for this hack is that OpenGL selects a X11 Visual for you, and you're supposed to use this Visual when creating the X window for the OpenGL context. Which means the X window can't be created early in the common X11 init code, but the OpenGL code needs to do something before that. API-wise you need separate functions for X11 init and X11 window creation. The VOFLAG_HIDDEN hack conflated window creation and the entrypoint for resizing on video resolution change into one function, vo_x11_config_vo_window(). This required all platform backends to handle this flag, even if they didn't need this mechanism. Wayland still uses this for minor reasons (alpha support?), so the wayland backend must be changed before the flag can be entirely removed.
Diffstat (limited to 'video/out/x11_common.c')
-rw-r--r--video/out/x11_common.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index d077957c4e..0aa49a4257 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -1477,28 +1477,13 @@ static void wait_until_mapped(struct vo *vo)
}
}
-/* Create and setup a window suitable for display
- * vis: Visual to use for creating the window (NULL for default)
- * x, y: position of window (might be ignored)
- * width, height: size of window
- * flags: flags for window creation (VOFLAG_*)
- * classname: name to use for the X11 classhint
- *
- * If the window already exists, it just moves and resizes it.
- */
-void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int flags,
+// Create the X11 window. There is only 1, and it must be created before
+// vo_x11_config_vo_window() is called. vis can be NULL for default.
+bool vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis,
const char *classname)
{
- struct mp_vo_opts *opts = vo->opts;
struct vo_x11_state *x11 = vo->x11;
-
- vo_x11_update_screeninfo(vo);
-
- struct vo_win_geometry geo;
- vo_calc_window_geometry(vo, &x11->screenrc, &geo);
- vo_apply_window_geometry(vo, &geo);
-
- struct mp_rect rc = geo.win;
+ assert(!x11->window);
if (x11->parent) {
if (x11->parent == x11->rootwin) {
@@ -1508,18 +1493,36 @@ void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int flags,
} else {
XSelectInput(x11->display, x11->parent, StructureNotifyMask);
}
- vo_x11_update_geometry(vo);
- rc = (struct mp_rect){0, 0, RC_W(x11->winrc), RC_H(x11->winrc)};
}
if (x11->window == None) {
- vo_x11_create_window(vo, vis, rc);
+ vo_x11_create_window(vo, vis, (struct mp_rect){.x1 = 320, .y1 = 200 });
vo_x11_classhint(vo, x11->window, classname);
x11->window_hidden = true;
- x11->winrc = geo.win;
}
- if (flags & VOFLAG_HIDDEN)
- return;
+ return !!x11->window;
+}
+
+// Resize the window (e.g. new file, or video resolution change)
+void vo_x11_config_vo_window(struct vo *vo)
+{
+ struct mp_vo_opts *opts = vo->opts;
+ struct vo_x11_state *x11 = vo->x11;
+
+ assert(x11->window);
+
+ vo_x11_update_screeninfo(vo);
+
+ struct vo_win_geometry geo;
+ vo_calc_window_geometry(vo, &x11->screenrc, &geo);
+ vo_apply_window_geometry(vo, &geo);
+
+ struct mp_rect rc = geo.win;
+
+ if (x11->parent) {
+ vo_x11_update_geometry(vo);
+ rc = (struct mp_rect){0, 0, RC_W(x11->winrc), RC_H(x11->winrc)};
+ }
bool reset_size = x11->old_dw != RC_W(rc) || x11->old_dh != RC_H(rc);
x11->old_dw = RC_W(rc);