Bug 1337369 - [Wayland] query wayland registry to get wl_subcompositor for mozcontainer, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Tue, 24 Oct 2017 14:06:29 +0200
changeset 389302 b63c7bc7b0b1517e1ea872edc361a6a1861edd59
parent 389301 51c759b72e9a172eae173f52fc7f7fc4b6a6b631
child 389303 8afcd32835fc90305ded730468b91c7c9a57255c
push id32784
push userarchaeopteryx@coole-files.de
push dateTue, 31 Oct 2017 23:34:29 +0000
treeherdermozilla-central@ae1d655ea7c7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1337369
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1337369 - [Wayland] query wayland registry to get wl_subcompositor for mozcontainer, r=jhorak MozReview-Commit-ID: E04hqpFKFhk
widget/gtk/mozcontainer.cpp
widget/gtk/mozcontainer.h
--- a/widget/gtk/mozcontainer.cpp
+++ b/widget/gtk/mozcontainer.cpp
@@ -2,16 +2,20 @@
 /* vim:expandtab:shiftwidth=4:tabstop=4:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozcontainer.h"
 #include <gtk/gtk.h>
+#ifdef MOZ_WAYLAND
+#include <gdk/gdkx.h>
+#include <gdk/gdkwayland.h>
+#endif
 #include <stdio.h>
 
 #ifdef ACCESSIBILITY
 #include <atk/atk.h>
 #include "maiRedundantObjectFactory.h"
 #endif 
 
 /* init methods */
@@ -157,22 +161,66 @@ moz_container_class_init (MozContainerCl
     widget_class->realize = moz_container_realize;
     widget_class->size_allocate = moz_container_size_allocate;
 
     container_class->remove = moz_container_remove;
     container_class->forall = moz_container_forall;
     container_class->add = moz_container_add;
 }
 
+#if defined(MOZ_WAYLAND)
+static void
+registry_handle_global (void *data,
+                        struct wl_registry *registry,
+                        uint32_t name,
+                        const char *interface,
+                        uint32_t version)
+{
+    MozContainer *container = MOZ_CONTAINER(data);
+    if(strcmp(interface, "wl_subcompositor") == 0) {
+        container->subcompositor =
+            static_cast<wl_subcompositor*>(wl_registry_bind(registry,
+                                           name,
+                                           &wl_subcompositor_interface,
+                                           1));
+    }
+}
+
+static void
+registry_handle_global_remove (void *data,
+                               struct wl_registry *registry,
+                               uint32_t name)
+{
+}
+
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    registry_handle_global_remove
+};
+#endif
+
 void
 moz_container_init (MozContainer *container)
 {
     gtk_widget_set_can_focus(GTK_WIDGET(container), TRUE);
     gtk_container_set_resize_mode(GTK_CONTAINER(container), GTK_RESIZE_IMMEDIATE);
     gtk_widget_set_redraw_on_allocate(GTK_WIDGET(container), FALSE);
+
+#if defined(MOZ_WAYLAND)
+    {
+      GdkDisplay *gdk_display = gtk_widget_get_display(GTK_WIDGET(container));
+      if (GDK_IS_WAYLAND_DISPLAY (gdk_display)) {
+          wl_display* display = gdk_wayland_display_get_wl_display(gdk_display);
+          wl_registry* registry = wl_display_get_registry(display);
+          wl_registry_add_listener(registry, &registry_listener, container);
+          wl_display_dispatch(display);
+          wl_display_roundtrip(display);
+        }
+    }
+#endif
 }
 
 void
 moz_container_map (GtkWidget *widget)
 {
     MozContainer *container;
     GList *tmp_list;
     GtkWidget *tmp_child;
--- a/widget/gtk/mozcontainer.h
+++ b/widget/gtk/mozcontainer.h
@@ -8,21 +8,24 @@
 #ifndef __MOZ_CONTAINER_H__
 #define __MOZ_CONTAINER_H__
 
 #include <gtk/gtk.h>
 
 /*
  * MozContainer
  *
- * This class serves two purposes in the nsIWidget implementation.
+ * This class serves three purposes in the nsIWidget implementation.
  *
  *   - It provides objects to receive signals from GTK for events on native
  *     windows.
  *
+ *   - It provides GdkWindow to draw content on Wayland or when Gtk+ renders
+ *     client side decorations to mShell.
+ *
  *   - It provides a container parent for GtkWidgets.  The only GtkWidgets
  *     that need this in Mozilla are the GtkSockets for windowed plugins (Xt
  *     and XEmbed).
  *
  * Note that the window hierarchy in Mozilla differs from conventional
  * GtkWidget hierarchies.
  *
  * Mozilla's hierarchy exists through the GdkWindow hierarchy, and all child
@@ -46,20 +49,35 @@
 #define MOZ_CONTAINER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), MOZ_CONTAINER_TYPE, MozContainerClass))
 #define IS_MOZ_CONTAINER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOZ_CONTAINER_TYPE))
 #define IS_MOZ_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZ_CONTAINER_TYPE))
 #define MOZ_CONTAINER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZ_CONTAINER_TYPE, MozContainerClass))
 
 typedef struct _MozContainer      MozContainer;
 typedef struct _MozContainerClass MozContainerClass;
 
+/* Workaround for bug at wayland-util.h,
+ * present in wayland-devel < 1.12
+ */
+#ifdef MOZ_WAYLAND
+struct wl_subcompositor;
+struct wl_surface;
+struct wl_subsurface;
+#endif
+
 struct _MozContainer
 {
     GtkContainer   container;
     GList         *children;
+
+#ifdef MOZ_WAYLAND
+    struct wl_subcompositor *subcompositor;
+    struct wl_surface       *surface;
+    struct wl_subsurface    *subsurface;
+#endif
 };
 
 struct _MozContainerClass
 {
     GtkContainerClass parent_class;
 };
 
 GType      moz_container_get_type (void);