Commit c7c00fa3 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

XCB/GLX: reuse windowing code from other XCB plugins

parent be23a60d
...@@ -85,8 +85,8 @@ static xcb_connection_t *Connect (vlc_object_t *obj, const char *display) ...@@ -85,8 +85,8 @@ static xcb_connection_t *Connect (vlc_object_t *obj, const char *display)
/** /**
* (Try to) register to mouse events on a window if needed. * (Try to) register to mouse events on a window if needed.
*/ */
void RegisterMouseEvents (vlc_object_t *obj, xcb_connection_t *conn, static void RegisterEvents (vlc_object_t *obj, xcb_connection_t *conn,
xcb_window_t wnd) xcb_window_t wnd)
{ {
/* Subscribe to parent window resize events */ /* Subscribe to parent window resize events */
uint32_t value = XCB_EVENT_MASK_POINTER_MOTION uint32_t value = XCB_EVENT_MASK_POINTER_MOTION
...@@ -158,7 +158,7 @@ vout_window_t *GetWindow (vout_display_t *vd, ...@@ -158,7 +158,7 @@ vout_window_t *GetWindow (vout_display_t *vd,
/* Events must be registered before the window geometry is queried, so as /* Events must be registered before the window geometry is queried, so as
* to avoid missing impeding resize events. */ * to avoid missing impeding resize events. */
RegisterMouseEvents (VLC_OBJECT(vd), conn, wnd->handle.xid); RegisterEvents (VLC_OBJECT(vd), conn, wnd->handle.xid);
xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply_t *geo =
xcb_get_geometry_reply (conn, xcb_get_geometry (conn, wnd->handle.xid), xcb_get_geometry_reply (conn, xcb_get_geometry (conn, wnd->handle.xid),
......
...@@ -84,70 +84,19 @@ static void Manage (vout_display_t *); ...@@ -84,70 +84,19 @@ static void Manage (vout_display_t *);
static void SwapBuffers (vlc_gl_t *gl); static void SwapBuffers (vlc_gl_t *gl);
static void *GetProcAddress (vlc_gl_t *gl, const char *); static void *GetProcAddress (vlc_gl_t *gl, const char *);
static vout_window_t *MakeWindow (vout_display_t *vd) static unsigned GetScreenNumber (xcb_connection_t *conn,
const xcb_screen_t *screen)
{ {
vout_window_cfg_t wnd_cfg;
memset (&wnd_cfg, 0, sizeof (wnd_cfg));
wnd_cfg.type = VOUT_WINDOW_TYPE_XID;
wnd_cfg.x = var_InheritInteger (vd, "video-x");
wnd_cfg.y = var_InheritInteger (vd, "video-y");
wnd_cfg.width = vd->cfg->display.width;
wnd_cfg.height = vd->cfg->display.height;
vout_window_t *wnd = vout_display_NewWindow (vd, &wnd_cfg);
if (wnd == NULL)
msg_Err (vd, "parent window not available");
return wnd;
}
static const xcb_screen_t *
FindWindow (vout_display_t *vd, xcb_connection_t *conn,
unsigned *restrict pnum, uint8_t *restrict pdepth,
uint16_t *restrict pwidth, uint16_t *restrict pheight)
{
vout_display_sys_t *sys = vd->sys;
xcb_get_geometry_reply_t *geo =
xcb_get_geometry_reply (conn,
xcb_get_geometry (conn, sys->embed->handle.xid), NULL);
if (geo == NULL)
{
msg_Err (vd, "parent window not valid");
return NULL;
}
xcb_window_t root = geo->root;
*pdepth = geo->depth;
*pwidth = geo->width;
*pheight = geo->height;
free (geo);
/* Find the selected screen */
const xcb_setup_t *setup = xcb_get_setup (conn); const xcb_setup_t *setup = xcb_get_setup (conn);
const xcb_screen_t *screen = NULL;
unsigned num = 0; unsigned num = 0;
for (xcb_screen_iterator_t i = xcb_setup_roots_iterator (setup); for (xcb_screen_iterator_t i = xcb_setup_roots_iterator (setup);;
i.rem > 0;
xcb_screen_next (&i)) xcb_screen_next (&i))
{ {
if (i.data->root == root) if (i.data->root == screen->root)
{ return num;
screen = i.data;
break;
}
num++; num++;
} }
if (screen == NULL)
{
msg_Err (vd, "parent window screen not found");
return NULL;
}
msg_Dbg (vd, "using screen 0x%"PRIx32 " (number: %u)", root, num);
*pnum = num;
return screen;
} }
static bool CheckGLX (vout_display_t *vd, Display *dpy) static bool CheckGLX (vout_display_t *vd, Display *dpy)
...@@ -215,22 +164,20 @@ static int Open (vlc_object_t *obj) ...@@ -215,22 +164,20 @@ static int Open (vlc_object_t *obj)
sys->pool = NULL; sys->pool = NULL;
sys->gl.sys = NULL; sys->gl.sys = NULL;
/* Get window */ /* Get window, connect to X server (via XCB) */
sys->embed = MakeWindow (vd); xcb_connection_t *conn;
const xcb_screen_t *scr;
uint16_t width, height;
uint8_t depth;
sys->embed = GetWindow (vd, &conn, &scr, &depth, &width, &height);
if (sys->embed == NULL) if (sys->embed == NULL)
{ {
free (sys); free (sys);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
const unsigned snum = GetScreenNumber (conn, scr);
/* Connect to X server */ sys->conn = conn;
xcb_connection_t *conn = xcb_connect (sys->embed->display.x11, NULL);
if (unlikely(xcb_connection_has_error (conn)))
{
vout_display_DeleteWindow (vd, sys->embed);
free (sys);
return VLC_EGENERIC;
}
Display *dpy = XOpenDisplay (sys->embed->display.x11); Display *dpy = XOpenDisplay (sys->embed->display.x11);
if (dpy == NULL) if (dpy == NULL)
...@@ -241,23 +188,11 @@ static int Open (vlc_object_t *obj) ...@@ -241,23 +188,11 @@ static int Open (vlc_object_t *obj)
return VLC_EGENERIC; return VLC_EGENERIC;
} }
sys->display = dpy; sys->display = dpy;
sys->conn = conn;
sys->ctx = NULL; sys->ctx = NULL;
if (!CheckGLX (vd, dpy)) if (!CheckGLX (vd, dpy))
goto error; goto error;
RegisterMouseEvents (obj, conn, sys->embed->handle.xid);
/* Find window parameters */
unsigned snum;
uint8_t depth;
uint16_t width, height;
const xcb_screen_t *scr = FindWindow (vd, conn, &snum, &depth,
&width, &height);
if (scr == NULL)
goto error;
sys->window = xcb_generate_id (conn); sys->window = xcb_generate_id (conn);
/* Determine our pixel format */ /* Determine our pixel format */
......
...@@ -47,7 +47,6 @@ struct vout_window_t *GetWindow (vout_display_t *obj, xcb_connection_t **, ...@@ -47,7 +47,6 @@ struct vout_window_t *GetWindow (vout_display_t *obj, xcb_connection_t **,
uint16_t *width, uint16_t *height); uint16_t *width, uint16_t *height);
bool CheckSHM (vlc_object_t *obj, xcb_connection_t *conn); bool CheckSHM (vlc_object_t *obj, xcb_connection_t *conn);
xcb_cursor_t CreateBlankCursor (xcb_connection_t *, const xcb_screen_t *); xcb_cursor_t CreateBlankCursor (xcb_connection_t *, const xcb_screen_t *);
void RegisterMouseEvents (vlc_object_t *, xcb_connection_t *, xcb_window_t);
int CheckError (vout_display_t *, xcb_connection_t *conn, int CheckError (vout_display_t *, xcb_connection_t *conn,
const char *str, xcb_void_cookie_t); const char *str, xcb_void_cookie_t);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment