[vlc-commits] XCB/window: catch resize events
Rémi Denis-Courmont
git at videolan.org
Thu Oct 16 19:26:02 CEST 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 12 14:17:56 2014 +0300| [908acfe2165b7293a204cbcb638c65cb7c8add48] | committer: Rémi Denis-Courmont
XCB/window: catch resize events
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=908acfe2165b7293a204cbcb638c65cb7c8add48
---
modules/video_output/xcb/window.c | 62 ++++++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 14 deletions(-)
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index 931d49d..94156f7 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -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))
More information about the vlc-commits
mailing list