Commit cd53220749ddf061c8d55d8edd09fd658e3426e4

Ryan C. Gordon 2018-02-07T13:13:55

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 91e2f97..4093594 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -685,7 +685,7 @@ macro(CheckWayland)
 
       WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
 
-      foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
+      foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1, xdg-shell-unstable-v6)
         string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
         WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
       endforeach()
diff --git a/configure b/configure
index 1025608..bc79df9 100755
--- a/configure
+++ b/configure
@@ -19220,7 +19220,7 @@ $as_echo "#define SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1" >>confdefs.h
 
             fi
 
-            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1"
+            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"
 
             SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
             EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
diff --git a/configure.in b/configure.in
index d8137f2..56dd7a7 100644
--- a/configure.in
+++ b/configure.in
@@ -1409,7 +1409,7 @@ AC_HELP_STRING([--enable-video-wayland-qt-touch], [QtWayland server support for 
                 AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH, 1, [ ])
             fi
 
-            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1"
+            WAYLAND_PROTOCOLS_UNSTABLE="relative-pointer-unstable-v1 pointer-constraints-unstable-v1 xdg-shell-unstable-v6"
 
             SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
             EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS -I\$(gen)"
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 3b07962..53453a2 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -40,6 +40,7 @@
 
 #include "pointer-constraints-unstable-v1-client-protocol.h"
 #include "relative-pointer-unstable-v1-client-protocol.h"
+#include "xdg-shell-unstable-v6-client-protocol.h"
 
 #include <linux/input.h>
 #include <sys/select.h>
@@ -248,15 +249,25 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
     if (window->hit_test) {
         const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
         const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
-        static const uint32_t directions[] = {
+
+        static const uint32_t directions_wl[] = {
             WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
             WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
             WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
             WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
         };
+
+        /* the names are different (ZXDG_TOPLEVEL_V6_RESIZE_EDGE_* vs
+           WL_SHELL_SURFACE_RESIZE_*), but the values are the same. */
+        const uint32_t *directions_zxdg = directions_wl;
+
         switch (rc) {
             case SDL_HITTEST_DRAGGABLE:
-                wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
+                if (input->display->shell.zxdg) {
+                    zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial);
+                } else {
+                    wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial);
+                }
                 return SDL_TRUE;
 
             case SDL_HITTEST_RESIZE_TOPLEFT:
@@ -267,7 +278,11 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
             case SDL_HITTEST_RESIZE_BOTTOM:
             case SDL_HITTEST_RESIZE_BOTTOMLEFT:
             case SDL_HITTEST_RESIZE_LEFT:
-                wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+                if (input->display->shell.zxdg) {
+                    zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+                } else {
+                    wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+                }
                 return SDL_TRUE;
 
             default: return SDL_FALSE;
@@ -950,6 +965,7 @@ SDL_WaylandDataDevice* Wayland_get_data_device(struct SDL_WaylandInput *input)
     return input->data_device;
 }
 
+/* !!! FIXME: just merge these into display_handle_global(). */
 void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id)
 {
     d->relative_pointer_manager =
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 5dd4863..8401a08 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -45,6 +45,8 @@
 #include "SDL_waylanddyn.h"
 #include <wayland-util.h>
 
+#include "xdg-shell-unstable-v6-client-protocol.h"
+
 #define WAYLANDVID_DRIVER_NAME "wayland"
 
 /* Initialization/Query functions */
@@ -64,6 +66,12 @@ Wayland_VideoQuit(_THIS);
 static char *
 get_classname()
 {
+/* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec:
+	"The surface class identifies the general class of applications
+	to which the surface belongs. A common convention is to use the
+	file name (or the full path if it is a non-standard location) of
+	the application's .desktop file as the class." */
+
     char *spot;
 #if defined(__LINUX__) || defined(__FREEBSD__)
     char procfile[1024];
@@ -307,6 +315,18 @@ static const struct qt_windowmanager_listener windowmanager_listener = {
 };
 #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
 
+
+static void
+handle_ping_zxdg_shell(void *data, struct zxdg_shell_v6 *zxdg, uint32_t serial)
+{
+    zxdg_shell_v6_pong(zxdg, serial);
+}
+
+static const struct zxdg_shell_v6_listener shell_listener_zxdg = {
+    handle_ping_zxdg_shell
+};
+
+
 static void
 display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
                       const char *interface, uint32_t version)
@@ -319,8 +339,11 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
         Wayland_add_display(d, id);
     } else if (strcmp(interface, "wl_seat") == 0) {
         Wayland_display_add_input(d, id);
+    } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
+        d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1);
+        zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL);
     } else if (strcmp(interface, "wl_shell") == 0) {
-        d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
+        d->shell.wl = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
     } else if (strcmp(interface, "wl_shm") == 0) {
         d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
         d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm);
@@ -330,6 +353,7 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
         Wayland_display_add_pointer_constraints(d, id);
     } else if (strcmp(interface, "wl_data_device_manager") == 0) {
         d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
+
 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
     } else if (strcmp(interface, "qt_touch_extension") == 0) {
         Wayland_touch_create(d, id);
@@ -448,8 +472,11 @@ Wayland_VideoQuit(_THIS)
     if (data->cursor_theme)
         WAYLAND_wl_cursor_theme_destroy(data->cursor_theme);
 
-    if (data->shell)
-        wl_shell_destroy(data->shell);
+    if (data->shell.wl)
+        wl_shell_destroy(data->shell.wl);
+
+    if (data->shell.zxdg)
+        zxdg_shell_v6_destroy(data->shell.zxdg);
 
     if (data->compositor)
         wl_compositor_destroy(data->compositor);
diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h
index b493c95..6ad68de 100644
--- a/src/video/wayland/SDL_waylandvideo.h
+++ b/src/video/wayland/SDL_waylandvideo.h
@@ -43,7 +43,11 @@ typedef struct {
     struct wl_shm *shm;
     struct wl_cursor_theme *cursor_theme;
     struct wl_pointer *pointer;
-    struct wl_shell *shell;
+    struct {
+        /* !!! FIXME: add stable xdg_shell from 1.12 */
+        struct zxdg_shell_v6 *zxdg;
+        struct wl_shell *wl;
+    } shell;
     struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
     struct zwp_pointer_constraints_v1 *pointer_constraints;
     struct wl_data_device_manager *data_device_manager;
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 837f072..684022a 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -33,15 +33,22 @@
 #include "SDL_waylanddyn.h"
 #include "SDL_hints.h"
 
+#include "xdg-shell-unstable-v6-client-protocol.h"
+
+/* On modern desktops, we probably will use the xdg-shell protocol instead
+   of wl_shell, but wl_shell might be useful on older Wayland installs that
+   don't have the newer protocol, or embedded things that don't have a full
+   window manager. */
+
 static void
-handle_ping(void *data, struct wl_shell_surface *shell_surface,
+handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
             uint32_t serial)
 {
     wl_shell_surface_pong(shell_surface, serial);
 }
 
 static void
-handle_configure(void *data, struct wl_shell_surface *shell_surface,
+handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
                  uint32_t edges, int32_t width, int32_t height)
 {
     SDL_WindowData *wind = (SDL_WindowData *)data;
@@ -87,16 +94,94 @@ handle_configure(void *data, struct wl_shell_surface *shell_surface,
 }
 
 static void
-handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
+handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
 {
 }
 
-static const struct wl_shell_surface_listener shell_surface_listener = {
-    handle_ping,
-    handle_configure,
-    handle_popup_done
+static const struct wl_shell_surface_listener shell_surface_listener_wl = {
+    handle_ping_wl_shell_surface,
+    handle_configure_wl_shell_surface,
+    handle_popup_done_wl_shell_surface
 };
 
+
+
+
+static void
+handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, uint32_t serial)
+{
+    SDL_WindowData *wind = (SDL_WindowData *)data;
+    SDL_Window *window = wind->sdlwindow;
+    struct wl_region *region;
+    WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+
+    region = wl_compositor_create_region(wind->waylandData->compositor);
+    wl_region_add(region, 0, 0, window->w, window->h);
+    wl_surface_set_opaque_region(wind->surface, region);
+    wl_region_destroy(region);
+    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h);
+    zxdg_surface_v6_ack_configure(zxdg, serial);
+}
+
+static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
+    handle_configure_zxdg_shell_surface
+};
+
+
+static void
+handle_configure_zxdg_toplevel(void *data,
+			  struct zxdg_toplevel_v6 *zxdg_toplevel_v6,
+			  int32_t width,
+			  int32_t height,
+			  struct wl_array *states)
+{
+    SDL_WindowData *wind = (SDL_WindowData *)data;
+    SDL_Window *window = wind->sdlwindow;
+
+    /* wl_shell_surface spec states that this is a suggestion.
+       Ignore if less than or greater than max/min size. */
+
+    if (width == 0 || height == 0) {
+        return;
+    }
+
+    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+        if ((window->flags & SDL_WINDOW_RESIZABLE)) {
+            if (window->max_w > 0) {
+                width = SDL_min(width, window->max_w);
+            } 
+            width = SDL_max(width, window->min_w);
+
+            if (window->max_h > 0) {
+                height = SDL_min(height, window->max_h);
+            }
+            height = SDL_max(height, window->min_h);
+        } else {
+            return;
+        }
+    }
+
+    if (width == window->w && height == window->h) {
+        return;
+    }
+
+    window->w = width;
+    window->h = height;
+}
+
+static void
+handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
+{
+    SDL_WindowData *window = (SDL_WindowData *)data;
+    SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
+}
+
+static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = {
+    handle_configure_zxdg_toplevel,
+    handle_close_zxdg_toplevel
+};
+
+
 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
 static void
 handle_onscreen_visibility(void *data,
@@ -151,7 +236,7 @@ Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
 
     info->info.wl.display = data->waylandData->display;
     info->info.wl.surface = data->surface;
-    info->info.wl.shell_surface = data->shell_surface;
+    info->info.wl.shell_surface = data->shell_surface.wl;
     info->subsystem = SDL_SYSWM_WAYLAND;
 
     return SDL_TRUE;
@@ -163,20 +248,37 @@ Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
     return 0;  /* just succeed, the real work is done elsewhere. */
 }
 
