[PATCH SDL] wayland: Track core protocol changes.

Scott Moreau oreaus at gmail.com
Sat Nov 3 15:13:19 PDT 2012


---

This update allows SDL to work with wayland 1.0. It applies on top of
https://github.com/dhewg/libsdl/tree/wl. The github repo is in the wayland
branch here https://github.com/soreau/SDL/tree/wayland

 src/video/wayland/SDL_waylandevents.c | 23 ++---------------------
 src/video/wayland/SDL_waylandvideo.c  | 35 ++++++++++++-----------------------
 src/video/wayland/SDL_waylandvideo.h  |  9 ++-------
 3 files changed, 16 insertions(+), 51 deletions(-)

diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index dec44eb..0efb48d 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -58,27 +58,8 @@ void
 Wayland_PumpEvents(_THIS)
 {
     SDL_WaylandData *d = _this->driverdata;
-    struct timeval tv;
-    fd_set rfds;
-    int retval;
 
-    if (!(d->event_mask & WL_DISPLAY_READABLE))
-        return;
-
-    tv.tv_sec  = 0;
-    tv.tv_usec = 0;
-    do {
-        FD_ZERO(&rfds);
-        FD_SET(d->event_fd, &rfds);
-
-        retval = select(d->event_fd + 1, &rfds, NULL, NULL, &tv);
-        if (retval < 0) {
-            SDL_SetError("select failed: %m");
-            break;
-        }
-        if (retval == 1)
-            wl_display_iterate(d->display, WL_DISPLAY_READABLE);
-    } while (retval > 0);
+    wl_display_dispatch_pending(d->display);
 }
 
 static void
@@ -352,7 +333,7 @@ Wayland_display_add_input(SDL_WaylandData *d, uint32_t id)
 
     memset(input, 0, sizeof *input);
     input->display = d;
-    input->seat = wl_display_bind(d->display, id, &wl_seat_interface);
+    input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
 
     d->input = input;
 
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index adc3e52..11c2457 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -145,37 +145,26 @@ static const struct wl_output_listener output_listener = {
 };
 
 static void
-display_handle_global(struct wl_display *display, uint32_t id,
-                      const char *interface, uint32_t version, void *data)
+display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
+					const char *interface, uint32_t version)
 {
     SDL_WaylandData *d = data;
 
     if (strcmp(interface, "wl_compositor") == 0) {
-        d->compositor = wl_display_bind(display, id, &wl_compositor_interface);
+        d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
     } else if (strcmp(interface, "wl_output") == 0) {
-        d->output = wl_display_bind(display, id, &wl_output_interface);
+        d->output = wl_registry_bind(d->registry, id, &wl_output_interface, 1);
         wl_output_add_listener(d->output, &output_listener, d);
     } else if (strcmp(interface, "wl_seat") == 0) {
         Wayland_display_add_input(d, id);
     } else if (strcmp(interface, "wl_shell") == 0) {
-        d->shell = wl_display_bind(display, id, &wl_shell_interface);
+        d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
     }
 }
 
-static int
-update_event_mask(uint32_t mask, void *data)
-{
-    SDL_WaylandData *d = data;
-
-    d->event_mask = mask;
-
-    if (mask & WL_DISPLAY_WRITABLE)
-        d->schedule_write = 1;
-    else
-        d->schedule_write = 0;
-
-    return 0;
-}
+static const struct wl_registry_listener registry_listener = {
+	display_handle_global
+};
 
 int
 Wayland_VideoInit(_THIS)
@@ -195,12 +184,12 @@ Wayland_VideoInit(_THIS)
         return 0;
     }
 
-    wl_display_add_global_listener(data->display,
-                                   display_handle_global, data);
+    data->registry = wl_display_get_registry(data->display);
+    wl_registry_add_listener(data->registry, &registry_listener, data);
 
-    wl_display_iterate(data->display, WL_DISPLAY_READABLE);
+    wl_display_dispatch(data->display);
 
-    data->event_fd = wl_display_get_fd(data->display, update_event_mask, data);
+    wl_display_get_fd(data->display);
 
     data->xkb_context = xkb_context_new(0);
     if (!data->xkb_context) {
diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h
index 8b8034c..a62072b 100644
--- a/src/video/wayland/SDL_waylandvideo.h
+++ b/src/video/wayland/SDL_waylandvideo.h
@@ -35,6 +35,7 @@ struct SDL_WaylandInput;
 
 typedef struct {
     struct wl_display *display;
+    struct wl_registry *registry;
     struct wl_compositor *compositor;
     struct wl_output *output;
     struct wl_shell *shell;
@@ -49,18 +50,12 @@ typedef struct {
 
     struct xkb_context *xkb_context;
     struct SDL_WaylandInput *input;
-
-    int event_fd;
-    int event_mask;
-
-    int schedule_write;
 } SDL_WaylandData;
 
 static inline void
 wayland_schedule_write(SDL_WaylandData *data)
 {
-    if (data->schedule_write)
-        wl_display_iterate(data->display, WL_DISPLAY_WRITABLE);
+    wl_display_flush(data->display);
 }
 
 #endif /* _SDL_nullvideo_h */
-- 
1.7.11.7



More information about the wayland-devel mailing list