src/video/wayland/SDL_waylandvideo.c
changeset 8104 2e4f1bd21196
parent 8082 5b83ad3f01ac
child 8116 f7c2f71251e5
     1.1 --- a/src/video/wayland/SDL_waylandvideo.c	Wed Jan 08 14:53:08 2014 -0500
     1.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Thu Jan 09 13:56:21 2014 -0300
     1.3 @@ -19,10 +19,11 @@
     1.4    3. This notice may not be removed or altered from any source distribution.
     1.5  */
     1.6  
     1.7 -#include "SDL_config.h"
     1.8 +#include "../../SDL_internal.h"
     1.9  
    1.10  #include "SDL_video.h"
    1.11  #include "SDL_mouse.h"
    1.12 +#include "SDL_stdinc.h"
    1.13  #include "../../events/SDL_events_c.h"
    1.14  
    1.15  #include "SDL_waylandvideo.h"
    1.16 @@ -35,6 +36,9 @@
    1.17  #include <fcntl.h>
    1.18  #include <xkbcommon/xkbcommon.h>
    1.19  
    1.20 +#include "SDL_waylanddyn.h"
    1.21 +#include <wayland-util.h>
    1.22 +
    1.23  #define WAYLANDVID_DRIVER_NAME "wayland"
    1.24  
    1.25  struct wayland_mode {
    1.26 @@ -59,10 +63,12 @@
    1.27  Wayland_Available(void)
    1.28  {
    1.29      struct wl_display *display = NULL;
    1.30 -
    1.31 -    display = wl_display_connect(NULL);
    1.32 -    if (display != NULL) {
    1.33 -        wl_display_disconnect(display);
    1.34 +    if (SDL_WAYLAND_LoadSymbols()) {
    1.35 +        display = WAYLAND_wl_display_connect(NULL);
    1.36 +        if (display != NULL) {
    1.37 +            WAYLAND_wl_display_disconnect(display);
    1.38 +        }
    1.39 +        SDL_WAYLAND_UnloadSymbols();
    1.40      }
    1.41  
    1.42      return (display != NULL);
    1.43 @@ -72,12 +78,17 @@
    1.44  Wayland_DeleteDevice(SDL_VideoDevice *device)
    1.45  {
    1.46      SDL_free(device);
    1.47 +    SDL_WAYLAND_UnloadSymbols();
    1.48  }
    1.49  
    1.50  static SDL_VideoDevice *
    1.51  Wayland_CreateDevice(int devindex)
    1.52  {
    1.53      SDL_VideoDevice *device;
    1.54 +    
    1.55 +    if (!SDL_WAYLAND_LoadSymbols()) {
    1.56 +        return NULL;
    1.57 +    }
    1.58  
    1.59      /* Initialize all variables that we clean on shutdown */
    1.60      device = SDL_calloc(1, sizeof(SDL_VideoDevice));
    1.61 @@ -133,13 +144,13 @@
    1.62  	    return;
    1.63  
    1.64      /* Add new mode to the list */
    1.65 -    mode = SDL_calloc(1, sizeof *mode);
    1.66 +    mode = (struct wayland_mode *) SDL_calloc(1, sizeof *mode);
    1.67  
    1.68      if (!mode)
    1.69  	return;
    1.70  
    1.71      mode->mode = m;
    1.72 -    wl_list_insert(&d->modes_list, &mode->link);
    1.73 +    WAYLAND_wl_list_insert(&d->modes_list, &mode->link);
    1.74  }
    1.75  
    1.76  static void
    1.77 @@ -227,7 +238,7 @@
    1.78  					const char *interface, uint32_t version)
    1.79  {
    1.80      SDL_VideoData *d = data;
    1.81 -
    1.82 +    
    1.83      if (strcmp(interface, "wl_compositor") == 0) {
    1.84          d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
    1.85      } else if (strcmp(interface, "wl_output") == 0) {
    1.86 @@ -239,8 +250,8 @@
    1.87          d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
    1.88      } else if (strcmp(interface, "wl_shm") == 0) {
    1.89          d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
    1.90 -        d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm);
    1.91 -        d->default_cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
    1.92 +        d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm);
    1.93 +        d->default_cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
    1.94          wl_shm_add_listener(d->shm, &shm_listener, d);
    1.95      
    1.96  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    1.97 @@ -265,7 +276,10 @@
    1.98  Wayland_VideoInit(_THIS)
    1.99  {
   1.100      SDL_VideoData *data;
   1.101 -
   1.102 +    SDL_VideoDisplay display;
   1.103 +    SDL_DisplayMode mode;
   1.104 +    int i;
   1.105 +    
   1.106      data = malloc(sizeof *data);
   1.107      if (data == NULL)
   1.108          return 0;
   1.109 @@ -273,29 +287,41 @@
   1.110  
   1.111      _this->driverdata = data;
   1.112  
   1.113 -    wl_list_init(&data->modes_list);
   1.114 +    WAYLAND_wl_list_init(&data->modes_list);
   1.115      
   1.116 -    data->display = wl_display_connect(NULL);
   1.117 +    data->display = WAYLAND_wl_display_connect(NULL);
   1.118      if (data->display == NULL) {
   1.119          SDL_SetError("Failed to connect to a Wayland display");
   1.120          return 0;
   1.121      }
   1.122  
   1.123      data->registry = wl_display_get_registry(data->display);
   1.124 +   
   1.125 +    if ( data->registry == NULL) {
   1.126 +        SDL_SetError("Failed to get the Wayland registry");
   1.127 +        return 0;
   1.128 +    }
   1.129 +    
   1.130      wl_registry_add_listener(data->registry, &registry_listener, data);
   1.131  
   1.132 -    while (data->screen_allocation.width == 0)
   1.133 -        wl_display_dispatch(data->display);
   1.134 +    for (i=0; i < 100; i++) {
   1.135 +        if (data->screen_allocation.width != 0 || WAYLAND_wl_display_get_error(data->display) != 0) {
   1.136 +            break;
   1.137 +        }
   1.138 +        WAYLAND_wl_display_dispatch(data->display);
   1.139 +    }
   1.140 +    
   1.141 +    if (data->screen_allocation.width == 0) {
   1.142 +        SDL_SetError("Failed while waiting for screen allocation: %d ", WAYLAND_wl_display_get_error(data->display));
   1.143 +        return 0;
   1.144 +    }
   1.145  
   1.146 -    data->xkb_context = xkb_context_new(0);
   1.147 +    data->xkb_context = WAYLAND_xkb_context_new(0);
   1.148      if (!data->xkb_context) {
   1.149          SDL_SetError("Failed to create XKB context");
   1.150          return 0;
   1.151      }
   1.152  
   1.153 -    SDL_VideoDisplay display;
   1.154 -    SDL_DisplayMode mode;
   1.155 -
   1.156      /* Use a fake 32-bpp desktop mode */
   1.157      mode.format = SDL_PIXELFORMAT_RGB888;
   1.158      mode.w = data->screen_allocation.width;
   1.159 @@ -311,7 +337,7 @@
   1.160  
   1.161      Wayland_InitMouse ();
   1.162  
   1.163 -    wayland_schedule_write(data);
   1.164 +    WAYLAND_wl_display_flush(data->display);
   1.165  
   1.166      return 0;
   1.167  }
   1.168 @@ -363,7 +389,7 @@
   1.169      Wayland_display_destroy_input(data);
   1.170  
   1.171      if (data->xkb_context) {
   1.172 -        xkb_context_unref(data->xkb_context);
   1.173 +        WAYLAND_xkb_context_unref(data->xkb_context);
   1.174          data->xkb_context = NULL;
   1.175      }
   1.176  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   1.177 @@ -380,7 +406,7 @@
   1.178          wl_shm_destroy(data->shm);
   1.179  
   1.180      if (data->cursor_theme)
   1.181 -        wl_cursor_theme_destroy(data->cursor_theme);
   1.182 +        WAYLAND_wl_cursor_theme_destroy(data->cursor_theme);
   1.183  
   1.184      if (data->shell)
   1.185          wl_shell_destroy(data->shell);
   1.186 @@ -389,12 +415,12 @@
   1.187          wl_compositor_destroy(data->compositor);
   1.188  
   1.189      if (data->display) {
   1.190 -        wl_display_flush(data->display);
   1.191 -        wl_display_disconnect(data->display);
   1.192 +        WAYLAND_wl_display_flush(data->display);
   1.193 +        WAYLAND_wl_display_disconnect(data->display);
   1.194      }
   1.195      
   1.196      wl_list_for_each_safe(m, t, &data->modes_list, link) {
   1.197 -        wl_list_remove(&m->link);
   1.198 +        WAYLAND_wl_list_remove(&m->link);
   1.199          free(m);
   1.200      }
   1.201