-void Wayland_ShowWindow(_THIS, SDL_Window *window)
+static void
+SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output)
 {
+    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
     SDL_WindowData *wind = window->driverdata;
 
-    if (window->flags & SDL_WINDOW_FULLSCREEN)
-        wl_shell_surface_set_fullscreen(wind->shell_surface,
-                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
-                                        0, (struct wl_output *)window->fullscreen_mode.driverdata);
-    else
-        wl_shell_surface_set_toplevel(wind->shell_surface);
+    if (viddata->shell.zxdg) {
+        if (output) {
+            zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output);
+        } else {
+            zxdg_toplevel_v6_unset_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel);
+        }
+    } else {
+        if (output) {
+            wl_shell_surface_set_fullscreen(wind->shell_surface.wl,
+                                            WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
+                                            0, output);
+        } else {
+            wl_shell_surface_set_toplevel(wind->shell_surface.wl);
+        }
+    }
 
     WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
 }
 
+void Wayland_ShowWindow(_THIS, SDL_Window *window)
+{
+    struct wl_output *output = (struct wl_output *) window->fullscreen_mode.driverdata;
+    SetFullscreen(_this, window, (window->flags & SDL_WINDOW_FULLSCREEN) ? output : NULL);
+}
+
 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
 static void SDLCALL
 QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
@@ -247,24 +349,20 @@ void
 Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
                             SDL_VideoDisplay * _display, SDL_bool fullscreen)
 {
-    SDL_WindowData *wind = window->driverdata;
-
-    if (fullscreen)
-        wl_shell_surface_set_fullscreen(wind->shell_surface,
-                                        WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
-                                        0, (struct wl_output *)_display->driverdata);
-    else
-        wl_shell_surface_set_toplevel(wind->shell_surface);
-
-    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+    struct wl_output *output = (struct wl_output *) _display->driverdata;
+    SetFullscreen(_this, window, fullscreen ? output : NULL);
 }
 
 void
 Wayland_RestoreWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *wind = window->driverdata;
+    const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
 
