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