[PATCH xserver 3/4 v3] xwayland: refactor Wayland event handling

Olivier Fourdan ofourdan at redhat.com
Mon May 23 16:11:43 UTC 2016


To be able to reuse some code.

Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---
 v2: call prepre_read() before read() so we don't end up in a deadlock
 v3: no change, just keep the patch series together.

 hw/xwayland/xwayland.c | 44 ++++++++++++++++++++++++++++++++------------
 hw/xwayland/xwayland.h |  2 ++
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index 151e044..748abdf 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -460,14 +460,13 @@ static const struct wl_registry_listener registry_listener = {
 };
 
 static void
-socket_handler(int fd, int ready, void *data)
+xwl_read_events (struct xwl_screen *xwl_screen)
 {
-    struct xwl_screen *xwl_screen = data;
     int ret;
 
     ret = wl_display_read_events(xwl_screen->display);
     if (ret == -1)
-        FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
+        FatalError("failed to read Wayland events: %s\n", strerror(errno));
 
     xwl_screen->prepare_read = 0;
 
@@ -477,18 +476,10 @@ socket_handler(int fd, int ready, void *data)
 }
 
 static void
-wakeup_handler(void *data, int err, void *pRead)
-{
-}
-
-static void
-block_handler(void *data, OSTimePtr pTimeout, void *pRead)
+xwl_dispatch_events (struct xwl_screen *xwl_screen)
 {
-    struct xwl_screen *xwl_screen = data;
     int ret;
 
-    xwl_screen_post_damage(xwl_screen);
-
     while (xwl_screen->prepare_read == 0 &&
            wl_display_prepare_read(xwl_screen->display) == -1) {
         ret = wl_display_dispatch_pending(xwl_screen->display);
@@ -504,6 +495,35 @@ block_handler(void *data, OSTimePtr pTimeout, void *pRead)
         FatalError("failed to write to XWayland fd: %s\n", strerror(errno));
 }
 
+static void
+socket_handler(int fd, int ready, void *data)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    xwl_read_events (xwl_screen);
+}
+
+static void
+wakeup_handler(void *data, int err, void *pRead)
+{
+}
+
+static void
+block_handler(void *data, OSTimePtr pTimeout, void *pRead)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    xwl_screen_post_damage(xwl_screen);
+    xwl_dispatch_events (xwl_screen);
+}
+
+void
+xwl_sync_events (struct xwl_screen *xwl_screen)
+{
+    xwl_dispatch_events (xwl_screen);
+    xwl_read_events (xwl_screen);
+}
+
 static CARD32
 add_client_fd(OsTimerPtr timer, CARD32 time, void *arg)
 {
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 5c053d9..70a0492 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -155,6 +155,8 @@ struct xwl_output {
 
 struct xwl_pixmap;
 
+void xwl_sync_events (struct xwl_screen *xwl_screen);
+
 Bool xwl_screen_init_cursor(struct xwl_screen *xwl_screen);
 
 struct xwl_screen *xwl_screen_get(ScreenPtr screen);
-- 
2.7.4



More information about the xorg-devel mailing list