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