wayland: Add support for xdg-shell protocol (unstable v6).
authorRyan C. Gordon <icculus@icculus.org>
Wed, 07 Feb 2018 13:13:55 -0500
changeset 118482f157c1ca383
parent 11847 4249379583bc
child 11849 8553b0c52d2b
wayland: Add support for xdg-shell protocol (unstable v6).

This is meant to be the desktop-enhanced version of wl_shell. Right now we
just match what the existing wl_shell code does, but there are other areas of
functionality available to us now, that we can fill in later.

This uses the "unstable" API, since this is what ships in Ubuntu 17.10 (as
part of Wayland 1.10), but Wayland 1.12 promotes this to stable with extremely
minor changes. We will add support for the stable version when it makes sense
to do so.
cmake/sdlchecks.cmake
configure
configure.in
src/video/wayland/SDL_waylandevents.c
src/video/wayland/SDL_waylandvideo.c
src/video/wayland/SDL_waylandvideo.h
src/video/wayland/SDL_waylandwindow.c
src/video/wayland/SDL_waylandwindow.h
     1.1 --- a/cmake/sdlchecks.cmake	Wed Feb 07 13:07:59 2018 -0500
     1.2 +++ b/cmake/sdlchecks.cmake	Wed Feb 07 13:13:55 2018 -0500
     1.3 @@ -685,7 +685,7 @@
     1.4  
     1.5        WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
     1.6  
     1.7 -      foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
     1.8 +      foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1, xdg-shell-unstable-v6)
     1.9          string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
    1.10          WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
    1.11        endforeach()
     2.1 --- a/configure	Wed Feb 07 13:07:59 2018 -0500
     2.2 +++ b/configure	Wed Feb 07 13:13:55 2018 -0500
     2.3 @@ -19220,7 +19220,7 @@
     2.4  
     2.5              fi
     2.6  
     2.7 -            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1"
     2.8 +            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"
     2.9  
    2.10              SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
    2.11              EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
     3.1 --- a/configure.in	Wed Feb 07 13:07:59 2018 -0500
     3.2 +++ b/configure.in	Wed Feb 07 13:13:55 2018 -0500
     3.3 @@ -1409,7 +1409,7 @@
     3.4                  AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH, 1, [ ])
     3.5              fi
     3.6  
     3.7 -            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1"
     3.8 +            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"
     3.9  
    3.10              SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
    3.11              EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
     4.1 --- a/src/video/wayland/SDL_waylandevents.c	Wed Feb 07 13:07:59 2018 -0500
     4.2 +++ b/src/video/wayland/SDL_waylandevents.c	Wed Feb 07 13:13:55 2018 -0500
     4.3 @@ -40,6 +40,7 @@
     4.4  
     4.5  #include "pointer-constraints-unstable-v1-client-protocol.h"
     4.6  #include "relative-pointer-unstable-v1-client-protocol.h"
     4.7 +#include "xdg-shell-unstable-v6-client-protocol.h"
     4.8  
     4.9  #include <linux/input.h>
    4.10  #include <sys/select.h>
    4.11 @@ -248,15 +249,25 @@
    4.12      if (window->hit_test) {
    4.13          const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
    4.14          const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
    4.15 -        static const uint32_t directions[] = {
    4.16 +
    4.17 +        static const uint32_t directions_wl[] = {
    4.18              WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
    4.19              WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
    4.20              WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
    4.21              WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
    4.22          };
    4.23 +
    4.24 +        /* the names are different (ZXDG_TOPLEVEL_V6_RESIZE_EDGE_* vs
    4.25 +           WL_SHELL_SURFACE_RESIZE_*), but the values are the same. */
    4.26 +        const uint32_t *directions_zxdg = directions_wl;
    4.27 +
    4.28          switch (rc) {
    4.29              case SDL_HITTEST_DRAGGABLE:
    4.30 -                wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
    4.31 +                if (input->display->shell.zxdg) {
    4.32 +                    zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial);
    4.33 +                } else {
    4.34 +                    wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial);
    4.35 +                }
    4.36                  return SDL_TRUE;
    4.37  
    4.38              case SDL_HITTEST_RESIZE_TOPLEFT:
    4.39 @@ -267,7 +278,11 @@
    4.40              case SDL_HITTEST_RESIZE_BOTTOM:
    4.41              case SDL_HITTEST_RESIZE_BOTTOMLEFT:
    4.42              case SDL_HITTEST_RESIZE_LEFT:
    4.43 -                wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    4.44 +                if (input->display->shell.zxdg) {
    4.45 +                    zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    4.46 +                } else {
    4.47 +                    wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    4.48 +                }
    4.49                  return SDL_TRUE;
    4.50  
    4.51              default: return SDL_FALSE;
    4.52 @@ -950,6 +965,7 @@
    4.53      return input->data_device;
    4.54  }
    4.55  
    4.56 +/* !!! FIXME: just merge these into display_handle_global(). */
    4.57  void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id)
    4.58  {
    4.59      d->relative_pointer_manager =
     5.1 --- a/src/video/wayland/SDL_waylandvideo.c	Wed Feb 07 13:07:59 2018 -0500
     5.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Wed Feb 07 13:13:55 2018 -0500
     5.3 @@ -45,6 +45,8 @@
     5.4  #include "SDL_waylanddyn.h"
     5.5  #include <wayland-util.h>
     5.6  
     5.7 +#include "xdg-shell-unstable-v6-client-protocol.h"
     5.8 +
     5.9  #define WAYLANDVID_DRIVER_NAME "wayland"
    5.10  
    5.11  /* Initialization/Query functions */
    5.12 @@ -64,6 +66,12 @@
    5.13  static char *
    5.14  get_classname()
    5.15  {
    5.16 +/* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec:
    5.17 +	"The surface class identifies the general class of applications
    5.18 +	to which the surface belongs. A common convention is to use the
    5.19 +	file name (or the full path if it is a non-standard location) of
    5.20 +	the application's .desktop file as the class." */
    5.21 +
    5.22      char *spot;
    5.23  #if defined(__LINUX__) || defined(__FREEBSD__)
    5.24      char procfile[1024];
    5.25 @@ -307,6 +315,18 @@
    5.26  };
    5.27  #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
    5.28  
    5.29 +
    5.30 +static void
    5.31 +handle_ping_zxdg_shell(void *data, struct zxdg_shell_v6 *zxdg, uint32_t serial)
    5.32 +{
    5.33 +    zxdg_shell_v6_pong(zxdg, serial);
    5.34 +}
    5.35 +
    5.36 +static const struct zxdg_shell_v6_listener shell_listener_zxdg = {
    5.37 +    handle_ping_zxdg_shell
    5.38 +};
    5.39 +
    5.40 +
    5.41  static void
    5.42  display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
    5.43                        const char *interface, uint32_t version)
    5.44 @@ -319,8 +339,11 @@
    5.45          Wayland_add_display(d, id);
    5.46      } else if (strcmp(interface, "wl_seat") == 0) {
    5.47          Wayland_display_add_input(d, id);
    5.48 +    } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
    5.49 +        d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1);
    5.50 +        zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL);
    5.51      } else if (strcmp(interface, "wl_shell") == 0) {
    5.52 -        d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
    5.53 +        d->shell.wl = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
    5.54      } else if (strcmp(interface, "wl_shm") == 0) {
    5.55          d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
    5.56          d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm);
    5.57 @@ -330,6 +353,7 @@
    5.58          Wayland_display_add_pointer_constraints(d, id);
    5.59      } else if (strcmp(interface, "wl_data_device_manager") == 0) {
    5.60          d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
    5.61 +
    5.62  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    5.63      } else if (strcmp(interface, "qt_touch_extension") == 0) {
    5.64          Wayland_touch_create(d, id);
    5.65 @@ -448,8 +472,11 @@
    5.66      if (data->cursor_theme)
    5.67          WAYLAND_wl_cursor_theme_destroy(data->cursor_theme);
    5.68  
    5.69 -    if (data->shell)
    5.70 -        wl_shell_destroy(data->shell);
    5.71 +    if (data->shell.wl)
    5.72 +        wl_shell_destroy(data->shell.wl);
    5.73 +
    5.74 +    if (data->shell.zxdg)
    5.75 +        zxdg_shell_v6_destroy(data->shell.zxdg);
    5.76  
    5.77      if (data->compositor)
    5.78          wl_compositor_destroy(data->compositor);
     6.1 --- a/src/video/wayland/SDL_waylandvideo.h	Wed Feb 07 13:07:59 2018 -0500
     6.2 +++ b/src/video/wayland/SDL_waylandvideo.h	Wed Feb 07 13:13:55 2018 -0500
     6.3 @@ -43,7 +43,11 @@
     6.4      struct wl_shm *shm;
     6.5      struct wl_cursor_theme *cursor_theme;
     6.6      struct wl_pointer *pointer;
     6.7 -    struct wl_shell *shell;
     6.8 +    struct {
     6.9 +        /* !!! FIXME: add stable xdg_shell from 1.12 */
    6.10 +        struct zxdg_shell_v6 *zxdg;
    6.11 +        struct wl_shell *wl;
    6.12 +    } shell;
    6.13      struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
    6.14      struct zwp_pointer_constraints_v1 *pointer_constraints;
    6.15      struct wl_data_device_manager *data_device_manager;
     7.1 --- a/src/video/wayland/SDL_waylandwindow.c	Wed Feb 07 13:07:59 2018 -0500
     7.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Wed Feb 07 13:13:55 2018 -0500
     7.3 @@ -33,15 +33,22 @@
     7.4  #include "SDL_waylanddyn.h"
     7.5  #include "SDL_hints.h"
     7.6  
     7.7 +#include "xdg-shell-unstable-v6-client-protocol.h"
     7.8 +
     7.9 +/* On modern desktops, we probably will use the xdg-shell protocol instead
    7.10 +   of wl_shell, but wl_shell might be useful on older Wayland installs that
    7.11 +   don't have the newer protocol, or embedded things that don't have a full
    7.12 +   window manager. */
    7.13 +
    7.14  static void
    7.15 -handle_ping(void *data, struct wl_shell_surface *shell_surface,
    7.16 +handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
    7.17              uint32_t serial)
    7.18  {
    7.19      wl_shell_surface_pong(shell_surface, serial);
    7.20  }
    7.21  
    7.22  static void
    7.23 -handle_configure(void *data, struct wl_shell_surface *shell_surface,
    7.24 +handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
    7.25                   uint32_t edges, int32_t width, int32_t height)
    7.26  {
    7.27      SDL_WindowData *wind = (SDL_WindowData *)data;
    7.28 @@ -87,16 +94,94 @@
    7.29  }
    7.30  
    7.31  static void
    7.32 -handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
    7.33 +handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
    7.34  {
    7.35  }
    7.36  
    7.37 -static const struct wl_shell_surface_listener shell_surface_listener = {
    7.38 -    handle_ping,
    7.39 -    handle_configure,
    7.40 -    handle_popup_done
    7.41 +static const struct wl_shell_surface_listener shell_surface_listener_wl = {
    7.42 +    handle_ping_wl_shell_surface,
    7.43 +    handle_configure_wl_shell_surface,
    7.44 +    handle_popup_done_wl_shell_surface
    7.45  };
    7.46  
    7.47 +
    7.48 +
    7.49 +
    7.50 +static void
    7.51 +handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, uint32_t serial)
    7.52 +{
    7.53 +    SDL_WindowData *wind = (SDL_WindowData *)data;
    7.54 +    SDL_Window *window = wind->sdlwindow;
    7.55 +    struct wl_region *region;
    7.56 +    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
    7.57 +
    7.58 +    region = wl_compositor_create_region(wind->waylandData->compositor);
    7.59 +    wl_region_add(region, 0, 0, window->w, window->h);
    7.60 +    wl_surface_set_opaque_region(wind->surface, region);
    7.61 +    wl_region_destroy(region);
    7.62 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h);
    7.63 +    zxdg_surface_v6_ack_configure(zxdg, serial);
    7.64 +}
    7.65 +
    7.66 +static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
    7.67 +    handle_configure_zxdg_shell_surface
    7.68 +};
    7.69 +
    7.70 +
    7.71 +static void
    7.72 +handle_configure_zxdg_toplevel(void *data,
    7.73 +			  struct zxdg_toplevel_v6 *zxdg_toplevel_v6,
    7.74 +			  int32_t width,
    7.75 +			  int32_t height,
    7.76 +			  struct wl_array *states)
    7.77 +{
    7.78 +    SDL_WindowData *wind = (SDL_WindowData *)data;
    7.79 +    SDL_Window *window = wind->sdlwindow;
    7.80 +
    7.81 +    /* wl_shell_surface spec states that this is a suggestion.
    7.82 +       Ignore if less than or greater than max/min size. */
    7.83 +
    7.84 +    if (width == 0 || height == 0) {
    7.85 +        return;
    7.86 +    }
    7.87 +
    7.88 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    7.89 +        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
    7.90 +            if (window->max_w > 0) {
    7.91 +                width = SDL_min(width, window->max_w);
    7.92 +            } 
    7.93 +            width = SDL_max(width, window->min_w);
    7.94 +
    7.95 +            if (window->max_h > 0) {
    7.96 +                height = SDL_min(height, window->max_h);
    7.97 +            }
    7.98 +            height = SDL_max(height, window->min_h);
    7.99 +        } else {
   7.100 +            return;
   7.101 +        }
   7.102 +    }
   7.103 +
   7.104 +    if (width == window->w && height == window->h) {
   7.105 +        return;
   7.106 +    }
   7.107 +
   7.108 +    window->w = width;
   7.109 +    window->h = height;
   7.110 +}
   7.111 +
   7.112 +static void
   7.113 +handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
   7.114 +{
   7.115 +    SDL_WindowData *window = (SDL_WindowData *)data;
   7.116 +    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
   7.117 +}
   7.118 +
   7.119 +static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = {
   7.120 +    handle_configure_zxdg_toplevel,
   7.121 +    handle_close_zxdg_toplevel
   7.122 +};
   7.123 +
   7.124 +
   7.125  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   7.126  static void
   7.127  handle_onscreen_visibility(void *data,
   7.128 @@ -151,7 +236,7 @@
   7.129  
   7.130      info->info.wl.display = data->waylandData->display;
   7.131      info->info.wl.surface = data->surface;
   7.132 -    info->info.wl.shell_surface = data->shell_surface;
   7.133 +    info->info.wl.shell_surface = data->shell_surface.wl;
   7.134      info->subsystem = SDL_SYSWM_WAYLAND;
   7.135  
   7.136      return SDL_TRUE;
   7.137 @@ -163,18 +248,35 @@
   7.138      return 0;  /* just succeed, the real work is done elsewhere. */
   7.139  }
   7.140  
   7.141 +static void
   7.142 +SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output)
   7.143 +{
   7.144 +    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
   7.145 +    SDL_WindowData *wind = window->driverdata;
   7.146 +
   7.147 +    if (viddata->shell.zxdg) {
   7.148 +        if (output) {
   7.149 +            zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output);
   7.150 +        } else {
   7.151 +            zxdg_toplevel_v6_unset_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel);
   7.152 +        }
   7.153 +    } else {
   7.154 +        if (output) {
   7.155 +            wl_shell_surface_set_fullscreen(wind->shell_surface.wl,
   7.156 +                                            WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
   7.157 +                                            0, output);
   7.158 +        } else {
   7.159 +            wl_shell_surface_set_toplevel(wind->shell_surface.wl);
   7.160 +        }
   7.161 +    }
   7.162 +
   7.163 +    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
   7.164 +}
   7.165 +
   7.166  void Wayland_ShowWindow(_THIS, SDL_Window *window)
   7.167  {
   7.168 -    SDL_WindowData *wind = window->driverdata;
   7.169 -
   7.170 -    if (window->flags & SDL_WINDOW_FULLSCREEN)
   7.171 -        wl_shell_surface_set_fullscreen(wind->shell_surface,
   7.172 -                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
   7.173 -                                        0, (struct wl_output *)window->fullscreen_mode.driverdata);
   7.174 -    else
   7.175 -        wl_shell_surface_set_toplevel(wind->shell_surface);
   7.176 -
   7.177 -    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
   7.178 +    struct wl_output *output = (struct wl_output *) window->fullscreen_mode.driverdata;
   7.179 +    SetFullscreen(_this, window, (window->flags & SDL_WINDOW_FULLSCREEN) ? output : NULL);
   7.180  }
   7.181  
   7.182  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   7.183 @@ -247,24 +349,20 @@
   7.184  Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
   7.185                              SDL_VideoDisplay * _display, SDL_bool fullscreen)
   7.186  {
   7.187 -    SDL_WindowData *wind = window->driverdata;
   7.188 -
   7.189 -    if (fullscreen)
   7.190 -        wl_shell_surface_set_fullscreen(wind->shell_surface,
   7.191 -                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
   7.192 -                                        0, (struct wl_output *)_display->driverdata);
   7.193 -    else
   7.194 -        wl_shell_surface_set_toplevel(wind->shell_surface);
   7.195 -
   7.196 -    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
   7.197 +    struct wl_output *output = (struct wl_output *) _display->driverdata;
   7.198 +    SetFullscreen(_this, window, fullscreen ? output : NULL);
   7.199  }
   7.200  
   7.201  void
   7.202  Wayland_RestoreWindow(_THIS, SDL_Window * window)
   7.203  {
   7.204      SDL_WindowData *wind = window->driverdata;
   7.205 +    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
   7.206  
   7.207 -    wl_shell_surface_set_toplevel(wind->shell_surface);
   7.208 +    if (viddata->shell.zxdg) {
   7.209 +    } else {
   7.210 +        wl_shell_surface_set_toplevel(wind->shell_surface.wl);
   7.211 +    }
   7.212  
   7.213      WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
   7.214  }
   7.215 @@ -273,10 +371,15 @@
   7.216  Wayland_MaximizeWindow(_THIS, SDL_Window * window)
   7.217  {
   7.218      SDL_WindowData *wind = window->driverdata;
   7.219 +    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
   7.220  
   7.221 -    wl_shell_surface_set_maximized(wind->shell_surface, NULL);
   7.222 +    if (viddata->shell.zxdg) {
   7.223 +        zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
   7.224 +    } else {
   7.225 +        wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
   7.226 +    }
   7.227  
   7.228 -    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
   7.229 +    WAYLAND_wl_display_flush( viddata->display );
   7.230  }
   7.231  
   7.232  int Wayland_CreateWindow(_THIS, SDL_Window *window)
   7.233 @@ -310,9 +413,18 @@
   7.234      data->surface =
   7.235          wl_compositor_create_surface(c->compositor);
   7.236      wl_surface_set_user_data(data->surface, data);
   7.237 -    data->shell_surface = wl_shell_get_shell_surface(c->shell,
   7.238 -                                                     data->surface);
   7.239 -    wl_shell_surface_set_class (data->shell_surface, c->classname);
   7.240 +
   7.241 +    if (c->shell.zxdg) {
   7.242 +        data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
   7.243 +        /* !!! FIXME: add popup role */
   7.244 +        data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
   7.245 +        zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
   7.246 +        zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
   7.247 +    } else {
   7.248 +        data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
   7.249 +        wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
   7.250 +    }
   7.251 +
   7.252  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   7.253      if (c->surface_extension) {
   7.254          data->extended_surface = qt_surface_extension_get_extended_surface(
   7.255 @@ -333,10 +445,16 @@
   7.256          return SDL_SetError("failed to create a window surface");
   7.257      }
   7.258  
   7.259 -    if (data->shell_surface) {
   7.260 -        wl_shell_surface_set_user_data(data->shell_surface, data);
   7.261 -        wl_shell_surface_add_listener(data->shell_surface,
   7.262 -                                      &shell_surface_listener, data);
   7.263 +    if (c->shell.zxdg) {
   7.264 +        if (data->shell_surface.zxdg.surface) {
   7.265 +            zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
   7.266 +            zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
   7.267 +        }
   7.268 +    } else {
   7.269 +        if (data->shell_surface.wl) {
   7.270 +            wl_shell_surface_set_user_data(data->shell_surface.wl, data);
   7.271 +            wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data);
   7.272 +        }
   7.273      }
   7.274  
   7.275  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   7.276 @@ -356,6 +474,7 @@
   7.277          Wayland_input_lock_pointer(c->input);
   7.278      }
   7.279  
   7.280 +    wl_surface_commit(data->surface);
   7.281      WAYLAND_wl_display_flush(c->display);
   7.282  
   7.283      return 0;
   7.284 @@ -378,9 +497,14 @@
   7.285  void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
   7.286  {
   7.287      SDL_WindowData *wind = window->driverdata;
   7.288 +    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
   7.289      
   7.290      if (window->title != NULL) {
   7.291 -        wl_shell_surface_set_title(wind->shell_surface, window->title);
   7.292 +        if (viddata->shell.zxdg) {
   7.293 +            zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
   7.294 +        } else {
   7.295 +            wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
   7.296 +        }
   7.297      }
   7.298  
   7.299      WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
   7.300 @@ -395,8 +519,18 @@
   7.301          SDL_EGL_DestroySurface(_this, wind->egl_surface);
   7.302          WAYLAND_wl_egl_window_destroy(wind->egl_window);
   7.303  
   7.304 -        if (wind->shell_surface)
   7.305 -            wl_shell_surface_destroy(wind->shell_surface);
   7.306 +        if (data->shell.zxdg) {
   7.307 +            if (wind->shell_surface.zxdg.roleobj.toplevel) {
   7.308 +                zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
   7.309 +            }
   7.310 +            if (wind->shell_surface.zxdg.surface) {
   7.311 +                zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface);
   7.312 +            }
   7.313 +        } else {
   7.314 +            if (wind->shell_surface.wl) {
   7.315 +                wl_shell_surface_destroy(wind->shell_surface.wl);
   7.316 +            }
   7.317 +        }
   7.318  
   7.319  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   7.320          if (wind->extended_surface) {
     8.1 --- a/src/video/wayland/SDL_waylandwindow.h	Wed Feb 07 13:07:59 2018 -0500
     8.2 +++ b/src/video/wayland/SDL_waylandwindow.h	Wed Feb 07 13:13:55 2018 -0500
     8.3 @@ -32,10 +32,22 @@
     8.4  struct SDL_WaylandInput;
     8.5  
     8.6  typedef struct {
     8.7 +    struct zxdg_surface_v6 *surface;
     8.8 +    union {
     8.9 +        struct zxdg_toplevel_v6 *toplevel;
    8.10 +        struct zxdg_popup_v6 *popup;
    8.11 +    } roleobj;
    8.12 +} SDL_zxdg_shell_surface;
    8.13 +
    8.14 +typedef struct {
    8.15      SDL_Window *sdlwindow;
    8.16      SDL_VideoData *waylandData;
    8.17      struct wl_surface *surface;
    8.18 -    struct wl_shell_surface *shell_surface;
    8.19 +    union {
    8.20 +        /* !!! FIXME: add stable xdg_shell from 1.12 */
    8.21 +        SDL_zxdg_shell_surface zxdg;
    8.22 +        struct wl_shell_surface *wl;
    8.23 +    } shell_surface;
    8.24      struct wl_egl_window *egl_window;
    8.25      struct SDL_WaylandInput *keyboard_device;
    8.26      EGLSurface egl_surface;