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

XCB/window: catch resize events

parent 787a60ad
......@@ -247,7 +247,7 @@ static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
/* XCB_CW_BACK_PIXEL */
scr->black_pixel,
/* XCB_CW_EVENT_MASK */
XCB_EVENT_MASK_KEY_PRESS,
XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY,
};
xcb_window_t window = xcb_generate_id (conn);
......@@ -329,6 +329,15 @@ static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
/* Make the window visible */
xcb_map_window (conn, window);
/* Get the initial mapped size (may differ from requested size) */
xcb_get_geometry_reply_t *geo =
xcb_get_geometry_reply (conn, xcb_get_geometry (conn, window), NULL);
if (geo != NULL)
{
vout_window_ReportSize(wnd, geo->width, geo->height);
free (geo);
}
/* Create the event thread. It will dequeue all events, so any checked
* request from this thread must be completed at this point. */
if ((p_sys->keys != NULL)
......@@ -368,6 +377,30 @@ static void Close (vout_window_t *wnd)
free (p_sys);
}
static void ProcessEvent (vout_window_t *wnd, xcb_generic_event_t *ev)
{
vout_window_sys_t *sys = wnd->sys;
if (sys->keys != NULL && XCB_keyHandler_Process (sys->keys, ev) == 0)
return;
switch (ev->response_type & 0x7f)
{
case XCB_CONFIGURE_NOTIFY:
{
xcb_configure_notify_event_t *cne = (void *)ev;
vout_window_ReportSize (wnd, cne->width, cne->height);
break;
}
case XCB_MAPPING_NOTIFY:
break;
default:
msg_Dbg (wnd, "unhandled event %"PRIu8, ev->response_type);
}
free (ev);
}
/** Background thread for X11 events handling */
static void *Thread (void *data)
......@@ -389,12 +422,7 @@ static void *Thread (void *data)
int canc = vlc_savecancel ();
while ((ev = xcb_poll_for_event (conn)) != NULL)
{
if (XCB_keyHandler_Process (p_sys->keys, ev) == 0)
continue;
msg_Dbg (wnd, "unhandled event: %"PRIu8, ev->response_type);
free (ev);
}
ProcessEvent(wnd, ev);
vlc_restorecancel (canc);
if (xcb_connection_has_error (conn))
......@@ -583,6 +611,12 @@ static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg)
p_sys->conn = conn;
/* Subscribe to window events (_before_ the geometry is queried) */
uint32_t mask = XCB_CW_EVENT_MASK;
uint32_t value = XCB_EVENT_MASK_STRUCTURE_NOTIFY;
xcb_change_window_attributes (conn, window, mask, &value);
xcb_get_geometry_reply_t *geo =
xcb_get_geometry_reply (conn, xcb_get_geometry (conn, window), NULL);
if (geo == NULL)
......@@ -591,21 +625,21 @@ static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg)
goto error;
}
p_sys->root = geo->root;
vout_window_ReportSize(wnd, geo->width, geo->height);
free (geo);
/* Try to subscribe to keyboard events (only one X11 client can
* subscribe to input events, so this can fail). */
if (var_InheritBool (wnd, "keyboard-events"))
{
p_sys->keys = XCB_keyHandler_Create (VLC_OBJECT(wnd), conn);
if (p_sys->keys != NULL)
{
const uint32_t mask = XCB_CW_EVENT_MASK;
const uint32_t values[1] = {
XCB_EVENT_MASK_KEY_PRESS,
};
xcb_change_window_attributes (conn, window, mask, values);
}
value |= XCB_EVENT_MASK_KEY_PRESS;
}
if (value & ~XCB_EVENT_MASK_STRUCTURE_NOTIFY)
xcb_change_window_attributes (conn, window, mask, &value);
CacheAtoms (p_sys);
if ((p_sys->keys != NULL)
&& vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
......
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