]> Pileus Git - ~andy/gtk/blob - gdk/wayland/gdkwindow-wayland.c
wayland: Improve the error reporting in the Cairo GL surface code path
[~andy/gtk] / gdk / wayland / gdkwindow-wayland.c
1 /*
2  * Copyright © 2010 Intel Corporation
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include <netinet/in.h>
21 #include <unistd.h>
22
23 #include "gdk.h"
24 #include "gdkwayland.h"
25
26 #include "gdkwindow.h"
27 #include "gdkwindowimpl.h"
28 #include "gdkdisplay-wayland.h"
29 #include "gdkprivate-wayland.h"
30 #include "gdkinternals.h"
31 #include "gdkdeviceprivate.h"
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <sys/mman.h>
37 #include <errno.h>
38
39 #include <wayland-egl.h>
40
41 #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
42   (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&   \
43    GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
44
45 #define WINDOW_IS_TOPLEVEL(window)                   \
46   (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&   \
47    GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \
48    GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
49
50 /* Return whether time1 is considered later than time2 as far as xserver
51  * time is concerned.  Accounts for wraparound.
52  */
53 #define XSERVER_TIME_IS_LATER(time1, time2)                        \
54   ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) ||  \
55     (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 ))     \
56   )
57
58 typedef struct _GdkWaylandWindow GdkWaylandWindow;
59 typedef struct _GdkWaylandWindowClass GdkWaylandWindowClass;
60
61 struct _GdkWaylandWindow {
62   GdkWindow parent;
63 };
64
65 struct _GdkWaylandWindowClass {
66   GdkWindowClass parent_class;
67 };
68
69 G_DEFINE_TYPE (GdkWaylandWindow, _gdk_wayland_window, GDK_TYPE_WINDOW)
70
71 static void
72 _gdk_wayland_window_class_init (GdkWaylandWindowClass *wayland_window_class)
73 {
74 }
75
76 static void
77 _gdk_wayland_window_init (GdkWaylandWindow *wayland_window)
78 {
79 }
80
81 #define GDK_TYPE_WINDOW_IMPL_WAYLAND              (_gdk_window_impl_wayland_get_type ())
82 #define GDK_WINDOW_IMPL_WAYLAND(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WINDOW_IMPL_WAYLAND, GdkWindowImplWayland))
83 #define GDK_WINDOW_IMPL_WAYLAND_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WINDOW_IMPL_WAYLAND, GdkWindowImplWaylandClass))
84 #define GDK_IS_WINDOW_IMPL_WAYLAND(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WINDOW_IMPL_WAYLAND))
85 #define GDK_IS_WINDOW_IMPL_WAYLAND_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WINDOW_IMPL_WAYLAND))
86 #define GDK_WINDOW_IMPL_WAYLAND_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WINDOW_IMPL_WAYLAND, GdkWindowImplWaylandClass))
87
88 typedef struct _GdkWindowImplWayland GdkWindowImplWayland;
89 typedef struct _GdkWindowImplWaylandClass GdkWindowImplWaylandClass;
90
91 struct _GdkWindowImplWayland
92 {
93   GdkWindowImpl parent_instance;
94
95   GdkWindow *wrapper;
96
97   GdkCursor *cursor;
98
99   gint8 toplevel_window_type;
100
101   struct wl_surface *surface;
102   struct wl_shell_surface *shell_surface;
103   unsigned int mapped : 1;
104   GdkWindow *transient_for;
105   GdkWindowTypeHint hint;
106
107   /* The surface which is being "drawn to" to */
108   cairo_surface_t *cairo_surface;
109
110   /* The surface that was the last surface the Wayland buffer from which was attached
111    * to the Wayland surface. It will be the same as cairo_surface after a call
112    * to gdk_wayland_window_attach_image. But after a call to
113    * gdk_wayland_window_update_size and then
114    * gdk_wayland_window_ref_cairo_surface the above pointer will be different.
115    */
116   cairo_surface_t *server_surface;
117
118   uint32_t resize_edges;
119
120   int focus_count;
121
122   gulong map_serial;    /* Serial of last transition from unmapped */
123
124   cairo_surface_t *icon_pixmap;
125   cairo_surface_t *icon_mask;
126
127   /* Time of most recent user interaction. */
128   gulong user_time;
129
130   GdkGeometry geometry_hints;
131   GdkWindowHints geometry_mask;
132
133   struct wl_input_device *grab_input_device;
134   guint32 grab_time;
135 };
136
137 struct _GdkWindowImplWaylandClass
138 {
139   GdkWindowImplClass parent_class;
140 };
141
142 G_DEFINE_TYPE (GdkWindowImplWayland, _gdk_window_impl_wayland, GDK_TYPE_WINDOW_IMPL)
143
144 static void
145 _gdk_window_impl_wayland_init (GdkWindowImplWayland *impl)
146 {
147   impl->toplevel_window_type = -1;
148 }
149
150 void
151 _gdk_wayland_window_add_focus (GdkWindow *window)
152 {
153   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
154
155   impl->focus_count++;
156   if (impl->focus_count == 1)
157     gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FOCUSED);
158 }
159
160 void
161 _gdk_wayland_window_remove_focus (GdkWindow *window)
162 {
163   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
164
165   impl->focus_count--;
166   if (impl->focus_count == 0)
167     gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FOCUSED, 0);
168 }
169
170 /**
171  * gdk_wayland_window_update_size:
172  * @drawable: a #GdkDrawableImplWayland.
173  * 
174  * Updates the state of the drawable (in particular the drawable's
175  * cairo surface) when its size has changed.
176  **/
177 static void
178 gdk_wayland_window_update_size (GdkWindow *window,
179                                 int32_t width, int32_t height, uint32_t edges)
180 {
181   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
182   GdkRectangle area;
183   cairo_region_t *region;
184
185   if (impl->cairo_surface)
186     {
187       cairo_surface_destroy (impl->cairo_surface);
188       impl->cairo_surface = NULL;
189     }
190
191   window->width = width;
192   window->height = height;
193   impl->resize_edges = edges;
194
195   area.x = 0;
196   area.y = 0;
197   area.width = window->width;
198   area.height = window->height;
199
200   region = cairo_region_create_rectangle (&area);
201   _gdk_window_invalidate_for_expose (window, region);
202   cairo_region_destroy (region);
203 }
204
205 GdkWindow *
206 _gdk_wayland_screen_create_root_window (GdkScreen *screen,
207                                         int width, int height)
208 {
209   GdkWindow *window;
210   GdkWindowImplWayland *impl;
211
212   window = _gdk_display_create_window (gdk_screen_get_display (screen));
213   window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_WAYLAND, NULL);
214   window->impl_window = window;
215   window->visual = gdk_screen_get_system_visual (screen);
216
217   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
218
219   impl->wrapper = GDK_WINDOW (window);
220
221   window->window_type = GDK_WINDOW_ROOT;
222   window->depth = 32;
223
224   window->x = 0;
225   window->y = 0;
226   window->abs_x = 0;
227   window->abs_y = 0;
228   window->width = width;
229   window->height = height;
230   window->viewable = TRUE;
231
232   /* see init_randr_support() in gdkscreen-wayland.c */
233   window->event_mask = GDK_STRUCTURE_MASK;
234
235   return window;
236 }
237
238 static const gchar *
239 get_default_title (void)
240 {
241   const char *title;
242
243   title = g_get_application_name ();
244   if (!title)
245     title = g_get_prgname ();
246   if (!title)
247     title = "";
248
249   return title;
250 }
251
252 void
253 _gdk_wayland_display_create_window_impl (GdkDisplay    *display,
254                                          GdkWindow     *window,
255                                          GdkWindow     *real_parent,
256                                          GdkScreen     *screen,
257                                          GdkEventMask   event_mask,
258                                          GdkWindowAttr *attributes,
259                                          gint           attributes_mask)
260 {
261   GdkWindowImplWayland *impl;
262   const char *title;
263
264   impl = g_object_new (GDK_TYPE_WINDOW_IMPL_WAYLAND, NULL);
265   window->impl = GDK_WINDOW_IMPL (impl);
266   impl->wrapper = GDK_WINDOW (window);
267
268   if (window->width > 65535 ||
269       window->height > 65535)
270     {
271       g_warning ("Native Windows wider or taller than 65535 pixels are not supported");
272
273       if (window->width > 65535)
274         window->width = 65535;
275       if (window->height > 65535)
276         window->height = 65535;
277     }
278
279   g_object_ref (window);
280
281   switch (GDK_WINDOW_TYPE (window))
282     {
283     case GDK_WINDOW_TOPLEVEL:
284     case GDK_WINDOW_TEMP:
285       if (attributes_mask & GDK_WA_TITLE)
286         title = attributes->title;
287       else
288         title = get_default_title ();
289
290       gdk_window_set_title (window, title);
291       break;
292
293     case GDK_WINDOW_CHILD:
294     default:
295       break;
296     }
297
298   if (attributes_mask & GDK_WA_TYPE_HINT)
299     gdk_window_set_type_hint (window, attributes->type_hint);
300 }
301
302 static const cairo_user_data_key_t gdk_wayland_cairo_key;
303
304 typedef struct _GdkWaylandCairoSurfaceData {
305 #ifdef GDK_WAYLAND_USE_EGL
306   EGLImageKHR image;
307   GLuint texture;
308   struct wl_egl_pixmap *pixmap;
309 #else
310   gpointer buf;
311   size_t buf_length;
312 #endif
313   struct wl_buffer *buffer;
314   GdkWaylandDisplay *display;
315   int32_t width, height;
316 } GdkWaylandCairoSurfaceData;
317
318 static void
319 gdk_wayland_window_attach_image (GdkWindow *window)
320 {
321   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
322   GdkWaylandCairoSurfaceData *data;
323   int32_t server_width, server_height, dx, dy;
324
325   if (GDK_WINDOW_DESTROYED (window))
326     return;
327
328   /* The "drawn to" Cairo surface is the same as the Cairo surface from which
329    * we are driving the buffer for the Wayland surface. Therefore we don't
330    * need to do anything here
331    */
332   if (impl->server_surface == impl->cairo_surface)
333     return;
334
335   /* The wayland surface is attached to a buffer that is from the old "drawn
336    * to" surface. Unref the surface and restore the state.
337    */
338   if (impl->server_surface)
339     {
340       data = cairo_surface_get_user_data (impl->server_surface,
341                                           &gdk_wayland_cairo_key);
342
343       /* Save the old dimensions used for the surface */
344       server_width = data->width;
345       server_height = data->height;
346
347       cairo_surface_destroy (impl->server_surface);
348     }
349   else
350     {
351       server_width = 0;
352       server_height = 0;
353     }
354
355   /* Save the current "drawn to" surface for future calls into here */
356   impl->server_surface = cairo_surface_reference (impl->cairo_surface);
357
358   /* Get a Wayland buffer from this new surface */
359   data = cairo_surface_get_user_data (impl->cairo_surface,
360                                       &gdk_wayland_cairo_key);
361
362   if (impl->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT)
363     dx = server_width - data->width;
364   else
365     dx = 0;
366
367   if (impl->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP)
368     dy = server_height - data->height;
369   else
370     dy = 0;
371
372   /* Attach this new buffer to the surface */
373   wl_surface_attach (impl->surface, data->buffer, dx, dy);
374 }
375
376 #ifdef GDK_WAYLAND_USE_EGL
377 static void
378 gdk_wayland_cairo_surface_destroy (void *p)
379 {
380   GdkWaylandCairoSurfaceData *data = p;
381
382   data->display->destroy_image (data->display->egl_display, data->image);
383   cairo_device_acquire(data->display->cairo_device);
384   glDeleteTextures(1, &data->texture);
385   cairo_device_release(data->display->cairo_device);
386   if (data->buffer)
387     wl_buffer_destroy(data->buffer);
388   g_free(data);
389 }
390
391 static cairo_surface_t *
392 gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
393                                   int width, int height)
394 {
395   GdkWaylandCairoSurfaceData *data;
396   cairo_surface_t *surface;
397   cairo_status_t status;
398
399   data = g_new (GdkWaylandCairoSurfaceData, 1);
400   data->display = display;
401   data->buffer = NULL;
402   data->width = width;
403   data->height = height;
404   data->pixmap = wl_egl_pixmap_create(width, height, 0);
405   data->image =
406     display->create_image(display->egl_display, NULL, EGL_NATIVE_PIXMAP_KHR,
407                           (EGLClientBuffer) data->pixmap, NULL);
408
409   cairo_device_acquire(display->cairo_device);
410   glGenTextures(1, &data->texture);
411   glBindTexture(GL_TEXTURE_2D, data->texture);
412   display->image_target_texture_2d(GL_TEXTURE_2D, data->image);
413   cairo_device_release(display->cairo_device);
414
415   surface = cairo_gl_surface_create_for_texture(display->cairo_device,
416                                                 CAIRO_CONTENT_COLOR_ALPHA,
417                                                 data->texture, width, height);
418
419   cairo_surface_set_user_data (surface, &gdk_wayland_cairo_key,
420                                data, gdk_wayland_cairo_surface_destroy);
421
422   status = cairo_surface_status (surface);
423   if (status != CAIRO_STATUS_SUCCESS)
424     {
425       g_critical (G_STRLOC ": Unable to create Cairo GL surface: %s",
426                   cairo_status_to_string (status));
427
428     }
429
430   if (!data->buffer)
431     data->buffer =
432       wl_egl_pixmap_create_buffer(data->pixmap);
433
434   return surface;
435 }
436 #else
437 static struct wl_buffer *
438 create_shm_buffer (struct wl_shm  *shm,
439                    int             width,
440                    int             height,
441                    uint32_t        format,
442                    size_t         *buf_length,
443                    void          **data_out)
444 {
445   char filename[] = "/tmp/wayland-shm-XXXXXX";
446   struct wl_buffer *buffer;
447   int fd, size, stride;
448   void *data;
449
450   fd = mkstemp (filename);
451   if (fd < 0) {
452       g_critical (G_STRLOC ": Unable to create temporary file (%s): %s",
453                   filename, g_strerror (errno));
454       return NULL;
455   }
456   stride = width * 4;
457   size = stride * height;
458   if (ftruncate (fd, size) < 0) {
459       g_critical (G_STRLOC ": Truncating temporary file failed: %s",
460                   g_strerror (errno));
461       close(fd);
462       return NULL;
463   }
464
465   data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
466   unlink (filename);
467
468   if (data == MAP_FAILED) {
469       g_critical (G_STRLOC ": mmap'ping temporary file failed: %s",
470                   g_strerror (errno));
471       close(fd);
472       return NULL;
473   }
474
475   buffer = wl_shm_create_buffer (shm, fd,
476                                  width, height,
477                                  stride, format);
478
479   close (fd);
480
481   *data_out = data;
482   *buf_length = size;
483   return buffer;
484 }
485
486 static void
487 gdk_wayland_cairo_surface_destroy (void *p)
488 {
489   GdkWaylandCairoSurfaceData *data = p;
490
491   if (data->buffer)
492     wl_buffer_destroy (data->buffer);
493
494   munmap (data->buf, data->buf_length);
495   g_free (data);
496 }
497
498 static cairo_surface_t *
499 gdk_wayland_create_cairo_surface (GdkWaylandDisplay *display,
500                                   int width, int height)
501 {
502   GdkWaylandCairoSurfaceData *data;
503   cairo_surface_t *surface = NULL;
504   cairo_status_t status;
505
506   data = g_new (GdkWaylandCairoSurfaceData, 1);
507   data->display = display;
508   data->buffer = NULL;
509   data->width = width;
510   data->height = height;
511
512   data->buffer = create_shm_buffer (display->shm,
513                                     width,
514                                     height,
515                                     WL_SHM_FORMAT_ARGB8888,
516                                     &data->buf_length,
517                                     &data->buf);
518
519   surface = cairo_image_surface_create_for_data (data->buf,
520                                                  CAIRO_FORMAT_ARGB32,
521                                                  width,
522                                                  height,
523                                                  width * 4);
524
525   cairo_surface_set_user_data (surface, &gdk_wayland_cairo_key,
526                                data, gdk_wayland_cairo_surface_destroy);
527
528   status = cairo_surface_status (surface);
529   if (status != CAIRO_STATUS_SUCCESS)
530     {
531       g_critical (G_STRLOC ": Unable to create Cairo image surface: %s",
532                   cairo_status_to_string (status));
533     }
534
535   return surface;
536 }
537 #endif
538
539 /* On this first call this creates a double reference - the first reference
540  * is held by the GdkWindowImplWayland struct - since unlike other backends
541  * the Cairo surface is not just a cheap wrapper around some other backing.
542  * It is the buffer itself.
543  */
544 static cairo_surface_t *
545 gdk_wayland_window_ref_cairo_surface (GdkWindow *window)
546 {
547   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
548   GdkWaylandDisplay *display_wayland =
549     GDK_WAYLAND_DISPLAY (gdk_window_get_display (impl->wrapper));
550
551   if (GDK_WINDOW_DESTROYED (impl->wrapper))
552     return NULL;
553
554   if (!impl->cairo_surface)
555     {
556       impl->cairo_surface =
557         gdk_wayland_create_cairo_surface (display_wayland,
558                                       impl->wrapper->width,
559                                       impl->wrapper->height);
560     }
561
562   cairo_surface_reference (impl->cairo_surface);
563
564   return impl->cairo_surface;
565 }
566
567
568 static void
569 gdk_window_impl_wayland_finalize (GObject *object)
570 {
571   GdkWindowImplWayland *impl;
572
573   g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (object));
574
575   impl = GDK_WINDOW_IMPL_WAYLAND (object);
576
577   if (impl->cursor)
578     g_object_unref (impl->cursor);
579   if (impl->server_surface)
580     cairo_surface_destroy (impl->server_surface);
581
582   G_OBJECT_CLASS (_gdk_window_impl_wayland_parent_class)->finalize (object);
583 }
584
585 static void
586 gdk_wayland_window_configure (GdkWindow *window,
587                               int width, int height, int edges)
588 {
589   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
590   GdkDisplay *display;
591   GdkEvent *event;
592
593   display = gdk_window_get_display (window);
594
595   /* TODO: Only generate a configure event if width or height have actually
596    * changed?
597    */
598   event = gdk_event_new (GDK_CONFIGURE);
599   event->configure.window = window;
600   event->configure.send_event = FALSE;
601   event->configure.width = width;
602   event->configure.height = height;
603
604   _gdk_window_update_size (window);
605   gdk_wayland_window_update_size (window, width, height, edges);
606
607   g_object_ref(window);
608
609   _gdk_wayland_display_deliver_event (display, event);
610 }
611
612 static void
613 gdk_wayland_window_set_user_time (GdkWindow *window, guint32 user_time)
614 {
615 }
616
617 static void
618 gdk_wayland_window_map (GdkWindow *window)
619 {
620   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
621   GdkWindowImplWayland *parent;
622
623   if (!impl->mapped)
624     {
625       if (impl->transient_for)
626         {
627           parent = GDK_WINDOW_IMPL_WAYLAND (impl->transient_for->impl);
628
629           if (impl->hint & GDK_WINDOW_TYPE_HINT_POPUP_MENU ||
630               impl->hint & GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU ||
631               impl->hint & GDK_WINDOW_TYPE_HINT_COMBO)
632             {
633               /* Use the device that was used for the grab as the device for
634                * the popup window setup - so this relies on GTK+ taking the
635                * grab before showing the popup window.
636                */
637               wl_shell_surface_set_popup (impl->shell_surface,
638                                           parent->grab_input_device, parent->grab_time,
639                                           parent->shell_surface,
640                                           window->x, window->y, 0);
641             } else {
642                 wl_shell_surface_set_transient (impl->shell_surface, parent->shell_surface,
643                                                 window->x, window->y, 0);
644             }
645         }
646       else
647         {
648           wl_shell_surface_set_toplevel (impl->shell_surface);
649         }
650       impl->mapped = TRUE;
651     }
652 }
653
654 static void
655 shell_surface_handle_configure(void *data,
656                                struct wl_shell_surface *shell_surface,
657                                uint32_t time,
658                                uint32_t edges,
659                                int32_t width,
660                                int32_t height)
661 {
662   GdkWindow *window = GDK_WINDOW (data);
663   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
664
665   gdk_window_constrain_size (&impl->geometry_hints,
666                              impl->geometry_mask,
667                              width,
668                              height,
669                              &width,
670                              &height);
671
672   gdk_wayland_window_configure (window, width, height, edges);
673 }
674
675 static void
676 shell_surface_popup_done (void                    *data,
677                           struct wl_shell_surface *shell_surface)
678 {
679   GdkWindow *window = GDK_WINDOW (data);
680
681   /* When the popup is complete hide the window - this really relies on the
682    * fix in https://bugzilla.gnome.org/show_bug.cgi?id=670881 to work
683    * effectively.
684    */
685   gdk_window_hide (window);
686 }
687
688 static const struct wl_shell_surface_listener shell_surface_listener = {
689   shell_surface_handle_configure,
690   shell_surface_popup_done
691 };
692
693 static void
694 gdk_wayland_window_show (GdkWindow *window, gboolean already_mapped)
695 {
696   GdkDisplay *display;
697   GdkWaylandDisplay *display_wayland;
698   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
699   GdkEvent *event;
700
701   display = gdk_window_get_display (window);
702   display_wayland = GDK_WAYLAND_DISPLAY (display);
703
704   if (impl->user_time != 0 &&
705       display_wayland->user_time != 0 &&
706       XSERVER_TIME_IS_LATER (display_wayland->user_time, impl->user_time))
707     gdk_wayland_window_set_user_time (window, impl->user_time);
708
709   impl->surface = wl_compositor_create_surface(display_wayland->compositor);
710   wl_surface_set_user_data(impl->surface, window);
711
712   impl->shell_surface = wl_shell_get_shell_surface (display_wayland->shell,
713                                                     impl->surface);
714   wl_shell_surface_add_listener(impl->shell_surface,
715                                 &shell_surface_listener, window);
716
717   gdk_window_set_type_hint (window, impl->hint);  
718
719   _gdk_make_event (window, GDK_MAP, NULL, FALSE);
720   event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY, NULL, FALSE);
721   event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
722
723   if (impl->cairo_surface)
724     gdk_wayland_window_attach_image (window);
725 }
726
727 static void
728 gdk_wayland_window_hide (GdkWindow *window)
729 {
730   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
731
732   if (impl->surface)
733     {
734       wl_surface_destroy(impl->surface);
735       impl->surface = NULL;
736       cairo_surface_destroy(impl->server_surface);
737       impl->server_surface = NULL;
738       impl->mapped = FALSE;
739     }
740
741   _gdk_window_clear_update_area (window);
742 }
743
744 static void
745 gdk_window_wayland_withdraw (GdkWindow *window)
746 {
747   GdkWindowImplWayland *impl;
748
749   if (!window->destroyed)
750     {
751       if (GDK_WINDOW_IS_MAPPED (window))
752         gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_WITHDRAWN);
753
754       g_assert (!GDK_WINDOW_IS_MAPPED (window));
755
756       impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
757       if (impl->surface)
758         {
759           wl_surface_destroy(impl->surface);
760           impl->surface = NULL;
761           cairo_surface_destroy(impl->server_surface);
762           impl->server_surface = NULL;
763           impl->mapped = FALSE;
764         }
765     }
766 }
767
768 static void
769 gdk_window_wayland_set_events (GdkWindow    *window,
770                                GdkEventMask  event_mask)
771 {
772   GDK_WINDOW (window)->event_mask = event_mask;
773 }
774
775 static GdkEventMask
776 gdk_window_wayland_get_events (GdkWindow *window)
777 {
778   if (GDK_WINDOW_DESTROYED (window))
779     return 0;
780   else
781     return GDK_WINDOW (window)->event_mask;
782 }
783
784 static void
785 gdk_window_wayland_raise (GdkWindow *window)
786 {
787   /* FIXME: wl_shell_raise() */
788 }
789
790 static void
791 gdk_window_wayland_lower (GdkWindow *window)
792 {
793   /* FIXME: wl_shell_lower() */
794 }
795
796 static void
797 gdk_window_wayland_restack_under (GdkWindow *window,
798                               GList *native_siblings)
799 {
800 }
801
802 static void
803 gdk_window_wayland_restack_toplevel (GdkWindow *window,
804                                  GdkWindow *sibling,
805                                  gboolean   above)
806 {
807 }
808
809 static void
810 gdk_window_wayland_move_resize (GdkWindow *window,
811                                 gboolean   with_move,
812                                 gint       x,
813                                 gint       y,
814                                 gint       width,
815                                 gint       height)
816 {
817   window->x = x;
818   window->y = y;
819
820   /* If this function is called with width and height = -1 then that means
821    * just move the window - don't update its size
822    */
823   if (width > 0 && height > 0)
824     gdk_wayland_window_configure (window, width, height, 0);
825 }
826
827 static void
828 gdk_window_wayland_set_background (GdkWindow      *window,
829                                cairo_pattern_t *pattern)
830 {
831 }
832
833 static gboolean
834 gdk_window_wayland_reparent (GdkWindow *window,
835                              GdkWindow *new_parent,
836                              gint       x,
837                              gint       y)
838 {
839   return FALSE;
840 }
841
842 static void
843 gdk_window_wayland_set_device_cursor (GdkWindow *window,
844                                       GdkDevice *device,
845                                       GdkCursor *cursor)
846 {
847   g_return_if_fail (GDK_IS_WINDOW (window));
848   g_return_if_fail (GDK_IS_DEVICE (device));
849
850   if (!GDK_WINDOW_DESTROYED (window))
851     GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor);
852 }
853
854 static void
855 gdk_window_wayland_get_geometry (GdkWindow *window,
856                                  gint      *x,
857                                  gint      *y,
858                                  gint      *width,
859                                  gint      *height)
860 {
861   if (!GDK_WINDOW_DESTROYED (window))
862     {
863       if (x)
864         *x = window->x;
865       if (y)
866         *y = window->y;
867       if (width)
868         *width = window->width;
869       if (height)
870         *height = window->height;
871     }
872 }
873
874 static gint
875 gdk_window_wayland_get_root_coords (GdkWindow *window,
876                                 gint       x,
877                                 gint       y,
878                                 gint      *root_x,
879                                 gint      *root_y)
880 {
881   /* We can't do this. */
882   if (root_x)
883     *root_x = 0;
884   if (root_y)
885     *root_y = 0;
886
887   return 1;
888 }
889
890 static gboolean
891 gdk_window_wayland_get_device_state (GdkWindow       *window,
892                                      GdkDevice       *device,
893                                      gint            *x,
894                                      gint            *y,
895                                      GdkModifierType *mask)
896 {
897   gboolean return_val;
898
899   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE);
900
901   return_val = TRUE;
902
903   if (!GDK_WINDOW_DESTROYED (window))
904     {
905       GdkWindow *child;
906
907       GDK_DEVICE_GET_CLASS (device)->query_state (device, window,
908                                                   NULL, &child,
909                                                   NULL, NULL,
910                                                   x, y, mask);
911       return_val = (child != NULL);
912     }
913
914   return return_val;
915 }
916
917 static void
918 gdk_window_wayland_shape_combine_region (GdkWindow       *window,
919                                          const cairo_region_t *shape_region,
920                                          gint             offset_x,
921                                          gint             offset_y)
922 {
923 }
924
925 static void 
926 gdk_window_wayland_input_shape_combine_region (GdkWindow       *window,
927                                                const cairo_region_t *shape_region,
928                                                gint             offset_x,
929                                                gint             offset_y)
930 {
931 }
932
933 static gboolean
934 gdk_window_wayland_set_static_gravities (GdkWindow *window,
935                                          gboolean   use_static)
936 {
937   return TRUE;
938 }
939
940 static gboolean
941 gdk_wayland_window_queue_antiexpose (GdkWindow *window,
942                                      cairo_region_t *area)
943 {
944   return FALSE;
945 }
946
947 static void
948 gdk_wayland_window_translate (GdkWindow      *window,
949                               cairo_region_t *area,
950                               gint            dx,
951                               gint            dy)
952 {
953   _gdk_window_invalidate_for_expose (window, area);
954 }
955
956 static void
957 gdk_wayland_window_destroy (GdkWindow *window,
958                             gboolean   recursing,
959                             gboolean   foreign_destroy)
960 {
961   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
962
963   g_return_if_fail (GDK_IS_WINDOW (window));
964
965   if (impl->cairo_surface)
966     {
967       cairo_surface_finish (impl->cairo_surface);
968       cairo_surface_set_user_data (impl->cairo_surface, &gdk_wayland_cairo_key,
969                                    NULL, NULL);
970     }
971
972   if (!recursing && !foreign_destroy)
973     {
974       if (GDK_WINDOW_IMPL_WAYLAND (window->impl)->surface)
975         wl_surface_destroy(GDK_WINDOW_IMPL_WAYLAND (window->impl)->surface);
976         wl_shell_surface_destroy(GDK_WINDOW_IMPL_WAYLAND (window->impl)->shell_surface);
977     }
978 }
979
980 static void
981 gdk_window_wayland_destroy_foreign (GdkWindow *window)
982 {
983 }
984
985 static cairo_surface_t *
986 gdk_window_wayland_resize_cairo_surface (GdkWindow       *window,
987                                          cairo_surface_t *surface,
988                                          gint             width,
989                                          gint             height)
990 {
991   return surface;
992 }
993
994 static cairo_region_t *
995 gdk_wayland_window_get_shape (GdkWindow *window)
996 {
997   return NULL;
998 }
999
1000 static cairo_region_t *
1001 gdk_wayland_window_get_input_shape (GdkWindow *window)
1002 {
1003   return NULL;
1004 }
1005
1006 static void
1007 gdk_wayland_window_focus (GdkWindow *window,
1008                           guint32    timestamp)
1009 {
1010   /* FIXME: wl_shell_focus() */
1011 }
1012
1013 static void
1014 gdk_wayland_window_set_type_hint (GdkWindow        *window,
1015                                   GdkWindowTypeHint hint)
1016 {
1017   GdkWindowImplWayland *impl;
1018
1019   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1020
1021   if (GDK_WINDOW_DESTROYED (window))
1022     return;
1023
1024   impl->hint = hint;
1025
1026   switch (hint)
1027     {
1028     case GDK_WINDOW_TYPE_HINT_MENU:
1029     case GDK_WINDOW_TYPE_HINT_TOOLBAR:
1030     case GDK_WINDOW_TYPE_HINT_UTILITY:
1031     case GDK_WINDOW_TYPE_HINT_DOCK:
1032     case GDK_WINDOW_TYPE_HINT_DESKTOP:
1033     case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
1034     case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
1035     case GDK_WINDOW_TYPE_HINT_TOOLTIP:
1036     case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
1037     case GDK_WINDOW_TYPE_HINT_COMBO:
1038     case GDK_WINDOW_TYPE_HINT_DND:
1039       break;
1040     default:
1041       g_warning ("Unknown hint %d passed to gdk_window_set_type_hint", hint);
1042       /* Fall thru */
1043     case GDK_WINDOW_TYPE_HINT_DIALOG:
1044     case GDK_WINDOW_TYPE_HINT_NORMAL:
1045     case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
1046       if (impl->shell_surface)
1047         wl_shell_surface_set_toplevel (impl->shell_surface);
1048       break;
1049     }
1050 }
1051
1052 static GdkWindowTypeHint
1053 gdk_wayland_window_get_type_hint (GdkWindow *window)
1054 {
1055   return GDK_WINDOW_TYPE_HINT_NORMAL;
1056 }
1057
1058 void
1059 gdk_wayland_window_set_modal_hint (GdkWindow *window,
1060                                    gboolean   modal)
1061 {
1062 }
1063
1064 static void
1065 gdk_wayland_window_set_skip_taskbar_hint (GdkWindow *window,
1066                                           gboolean   skips_taskbar)
1067 {
1068 }
1069
1070 static void
1071 gdk_wayland_window_set_skip_pager_hint (GdkWindow *window,
1072                                         gboolean   skips_pager)
1073 {
1074 }
1075
1076 static void
1077 gdk_wayland_window_set_urgency_hint (GdkWindow *window,
1078                                      gboolean   urgent)
1079 {
1080 }
1081
1082 static void
1083 gdk_wayland_window_set_geometry_hints (GdkWindow         *window,
1084                                        const GdkGeometry *geometry,
1085                                        GdkWindowHints     geom_mask)
1086 {
1087   GdkWindowImplWayland *impl;
1088
1089   if (GDK_WINDOW_DESTROYED (window) ||
1090       !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1091     return;
1092
1093   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1094
1095   impl->geometry_hints = *geometry;
1096   impl->geometry_mask = geom_mask;
1097
1098   /*
1099    * GDK_HINT_POS
1100    * GDK_HINT_USER_POS
1101    * GDK_HINT_USER_SIZE
1102    * GDK_HINT_MIN_SIZE
1103    * GDK_HINT_MAX_SIZE
1104    * GDK_HINT_BASE_SIZE
1105    * GDK_HINT_RESIZE_INC
1106    * GDK_HINT_ASPECT
1107    * GDK_HINT_WIN_GRAVITY
1108    */
1109 }
1110
1111 static void
1112 gdk_wayland_window_set_title (GdkWindow   *window,
1113                               const gchar *title)
1114 {
1115   g_return_if_fail (title != NULL);
1116
1117   if (GDK_WINDOW_DESTROYED (window))
1118     return;
1119 }
1120
1121 static void
1122 gdk_wayland_window_set_role (GdkWindow   *window,
1123                              const gchar *role)
1124 {
1125 }
1126
1127 static void
1128 gdk_wayland_window_set_startup_id (GdkWindow   *window,
1129                                    const gchar *startup_id)
1130 {
1131 }
1132
1133 static void
1134 gdk_wayland_window_set_transient_for (GdkWindow *window,
1135                                       GdkWindow *parent)
1136 {
1137   GdkWindowImplWayland *impl;
1138
1139   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1140   impl->transient_for = parent;
1141 }
1142
1143 static void
1144 gdk_wayland_window_get_root_origin (GdkWindow *window,
1145                                    gint      *x,
1146                                    gint      *y)
1147 {
1148   if (x)
1149     *x = 0;
1150
1151   if (y)
1152     *y = 0;
1153 }
1154
1155 static void
1156 gdk_wayland_window_get_frame_extents (GdkWindow    *window,
1157                                       GdkRectangle *rect)
1158 {
1159   rect->x = window->x;
1160   rect->y = window->y;
1161   rect->width = window->width;
1162   rect->height = window->height;
1163 }
1164
1165 static void
1166 gdk_wayland_window_set_override_redirect (GdkWindow *window,
1167                                           gboolean override_redirect)
1168 {
1169 }
1170
1171 static void
1172 gdk_wayland_window_set_accept_focus (GdkWindow *window,
1173                                      gboolean accept_focus)
1174 {
1175 }
1176
1177 static void
1178 gdk_wayland_window_set_focus_on_map (GdkWindow *window,
1179                                      gboolean focus_on_map)
1180 {
1181   focus_on_map = focus_on_map != FALSE;
1182
1183   if (window->focus_on_map != focus_on_map)
1184     {
1185       window->focus_on_map = focus_on_map;
1186
1187       if ((!GDK_WINDOW_DESTROYED (window)) &&
1188           (!window->focus_on_map) &&
1189           WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1190         gdk_wayland_window_set_user_time (window, 0);
1191     }
1192 }
1193
1194 static void
1195 gdk_wayland_window_set_icon_list (GdkWindow *window,
1196                                   GList     *pixbufs)
1197 {
1198 }
1199
1200 static void
1201 gdk_wayland_window_set_icon_name (GdkWindow   *window,
1202                                   const gchar *name)
1203 {
1204   if (GDK_WINDOW_DESTROYED (window))
1205     return;
1206 }
1207
1208 static void
1209 gdk_wayland_window_iconify (GdkWindow *window)
1210 {
1211 }
1212
1213 static void
1214 gdk_wayland_window_deiconify (GdkWindow *window)
1215 {
1216   if (GDK_WINDOW_DESTROYED (window) ||
1217       !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1218     return;
1219
1220   if (GDK_WINDOW_IS_MAPPED (window))
1221     {  
1222       gdk_window_show (window);
1223     }
1224   else
1225     {
1226       /* Flip our client side flag, the real work happens on map. */
1227       gdk_synthesize_window_state (window, GDK_WINDOW_STATE_ICONIFIED, 0);
1228     }
1229 }
1230
1231 static void
1232 gdk_wayland_window_stick (GdkWindow *window)
1233 {
1234   if (GDK_WINDOW_DESTROYED (window))
1235     return;
1236 }
1237
1238 static void
1239 gdk_wayland_window_unstick (GdkWindow *window)
1240 {
1241   if (GDK_WINDOW_DESTROYED (window))
1242     return;
1243 }
1244
1245 static void
1246 gdk_wayland_window_maximize (GdkWindow *window)
1247 {
1248   if (GDK_WINDOW_DESTROYED (window))
1249     return;
1250 }
1251
1252 static void
1253 gdk_wayland_window_unmaximize (GdkWindow *window)
1254 {
1255   if (GDK_WINDOW_DESTROYED (window))
1256     return;
1257 }
1258
1259 static void
1260 gdk_wayland_window_fullscreen (GdkWindow *window)
1261 {
1262   if (GDK_WINDOW_DESTROYED (window))
1263     return;
1264 }
1265
1266 static void
1267 gdk_wayland_window_unfullscreen (GdkWindow *window)
1268 {
1269   if (GDK_WINDOW_DESTROYED (window))
1270     return;
1271 }
1272
1273 static void
1274 gdk_wayland_window_set_keep_above (GdkWindow *window,
1275                                    gboolean   setting)
1276 {
1277   g_return_if_fail (GDK_IS_WINDOW (window));
1278
1279   if (GDK_WINDOW_DESTROYED (window))
1280     return;
1281 }
1282
1283 static void
1284 gdk_wayland_window_set_keep_below (GdkWindow *window, gboolean setting)
1285 {
1286   g_return_if_fail (GDK_IS_WINDOW (window));
1287
1288   if (GDK_WINDOW_DESTROYED (window))
1289     return;
1290 }
1291
1292 static GdkWindow *
1293 gdk_wayland_window_get_group (GdkWindow *window)
1294 {
1295   if (GDK_WINDOW_DESTROYED (window) ||
1296       !WINDOW_IS_TOPLEVEL (window))
1297     return NULL;
1298
1299   return NULL;
1300 }
1301
1302 static void
1303 gdk_wayland_window_set_group (GdkWindow *window,
1304                               GdkWindow *leader)
1305 {
1306   g_return_if_fail (GDK_IS_WINDOW (window));
1307   g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
1308   g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader));
1309 }
1310
1311 static void
1312 gdk_wayland_window_set_decorations (GdkWindow      *window,
1313                                     GdkWMDecoration decorations)
1314 {
1315 }
1316
1317 static gboolean
1318 gdk_wayland_window_get_decorations (GdkWindow       *window,
1319                                     GdkWMDecoration *decorations)
1320 {
1321   return FALSE;
1322 }
1323
1324 static void
1325 gdk_wayland_window_set_functions (GdkWindow    *window,
1326                                   GdkWMFunction functions)
1327 {
1328 }
1329
1330 static void
1331 gdk_wayland_window_begin_resize_drag (GdkWindow     *window,
1332                                       GdkWindowEdge  edge,
1333                                       GdkDevice     *device,
1334                                       gint           button,
1335                                       gint           root_x,
1336                                       gint           root_y,
1337                                       guint32        timestamp)
1338 {
1339   GdkWindowImplWayland *impl;
1340   uint32_t grab_type;
1341
1342   if (GDK_WINDOW_DESTROYED (window) ||
1343       !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
1344     return;
1345
1346   switch (edge)
1347     {
1348     case GDK_WINDOW_EDGE_NORTH_WEST:
1349       grab_type = WL_SHELL_SURFACE_RESIZE_TOP_LEFT;
1350       break;
1351
1352     case GDK_WINDOW_EDGE_NORTH:
1353       grab_type = WL_SHELL_SURFACE_RESIZE_TOP;
1354       break;
1355
1356     case GDK_WINDOW_EDGE_NORTH_EAST:
1357       grab_type = WL_SHELL_SURFACE_RESIZE_RIGHT;
1358       break;
1359
1360     case GDK_WINDOW_EDGE_WEST:
1361       grab_type = WL_SHELL_SURFACE_RESIZE_LEFT;
1362       break;
1363
1364     case GDK_WINDOW_EDGE_EAST:
1365       grab_type = WL_SHELL_SURFACE_RESIZE_RIGHT;
1366       break;
1367
1368     case GDK_WINDOW_EDGE_SOUTH_WEST:
1369       grab_type = WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT;
1370       break;
1371
1372     case GDK_WINDOW_EDGE_SOUTH:
1373       grab_type = WL_SHELL_SURFACE_RESIZE_BOTTOM;
1374       break;
1375
1376     case GDK_WINDOW_EDGE_SOUTH_EAST:
1377       grab_type = WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT;
1378       break;
1379
1380     default:
1381       g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!",
1382                  edge);
1383       return;
1384     }
1385
1386   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1387
1388   wl_shell_surface_resize (impl->shell_surface,
1389                            _gdk_wayland_device_get_device (device),
1390                            timestamp, grab_type);
1391
1392   /* This is needed since Wayland will absorb all the pointer events after the
1393    * above function - FIXME: Is this always safe..?
1394    */
1395   gdk_device_ungrab (device, timestamp);
1396 }
1397
1398 static void
1399 gdk_wayland_window_begin_move_drag (GdkWindow *window,
1400                                     GdkDevice *device,
1401                                     gint       button,
1402                                     gint       root_x,
1403                                     gint       root_y,
1404                                     guint32    timestamp)
1405 {
1406   GdkWindowImplWayland *impl;
1407
1408   if (GDK_WINDOW_DESTROYED (window) ||
1409       !WINDOW_IS_TOPLEVEL (window))
1410     return;
1411
1412   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1413
1414   wl_shell_surface_move (impl->shell_surface,
1415                          _gdk_wayland_device_get_device (device), timestamp);
1416
1417   /* This is needed since Wayland will absorb all the pointer events after the
1418    * above function - FIXME: Is this always safe..?
1419    */
1420   gdk_device_ungrab (device, timestamp);
1421 }
1422
1423 static void
1424 gdk_wayland_window_enable_synchronized_configure (GdkWindow *window)
1425 {
1426 }
1427
1428 static void
1429 gdk_wayland_window_configure_finished (GdkWindow *window)
1430 {
1431   if (!WINDOW_IS_TOPLEVEL (window))
1432     return;
1433
1434   if (!GDK_IS_WINDOW_IMPL_WAYLAND (window->impl))
1435     return;
1436 }
1437
1438 static void
1439 gdk_wayland_window_set_opacity (GdkWindow *window,
1440                                 gdouble    opacity)
1441 {
1442 }
1443
1444 static void
1445 gdk_wayland_window_set_composited (GdkWindow *window,
1446                                    gboolean   composited)
1447 {
1448 }
1449
1450 static void
1451 gdk_wayland_window_destroy_notify (GdkWindow *window)
1452 {
1453   if (!GDK_WINDOW_DESTROYED (window))
1454     {
1455       if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
1456         g_warning ("GdkWindow %p unexpectedly destroyed", window);
1457
1458       _gdk_window_destroy (window, TRUE);
1459     }
1460
1461   g_object_unref (window);
1462 }
1463
1464 static void
1465 gdk_wayland_window_process_updates_recurse (GdkWindow      *window,
1466                                             cairo_region_t *region)
1467 {
1468   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1469 #ifndef GDK_WAYLAND_USE_EGL
1470   GdkWaylandCairoSurfaceData *data = NULL;
1471 #endif
1472   cairo_rectangle_int_t rect;
1473   int i, n;
1474
1475   gdk_wayland_window_map (window);
1476
1477   if (impl->cairo_surface)
1478     gdk_wayland_window_attach_image (window);
1479
1480 #ifndef GDK_WAYLAND_USE_EGL
1481   if (impl->server_surface)
1482     data = cairo_surface_get_user_data (impl->server_surface,
1483                                         &gdk_wayland_cairo_key);
1484 #endif
1485
1486   n = cairo_region_num_rectangles(region);
1487   for (i = 0; i < n; i++)
1488     {
1489       cairo_region_get_rectangle (region, i, &rect);
1490 #ifndef GDK_WAYLAND_USE_EGL
1491       if (data && data->buffer)
1492         wl_buffer_damage (data->buffer,
1493                           rect.x, rect.y, rect.width, rect.height);
1494 #endif
1495       wl_surface_damage (impl->surface,
1496                          rect.x, rect.y, rect.width, rect.height);
1497     }
1498
1499   _gdk_window_process_updates_recurse (window, region);
1500 }
1501
1502 static void
1503 gdk_wayland_window_sync_rendering (GdkWindow *window)
1504 {
1505 }
1506
1507 static gboolean
1508 gdk_wayland_window_simulate_key (GdkWindow      *window,
1509                                  gint            x,
1510                                  gint            y,
1511                                  guint           keyval,
1512                                  GdkModifierType modifiers,
1513                                  GdkEventType    key_pressrelease)
1514 {
1515   return FALSE;
1516 }
1517
1518 static gboolean
1519 gdk_wayland_window_simulate_button (GdkWindow      *window,
1520                                     gint            x,
1521                                     gint            y,
1522                                     guint           button, /*1..3*/
1523                                     GdkModifierType modifiers,
1524                                     GdkEventType    button_pressrelease)
1525 {
1526   return FALSE;
1527 }
1528
1529 static gboolean
1530 gdk_wayland_window_get_property (GdkWindow   *window,
1531                                  GdkAtom      property,
1532                                  GdkAtom      type,
1533                                  gulong       offset,
1534                                  gulong       length,
1535                                  gint         pdelete,
1536                                  GdkAtom     *actual_property_type,
1537                                  gint        *actual_format_type,
1538                                  gint        *actual_length,
1539                                  guchar     **data)
1540 {
1541   return FALSE;
1542 }
1543
1544 static void
1545 gdk_wayland_window_change_property (GdkWindow    *window,
1546                                     GdkAtom       property,
1547                                     GdkAtom       type,
1548                                     gint          format,
1549                                     GdkPropMode   mode,
1550                                     const guchar *data,
1551                                     gint          nelements)
1552 {
1553 }
1554
1555 static void
1556 gdk_wayland_window_delete_property (GdkWindow *window,
1557                                     GdkAtom    property)
1558 {
1559 }
1560
1561 static void
1562 _gdk_window_impl_wayland_class_init (GdkWindowImplWaylandClass *klass)
1563 {
1564   GObjectClass *object_class = G_OBJECT_CLASS (klass);
1565   GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass);
1566
1567   object_class->finalize = gdk_window_impl_wayland_finalize;
1568
1569   impl_class->ref_cairo_surface = gdk_wayland_window_ref_cairo_surface;
1570   impl_class->show = gdk_wayland_window_show;
1571   impl_class->hide = gdk_wayland_window_hide;
1572   impl_class->withdraw = gdk_window_wayland_withdraw;
1573   impl_class->set_events = gdk_window_wayland_set_events;
1574   impl_class->get_events = gdk_window_wayland_get_events;
1575   impl_class->raise = gdk_window_wayland_raise;
1576   impl_class->lower = gdk_window_wayland_lower;
1577   impl_class->restack_under = gdk_window_wayland_restack_under;
1578   impl_class->restack_toplevel = gdk_window_wayland_restack_toplevel;
1579   impl_class->move_resize = gdk_window_wayland_move_resize;
1580   impl_class->set_background = gdk_window_wayland_set_background;
1581   impl_class->reparent = gdk_window_wayland_reparent;
1582   impl_class->set_device_cursor = gdk_window_wayland_set_device_cursor;
1583   impl_class->get_geometry = gdk_window_wayland_get_geometry;
1584   impl_class->get_root_coords = gdk_window_wayland_get_root_coords;
1585   impl_class->get_device_state = gdk_window_wayland_get_device_state;
1586   impl_class->shape_combine_region = gdk_window_wayland_shape_combine_region;
1587   impl_class->input_shape_combine_region = gdk_window_wayland_input_shape_combine_region;
1588   impl_class->set_static_gravities = gdk_window_wayland_set_static_gravities;
1589   impl_class->queue_antiexpose = gdk_wayland_window_queue_antiexpose;
1590   impl_class->translate = gdk_wayland_window_translate;
1591   impl_class->destroy = gdk_wayland_window_destroy;
1592   impl_class->destroy_foreign = gdk_window_wayland_destroy_foreign;
1593   impl_class->resize_cairo_surface = gdk_window_wayland_resize_cairo_surface;
1594   impl_class->get_shape = gdk_wayland_window_get_shape;
1595   impl_class->get_input_shape = gdk_wayland_window_get_input_shape;
1596   /* impl_class->beep */
1597
1598   impl_class->focus = gdk_wayland_window_focus;
1599   impl_class->set_type_hint = gdk_wayland_window_set_type_hint;
1600   impl_class->get_type_hint = gdk_wayland_window_get_type_hint;
1601   impl_class->set_modal_hint = gdk_wayland_window_set_modal_hint;
1602   impl_class->set_skip_taskbar_hint = gdk_wayland_window_set_skip_taskbar_hint;
1603   impl_class->set_skip_pager_hint = gdk_wayland_window_set_skip_pager_hint;
1604   impl_class->set_urgency_hint = gdk_wayland_window_set_urgency_hint;
1605   impl_class->set_geometry_hints = gdk_wayland_window_set_geometry_hints;
1606   impl_class->set_title = gdk_wayland_window_set_title;
1607   impl_class->set_role = gdk_wayland_window_set_role;
1608   impl_class->set_startup_id = gdk_wayland_window_set_startup_id;
1609   impl_class->set_transient_for = gdk_wayland_window_set_transient_for;
1610   impl_class->get_root_origin = gdk_wayland_window_get_root_origin;
1611   impl_class->get_frame_extents = gdk_wayland_window_get_frame_extents;
1612   impl_class->set_override_redirect = gdk_wayland_window_set_override_redirect;
1613   impl_class->set_accept_focus = gdk_wayland_window_set_accept_focus;
1614   impl_class->set_focus_on_map = gdk_wayland_window_set_focus_on_map;
1615   impl_class->set_icon_list = gdk_wayland_window_set_icon_list;
1616   impl_class->set_icon_name = gdk_wayland_window_set_icon_name;
1617   impl_class->iconify = gdk_wayland_window_iconify;
1618   impl_class->deiconify = gdk_wayland_window_deiconify;
1619   impl_class->stick = gdk_wayland_window_stick;
1620   impl_class->unstick = gdk_wayland_window_unstick;
1621   impl_class->maximize = gdk_wayland_window_maximize;
1622   impl_class->unmaximize = gdk_wayland_window_unmaximize;
1623   impl_class->fullscreen = gdk_wayland_window_fullscreen;
1624   impl_class->unfullscreen = gdk_wayland_window_unfullscreen;
1625   impl_class->set_keep_above = gdk_wayland_window_set_keep_above;
1626   impl_class->set_keep_below = gdk_wayland_window_set_keep_below;
1627   impl_class->get_group = gdk_wayland_window_get_group;
1628   impl_class->set_group = gdk_wayland_window_set_group;
1629   impl_class->set_decorations = gdk_wayland_window_set_decorations;
1630   impl_class->get_decorations = gdk_wayland_window_get_decorations;
1631   impl_class->set_functions = gdk_wayland_window_set_functions;
1632   impl_class->begin_resize_drag = gdk_wayland_window_begin_resize_drag;
1633   impl_class->begin_move_drag = gdk_wayland_window_begin_move_drag;
1634   impl_class->enable_synchronized_configure = gdk_wayland_window_enable_synchronized_configure;
1635   impl_class->configure_finished = gdk_wayland_window_configure_finished;
1636   impl_class->set_opacity = gdk_wayland_window_set_opacity;
1637   impl_class->set_composited = gdk_wayland_window_set_composited;
1638   impl_class->destroy_notify = gdk_wayland_window_destroy_notify;
1639   impl_class->get_drag_protocol = _gdk_wayland_window_get_drag_protocol;
1640   impl_class->register_dnd = _gdk_wayland_window_register_dnd;
1641   impl_class->drag_begin = _gdk_wayland_window_drag_begin;
1642   impl_class->process_updates_recurse = gdk_wayland_window_process_updates_recurse;
1643   impl_class->sync_rendering = gdk_wayland_window_sync_rendering;
1644   impl_class->simulate_key = gdk_wayland_window_simulate_key;
1645   impl_class->simulate_button = gdk_wayland_window_simulate_button;
1646   impl_class->get_property = gdk_wayland_window_get_property;
1647   impl_class->change_property = gdk_wayland_window_change_property;
1648   impl_class->delete_property = gdk_wayland_window_delete_property;
1649 }
1650
1651
1652 void
1653 _gdk_wayland_window_set_device_grabbed (GdkWindow              *window,
1654                                         struct wl_input_device *input_device,
1655                                         guint32                 time_)
1656 {
1657   GdkWindowImplWayland *impl;
1658
1659   g_return_if_fail (window != NULL);
1660
1661   impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
1662
1663   impl->grab_input_device = input_device;
1664   impl->grab_time = time_;
1665 }