-    wl_shell_surface_set_toplevel(wind->shell_surface);
+    if (viddata->shell.zxdg) {
+    } else {
+        wl_shell_surface_set_toplevel(wind->shell_surface.wl);
+    }
 
     WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
 }
@@ -273,10 +371,15 @@ void
 Wayland_MaximizeWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *wind = window->driverdata;
+    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
 
-    wl_shell_surface_set_maximized(wind->shell_surface, NULL);
+    if (viddata->shell.zxdg) {
+        zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
+    } else {
+        wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
+    }
 
-    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+    WAYLAND_wl_display_flush( viddata->display );
 }
 
 int Wayland_CreateWindow(_THIS, SDL_Window *window)
@@ -310,9 +413,18 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
     data->surface =
         wl_compositor_create_surface(c->compositor);
     wl_surface_set_user_data(data->surface, data);
-    data->shell_surface = wl_shell_get_shell_surface(c->shell,
-                                                     data->surface);
-    wl_shell_surface_set_class (data->shell_surface, c->classname);
+
+    if (c->shell.zxdg) {
+        data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
+        /* !!! FIXME: add popup role */
+        data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
+        zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
+        zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
+    } else {
+        data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
+        wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
+    }
+
 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
     if (c->surface_extension) {
         data->extended_surface = qt_surface_extension_get_extended_surface(
@@ -333,10 +445,16 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
         return SDL_SetError("failed to create a window surface");
     }
 
-    if (data->shell_surface) {
-        wl_shell_surface_set_user_data(data->shell_surface, data);
-        wl_shell_surface_add_listener(data->shell_surface,
-                                      &shell_surface_listener, data);
+    if (c->shell.zxdg) {
+        if (data->shell_surface.zxdg.surface) {
+            zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
+            zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
+        }
+    } else {
+        if (data->shell_surface.wl) {
+            wl_shell_surface_set_user_data(data->shell_surface.wl, data);
+            wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data);
+        }
     }
 
 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
@@ -356,6 +474,7 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window)
         Wayland_input_lock_pointer(c->input);
     }
 
+    wl_surface_commit(data->surface);
     WAYLAND_wl_display_flush(c->display);
 
     return 0;
@@ -378,9 +497,14 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window)
 void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
 {
     SDL_WindowData *wind = window->driverdata;
+    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
     
     if (window->title != NULL) {
-        wl_shell_surface_set_title(wind->shell_surface, window->title);
+        if (viddata->shell.zxdg) {
+            zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
+        } else {
+            wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
+        }
     }
 
     WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
@@ -395,8 +519,18 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window)
         SDL_EGL_DestroySurface(_this, wind->egl_surface);
         WAYLAND_wl_egl_window_destroy(wind->egl_window);
 
-        if (wind->shell_surface)
-            wl_shell_surface_destroy(wind->shell_surface);
+        if (data->shell.zxdg) {
+            if (wind->shell_surface.zxdg.roleobj.toplevel) {
+                zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
+            }
+            if (wind->shell_surface.zxdg.surface) {
+                zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface);
+            }
+        } else {
+            if (wind->shell_surface.wl) {
+                wl_shell_surface_destroy(wind->shell_surface.wl);
+            }
+        }
 
 #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
         if (wind->extended_surface) {
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index f35b0ac..80d4f31 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -32,10 +32,22 @@
 struct SDL_WaylandInput;
 
 typedef struct {
+    struct zxdg_surface_v6 *surface;
+    union {
+        struct zxdg_toplevel_v6 *toplevel;
+        struct zxdg_popup_v6 *popup;
+    } roleobj;
+} SDL_zxdg_shell_surface;
+
+typedef struct {
     SDL_Window *sdlwindow;
     SDL_VideoData *waylandData;
     struct wl_surface *surface;
-    struct wl_shell_surface *shell_surface;
+    union {
+        /* !!! FIXME: add stable xdg_shell from 1.12 */
+        SDL_zxdg_shell_surface zxdg;
+        struct wl_shell_surface *wl;
+    } shell_surface;
     struct wl_egl_window *egl_window;
     struct SDL_WaylandInput *keyboard_device;
     EGLSurface egl_surface;