wayland: Implemented xdg-wm-base support.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 24 Jun 2018 22:42:36 -0700
changeset 12033bc702c5a7c3a
parent 12032 a1fde7f4230f
child 12034 b3ae0dc577fd
wayland: Implemented xdg-wm-base support.

This is just in parity with the existing zxdg-shell-unstable-v6 code. Making
the Wayland target robust (and uh, with title bars) is going to take a lot
of work on top of this.
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/configure	Sun Jun 24 15:21:01 2018 -0400
     1.2 +++ b/configure	Sun Jun 24 22:42:36 2018 -0700
     1.3 @@ -19228,6 +19228,7 @@
     1.4              fi
     1.5  
     1.6              WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"
     1.7 +            WAYLAND_PROTOCOLS_STABLE="xdg-shell"
     1.8  
     1.9              SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
    1.10              EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
    1.11 @@ -24712,21 +24713,21 @@
    1.12  if test x$video_wayland = xyes; then
    1.13      WAYLAND_CORE_PROTOCOL_SOURCE='$(gen)/wayland-protocol.c'
    1.14      WAYLAND_CORE_PROTOCOL_HEADER='$(gen)/wayland-client-protocol.h'
    1.15 -    WAYLAND_PROTOCOLS_UNSTABLE_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
    1.16 +    WAYLAND_PROTOCOLS_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
    1.17          sed 's,[^ ]\+,\\$(gen)/&-protocol.c,g'`
    1.18 -    WAYLAND_PROTOCOLS_UNSTABLE_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
    1.19 +    WAYLAND_PROTOCOLS_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
    1.20          sed 's,[^ ]\+,\\$(gen)/&-client-protocol.h,g'`
    1.21 -    GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_UNSTABLE_SOURCES"
    1.22 -    GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_UNSTABLE_HEADERS"
    1.23 +    GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_SOURCES"
    1.24 +    GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_HEADERS"
    1.25  
    1.26      WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS="
    1.27  $WAYLAND_CORE_PROTOCOL_SOURCE: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
    1.28 -	\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    1.29 +	@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    1.30  	\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) code \$< \$@"
    1.31  
    1.32      WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS="
    1.33  $WAYLAND_CORE_PROTOCOL_HEADER: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
    1.34 -	\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    1.35 +	@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    1.36  	\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) client-header \$< \$@"
    1.37  
    1.38      WAYLAND_CORE_PROTOCOL_OBJECT="
    1.39 @@ -24736,13 +24737,25 @@
    1.40      WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
    1.41          do echo ; echo \$p | sed\
    1.42          "s,^\\([a-z\\-]\\+\\)-unstable-\\(v[0-9]\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
    1.43 -	\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    1.44 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    1.45 +	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`
    1.46 +
    1.47 +    WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
    1.48 +        do echo ; echo \$p | sed\
    1.49 +        "s,^\\([a-z\\-]\\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
    1.50 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    1.51  	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`
    1.52  
    1.53      WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
    1.54          do echo ; echo \$p | sed\
    1.55          "s,^\\([a-z\\-]\\+\\)-unstable-\\(v[0-9]\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
    1.56 -	\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    1.57 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    1.58 +	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`
    1.59 +
    1.60 +    WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
    1.61 +        do echo ; echo \$p | sed\
    1.62 +        "s,^\\([a-z\\-]\\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
    1.63 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    1.64  	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`
    1.65  
    1.66      WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
    1.67 @@ -24750,13 +24763,21 @@
    1.68          "s,^\\([a-z\\-]\\+\\)-unstable-\\(v[0-9]\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
    1.69  	\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`
    1.70  
    1.71 +    WAYLAND_PROTOCOLS_OBJECTS_STABLE=`for p in $WAYLAND_PROTOCOLS_STABLE;\
    1.72 +        do echo ; echo \$p | sed\
    1.73 +        "s,^\\([a-z\\-]\\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
    1.74 +	\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`
    1.75 +
    1.76      WAYLAND_PROTOCOLS_DEPENDS="
    1.77  $WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS
    1.78  $WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS
    1.79  $WAYLAND_CORE_PROTOCOL_OBJECT
    1.80  $WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS
    1.81 +$WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS
    1.82  $WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS
    1.83 +$WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS
    1.84  $WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE
    1.85 +$WAYLAND_PROTOCOLS_OBJECTS_STABLE
    1.86  "
    1.87  fi
    1.88  
     2.1 --- a/configure.in	Sun Jun 24 15:21:01 2018 -0400
     2.2 +++ b/configure.in	Sun Jun 24 22:42:36 2018 -0700
     2.3 @@ -1417,6 +1417,7 @@
     2.4              fi
     2.5  
     2.6              WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"
     2.7 +            WAYLAND_PROTOCOLS_STABLE="xdg-shell"
     2.8  
     2.9              SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
    2.10              EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
    2.11 @@ -3979,21 +3980,21 @@
    2.12  if test x$video_wayland = xyes; then
    2.13      WAYLAND_CORE_PROTOCOL_SOURCE='$(gen)/wayland-protocol.c'
    2.14      WAYLAND_CORE_PROTOCOL_HEADER='$(gen)/wayland-client-protocol.h'
    2.15 -    WAYLAND_PROTOCOLS_UNSTABLE_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
    2.16 +    WAYLAND_PROTOCOLS_SOURCES=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
    2.17          sed 's,[[^ ]]\+,\\$(gen)/&-protocol.c,g'`
    2.18 -    WAYLAND_PROTOCOLS_UNSTABLE_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE |\
    2.19 +    WAYLAND_PROTOCOLS_HEADERS=`echo $WAYLAND_PROTOCOLS_UNSTABLE $WAYLAND_PROTOCOLS_STABLE |\
    2.20          sed 's,[[^ ]]\+,\\$(gen)/&-client-protocol.h,g'`
    2.21 -    GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_UNSTABLE_SOURCES"
    2.22 -    GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_UNSTABLE_HEADERS"
    2.23 +    GEN_SOURCES="$GEN_SOURCES $WAYLAND_CORE_PROTOCOL_SOURCE $WAYLAND_PROTOCOLS_SOURCES"
    2.24 +    GEN_HEADERS="$GEN_HEADERS $WAYLAND_CORE_PROTOCOL_HEADER $WAYLAND_PROTOCOLS_HEADERS"
    2.25  
    2.26      WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS="
    2.27  $WAYLAND_CORE_PROTOCOL_SOURCE: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
    2.28 -	\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    2.29 +	@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    2.30  	\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) code \$< \$@"
    2.31  
    2.32      WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS="
    2.33  $WAYLAND_CORE_PROTOCOL_HEADER: $WAYLAND_CORE_PROTOCOL_DIR/wayland.xml
    2.34 -	\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    2.35 +	@\$(SHELL) \$(auxdir)/mkinstalldirs \$(gen)
    2.36  	\$(RUN_CMD_GEN)\$(WAYLAND_SCANNER) client-header \$< \$@"
    2.37  
    2.38      WAYLAND_CORE_PROTOCOL_OBJECT="
    2.39 @@ -4003,13 +4004,25 @@
    2.40      WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
    2.41          do echo ; echo \$p | sed\
    2.42          "s,^\\([[a-z\\-]]\\+\\)-unstable-\\(v[[0-9]]\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
    2.43 -	\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    2.44 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    2.45 +	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`
    2.46 +
    2.47 +    WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
    2.48 +        do echo ; echo \$p | sed\
    2.49 +        "s,^\\([[a-z\\-]]\\+\\)\$,\\$(gen)/&-client-protocol.h: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
    2.50 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    2.51  	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) client-header \\$< \\$@," ; done`
    2.52  
    2.53      WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
    2.54          do echo ; echo \$p | sed\
    2.55          "s,^\\([[a-z\\-]]\\+\\)-unstable-\\(v[[0-9]]\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/unstable/\1/&.xml\\\\
    2.56 -	\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    2.57 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    2.58 +	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`
    2.59 +
    2.60 +    WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS=`for p in $WAYLAND_PROTOCOLS_STABLE;\
    2.61 +        do echo ; echo \$p | sed\
    2.62 +        "s,^\\([[a-z\\-]]\\+\\)\$,\\$(gen)/&-protocol.c: $WAYLAND_PROTOCOLS_DIR/stable/\1/&.xml\\\\
    2.63 +	@\\$(SHELL) \\$(auxdir)/mkinstalldirs \\$(gen)\\\\
    2.64  	\\$(RUN_CMD_GEN)\\$(WAYLAND_SCANNER) code \\$< \\$@," ; done`
    2.65  
    2.66      WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE=`for p in $WAYLAND_PROTOCOLS_UNSTABLE;\
    2.67 @@ -4017,13 +4030,21 @@
    2.68          "s,^\\([[a-z\\-]]\\+\\)-unstable-\\(v[[0-9]]\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
    2.69  	\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`
    2.70  
    2.71 +    WAYLAND_PROTOCOLS_OBJECTS_STABLE=`for p in $WAYLAND_PROTOCOLS_STABLE;\
    2.72 +        do echo ; echo \$p | sed\
    2.73 +        "s,^\\([[a-z\\-]]\\+\\)\$,\\\$(objects)/&-protocol.lo: \\$(gen)/&-protocol.c \\$(gen)/&-client-protocol.h\\\\
    2.74 +	\\$(RUN_CMD_CC)\\$(LIBTOOL) --tag=CC --mode=compile \\$(CC) \\$(CFLAGS) \\$(EXTRA_CFLAGS) $DEPENDENCY_TRACKING_OPTIONS -c \\$< -o \\$@," ; done`
    2.75 +
    2.76      WAYLAND_PROTOCOLS_DEPENDS="
    2.77  $WAYLAND_CORE_PROTOCOL_SOURCE_DEPENDS
    2.78  $WAYLAND_CORE_PROTOCOL_HEADER_DEPENDS
    2.79  $WAYLAND_CORE_PROTOCOL_OBJECT
    2.80  $WAYLAND_PROTOCOLS_CLIENT_HEADER_UNSTABLE_DEPENDS
    2.81 +$WAYLAND_PROTOCOLS_CLIENT_HEADER_STABLE_DEPENDS
    2.82  $WAYLAND_PROTOCOLS_CODE_UNSTABLE_DEPENDS
    2.83 +$WAYLAND_PROTOCOLS_CODE_STABLE_DEPENDS
    2.84  $WAYLAND_PROTOCOLS_OBJECTS_UNSTABLE
    2.85 +$WAYLAND_PROTOCOLS_OBJECTS_STABLE
    2.86  "
    2.87  fi
    2.88  
     3.1 --- a/src/video/wayland/SDL_waylandevents.c	Sun Jun 24 15:21:01 2018 -0400
     3.2 +++ b/src/video/wayland/SDL_waylandevents.c	Sun Jun 24 22:42:36 2018 -0700
     3.3 @@ -40,6 +40,7 @@
     3.4  
     3.5  #include "pointer-constraints-unstable-v1-client-protocol.h"
     3.6  #include "relative-pointer-unstable-v1-client-protocol.h"
     3.7 +#include "xdg-shell-client-protocol.h"
     3.8  #include "xdg-shell-unstable-v6-client-protocol.h"
     3.9  
    3.10  #include <linux/input.h>
    3.11 @@ -263,7 +264,9 @@
    3.12  
    3.13          switch (rc) {
    3.14              case SDL_HITTEST_DRAGGABLE:
    3.15 -                if (input->display->shell.zxdg) {
    3.16 +                if (input->display->shell.xdg) {
    3.17 +                    xdg_toplevel_move(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial);
    3.18 +                } else if (input->display->shell.zxdg) {
    3.19                      zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial);
    3.20                  } else {
    3.21                      wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial);
    3.22 @@ -278,7 +281,9 @@
    3.23              case SDL_HITTEST_RESIZE_BOTTOM:
    3.24              case SDL_HITTEST_RESIZE_BOTTOMLEFT:
    3.25              case SDL_HITTEST_RESIZE_LEFT:
    3.26 -                if (input->display->shell.zxdg) {
    3.27 +                if (input->display->shell.xdg) {
    3.28 +                    xdg_toplevel_resize(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    3.29 +                } else if (input->display->shell.zxdg) {
    3.30                      zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
    3.31                  } else {
    3.32                      wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
     4.1 --- a/src/video/wayland/SDL_waylandvideo.c	Sun Jun 24 15:21:01 2018 -0400
     4.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Sun Jun 24 22:42:36 2018 -0700
     4.3 @@ -45,6 +45,7 @@
     4.4  #include "SDL_waylanddyn.h"
     4.5  #include <wayland-util.h>
     4.6  
     4.7 +#include "xdg-shell-client-protocol.h"
     4.8  #include "xdg-shell-unstable-v6-client-protocol.h"
     4.9  
    4.10  #define WAYLANDVID_DRIVER_NAME "wayland"
    4.11 @@ -328,6 +329,17 @@
    4.12  
    4.13  
    4.14  static void
    4.15 +handle_ping_xdg_wm_base(void *data, struct xdg_wm_base *xdg, uint32_t serial)
    4.16 +{
    4.17 +    xdg_wm_base_pong(xdg, serial);
    4.18 +}
    4.19 +
    4.20 +static const struct xdg_wm_base_listener shell_listener_xdg = {
    4.21 +    handle_ping_xdg_wm_base
    4.22 +};
    4.23 +
    4.24 +
    4.25 +static void
    4.26  display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
    4.27                        const char *interface, uint32_t version)
    4.28  {
    4.29 @@ -339,6 +351,9 @@
    4.30          Wayland_add_display(d, id);
    4.31      } else if (strcmp(interface, "wl_seat") == 0) {
    4.32          Wayland_display_add_input(d, id);
    4.33 +    } else if (strcmp(interface, "xdg_wm_base") == 0) {
    4.34 +        d->shell.xdg = wl_registry_bind(d->registry, id, &xdg_wm_base_interface, 1);
    4.35 +        xdg_wm_base_add_listener(d->shell.xdg, &shell_listener_xdg, NULL);
    4.36      } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
    4.37          d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1);
    4.38          zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL);
    4.39 @@ -475,6 +490,9 @@
    4.40      if (data->shell.wl)
    4.41          wl_shell_destroy(data->shell.wl);
    4.42  
    4.43 +    if (data->shell.xdg)
    4.44 +        xdg_wm_base_destroy(data->shell.xdg);
    4.45 +
    4.46      if (data->shell.zxdg)
    4.47          zxdg_shell_v6_destroy(data->shell.zxdg);
    4.48  
     5.1 --- a/src/video/wayland/SDL_waylandvideo.h	Sun Jun 24 15:21:01 2018 -0400
     5.2 +++ b/src/video/wayland/SDL_waylandvideo.h	Sun Jun 24 22:42:36 2018 -0700
     5.3 @@ -24,6 +24,16 @@
     5.4  #ifndef SDL_waylandvideo_h_
     5.5  #define SDL_waylandvideo_h_
     5.6  
     5.7 +
     5.8 +/*
     5.9 +!!! FIXME: xdg_wm_base is the stable replacement for zxdg_shell_v6. While it's
    5.10 +!!! FIXME:  harmless to leave it here, consider deleting the obsolete codepath
    5.11 +!!! FIXME:  soon, since Wayland (with xdg_wm_base) will probably be mainline
    5.12 +!!! FIXME:  by the time people are relying on this SDL target. It's available
    5.13 +!!! FIXME:  in Ubuntu 18.04 (and other distros).
    5.14 +*/
    5.15 +
    5.16 +
    5.17  #include <EGL/egl.h>
    5.18  #include "wayland-util.h"
    5.19  
    5.20 @@ -44,7 +54,7 @@
    5.21      struct wl_cursor_theme *cursor_theme;
    5.22      struct wl_pointer *pointer;
    5.23      struct {
    5.24 -        /* !!! FIXME: add stable xdg_shell from 1.12 */
    5.25 +        struct xdg_wm_base *xdg;
    5.26          struct zxdg_shell_v6 *zxdg;
    5.27          struct wl_shell *wl;
    5.28      } shell;
     6.1 --- a/src/video/wayland/SDL_waylandwindow.c	Sun Jun 24 15:21:01 2018 -0400
     6.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Sun Jun 24 22:42:36 2018 -0700
     6.3 @@ -33,6 +33,7 @@
     6.4  #include "SDL_waylanddyn.h"
     6.5  #include "SDL_hints.h"
     6.6  
     6.7 +#include "xdg-shell-client-protocol.h"
     6.8  #include "xdg-shell-unstable-v6-client-protocol.h"
     6.9  
    6.10  /* On modern desktops, we probably will use the xdg-shell protocol instead
    6.11 @@ -185,6 +186,87 @@
    6.12  };
    6.13  
    6.14  
    6.15 +
    6.16 +static void
    6.17 +handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t serial)
    6.18 +{
    6.19 +    SDL_WindowData *wind = (SDL_WindowData *)data;
    6.20 +    SDL_Window *window = wind->sdlwindow;
    6.21 +    struct wl_region *region;
    6.22 +
    6.23 +    wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE;
    6.24 +
    6.25 +    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
    6.26 +
    6.27 +    region = wl_compositor_create_region(wind->waylandData->compositor);
    6.28 +    wl_region_add(region, 0, 0, window->w, window->h);
    6.29 +    wl_surface_set_opaque_region(wind->surface, region);
    6.30 +    wl_region_destroy(region);
    6.31 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h);
    6.32 +    xdg_surface_ack_configure(xdg, serial);
    6.33 +}
    6.34 +
    6.35 +static const struct xdg_surface_listener shell_surface_listener_xdg = {
    6.36 +    handle_configure_xdg_shell_surface
    6.37 +};
    6.38 +
    6.39 +
    6.40 +static void
    6.41 +handle_configure_xdg_toplevel(void *data,
    6.42 +			  struct xdg_toplevel *xdg_toplevel,
    6.43 +			  int32_t width,
    6.44 +			  int32_t height,
    6.45 +			  struct wl_array *states)
    6.46 +{
    6.47 +    SDL_WindowData *wind = (SDL_WindowData *)data;
    6.48 +    SDL_Window *window = wind->sdlwindow;
    6.49 +
    6.50 +    /* wl_shell_surface spec states that this is a suggestion.
    6.51 +       Ignore if less than or greater than max/min size. */
    6.52 +
    6.53 +    if (width == 0 || height == 0) {
    6.54 +        return;
    6.55 +    }
    6.56 +
    6.57 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    6.58 +        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
    6.59 +            if (window->max_w > 0) {
    6.60 +                width = SDL_min(width, window->max_w);
    6.61 +            } 
    6.62 +            width = SDL_max(width, window->min_w);
    6.63 +
    6.64 +            if (window->max_h > 0) {
    6.65 +                height = SDL_min(height, window->max_h);
    6.66 +            }
    6.67 +            height = SDL_max(height, window->min_h);
    6.68 +        } else {
    6.69 +            return;
    6.70 +        }
    6.71 +    }
    6.72 +
    6.73 +    if (width == window->w && height == window->h) {
    6.74 +        return;
    6.75 +    }
    6.76 +
    6.77 +    window->w = width;
    6.78 +    window->h = height;
    6.79 +}
    6.80 +
    6.81 +static void
    6.82 +handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel)
    6.83 +{
    6.84 +    SDL_WindowData *window = (SDL_WindowData *)data;
    6.85 +    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
    6.86 +}
    6.87 +
    6.88 +static const struct xdg_toplevel_listener toplevel_listener_xdg = {
    6.89 +    handle_configure_xdg_toplevel,
    6.90 +    handle_close_xdg_toplevel
    6.91 +};
    6.92 +
    6.93 +
    6.94 +
    6.95 +
    6.96  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    6.97  static void
    6.98  handle_onscreen_visibility(void *data,
    6.99 @@ -257,7 +339,13 @@
   6.100      const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
   6.101      SDL_WindowData *wind = window->driverdata;
   6.102  
   6.103 -    if (viddata->shell.zxdg) {
   6.104 +    if (viddata->shell.xdg) {
   6.105 +        if (output) {
   6.106 +            xdg_toplevel_set_fullscreen(wind->shell_surface.xdg.roleobj.toplevel, output);
   6.107 +        } else {
   6.108 +            xdg_toplevel_unset_fullscreen(wind->shell_surface.xdg.roleobj.toplevel);
   6.109 +        }
   6.110 +    } else if (viddata->shell.zxdg) {
   6.111          if (output) {
   6.112              zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output);
   6.113          } else {
   6.114 @@ -362,7 +450,8 @@
   6.115      SDL_WindowData *wind = window->driverdata;
   6.116      const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
   6.117  
   6.118 -    if (viddata->shell.zxdg) {
   6.119 +    if (viddata->shell.xdg) {
   6.120 +    } else if (viddata->shell.zxdg) {
   6.121      } else {
   6.122          wl_shell_surface_set_toplevel(wind->shell_surface.wl);
   6.123      }
   6.124 @@ -376,7 +465,9 @@
   6.125      SDL_WindowData *wind = window->driverdata;
   6.126      SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
   6.127  
   6.128 -    if (viddata->shell.zxdg) {
   6.129 +    if (viddata->shell.xdg) {
   6.130 +        xdg_toplevel_set_maximized(wind->shell_surface.xdg.roleobj.toplevel);
   6.131 +    } else if (viddata->shell.zxdg) {
   6.132          zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
   6.133      } else {
   6.134          wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
   6.135 @@ -417,7 +508,13 @@
   6.136          wl_compositor_create_surface(c->compositor);
   6.137      wl_surface_set_user_data(data->surface, data);
   6.138  
   6.139 -    if (c->shell.zxdg) {
   6.140 +    if (c->shell.xdg) {
   6.141 +        data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->surface);
   6.142 +        /* !!! FIXME: add popup role */
   6.143 +        data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface);
   6.144 +        xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data);
   6.145 +        xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname);
   6.146 +    } else if (c->shell.zxdg) {
   6.147          data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
   6.148          /* !!! FIXME: add popup role */
   6.149          data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
   6.150 @@ -448,7 +545,12 @@
   6.151          return SDL_SetError("failed to create a window surface");
   6.152      }
   6.153  
   6.154 -    if (c->shell.zxdg) {
   6.155 +    if (c->shell.xdg) {
   6.156 +        if (data->shell_surface.xdg.surface) {
   6.157 +            xdg_surface_set_user_data(data->shell_surface.xdg.surface, data);
   6.158 +            xdg_surface_add_listener(data->shell_surface.xdg.surface, &shell_surface_listener_xdg, data);
   6.159 +        }
   6.160 +    } else if (c->shell.zxdg) {
   6.161          if (data->shell_surface.zxdg.surface) {
   6.162              zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
   6.163              zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
   6.164 @@ -482,7 +584,14 @@
   6.165  
   6.166      /* we have to wait until the surface gets a "configure" event, or
   6.167         use of this surface will fail. This is a new rule for xdg_shell. */
   6.168 -    if (c->shell.zxdg) {
   6.169 +    if (c->shell.xdg) {
   6.170 +        if (data->shell_surface.xdg.surface) {
   6.171 +            while (!data->shell_surface.xdg.initial_configure_seen) {
   6.172 +                WAYLAND_wl_display_flush(c->display);
   6.173 +                WAYLAND_wl_display_dispatch(c->display);
   6.174 +            }
   6.175 +        }
   6.176 +    } else if (c->shell.zxdg) {
   6.177          if (data->shell_surface.zxdg.surface) {
   6.178              while (!data->shell_surface.zxdg.initial_configure_seen) {
   6.179                  WAYLAND_wl_display_flush(c->display);
   6.180 @@ -514,7 +623,9 @@
   6.181      SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
   6.182      
   6.183      if (window->title != NULL) {
   6.184 -        if (viddata->shell.zxdg) {
   6.185 +        if (viddata->shell.xdg) {
   6.186 +            xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title);
   6.187 +        } else if (viddata->shell.zxdg) {
   6.188              zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
   6.189          } else {
   6.190              wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
   6.191 @@ -533,7 +644,14 @@
   6.192          SDL_EGL_DestroySurface(_this, wind->egl_surface);
   6.193          WAYLAND_wl_egl_window_destroy(wind->egl_window);
   6.194  
   6.195 -        if (data->shell.zxdg) {
   6.196 +        if (data->shell.xdg) {
   6.197 +            if (wind->shell_surface.xdg.roleobj.toplevel) {
   6.198 +                xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel);
   6.199 +            }
   6.200 +            if (wind->shell_surface.zxdg.surface) {
   6.201 +                xdg_surface_destroy(wind->shell_surface.xdg.surface);
   6.202 +            }
   6.203 +        } else if (data->shell.zxdg) {
   6.204              if (wind->shell_surface.zxdg.roleobj.toplevel) {
   6.205                  zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
   6.206              }
     7.1 --- a/src/video/wayland/SDL_waylandwindow.h	Sun Jun 24 15:21:01 2018 -0400
     7.2 +++ b/src/video/wayland/SDL_waylandwindow.h	Sun Jun 24 22:42:36 2018 -0700
     7.3 @@ -41,11 +41,20 @@
     7.4  } SDL_zxdg_shell_surface;
     7.5  
     7.6  typedef struct {
     7.7 +    struct xdg_surface *surface;
     7.8 +    union {
     7.9 +        struct xdg_toplevel *toplevel;
    7.10 +        struct xdg_popup *popup;
    7.11 +    } roleobj;
    7.12 +    SDL_bool initial_configure_seen;
    7.13 +} SDL_xdg_shell_surface;
    7.14 +
    7.15 +typedef struct {
    7.16      SDL_Window *sdlwindow;
    7.17      SDL_VideoData *waylandData;
    7.18      struct wl_surface *surface;
    7.19      union {
    7.20 -        /* !!! FIXME: add stable xdg_shell from 1.12 */
    7.21 +        SDL_xdg_shell_surface xdg;
    7.22          SDL_zxdg_shell_surface zxdg;
    7.23          struct wl_shell_surface *wl;
    7.24      } shell_surface;