[gtk/wip/matthiasc/popup5: 14/152] Introduce GtkNative



commit e3733d2bfe1841d8e25cfc5ba7d5db1a52fa65a4
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Apr 29 05:36:15 2019 +0000

    Introduce GtkNative
    
    Split off the parts of GtkRoot that are specific
    to widgets having a surface into the GtkNative
    interface, leaving just the parts that are about
    being a toplevel in GtkRoot.

 gtk/gtk.h              |   1 +
 gtk/gtknative.c        | 142 +++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtknative.h        |  72 +++++++++++++++++++++++++
 gtk/gtknativeprivate.h |  14 +++++
 gtk/gtkroot.c          |  64 ----------------------
 gtk/gtkroot.h          |  10 +---
 gtk/gtkrootprivate.h   |   6 +--
 gtk/meson.build        |   1 +
 8 files changed, 232 insertions(+), 78 deletions(-)
---
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 477cf4e496..651e8d6614 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -161,6 +161,7 @@
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkmodelbutton.h>
 #include <gtk/gtkmountoperation.h>
+#include <gtk/gtknative.h>
 #include <gtk/gtknativedialog.h>
 #include <gtk/gtknotebook.h>
 #include <gtk/gtkorientable.h>
diff --git a/gtk/gtknative.c b/gtk/gtknative.c
new file mode 100644
index 0000000000..4f5feb0593
--- /dev/null
+++ b/gtk/gtknative.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "config.h"
+
+#include "gtknativeprivate.h"
+#include "gtkcssnodeprivate.h"
+#include "gtkwidgetprivate.h"
+#include "gdk/gdk-private.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+
+/**
+ * SECTION:gtknative
+ * @Title: GtkNative
+ * @Short_description: Interface for widgets having surfaces
+ * @See_also: #GtkRoot
+ *
+ * #GtkNative is the interface implemented by all widgets that can provide
+ * a GdkSurface for widgets to render on.
+ *
+ * The obvious example of a #GtkNative is #GtkWindow.
+ */
+
+G_DEFINE_INTERFACE (GtkNative, gtk_native, GTK_TYPE_WIDGET)
+
+static GskRenderer *
+gtk_native_default_get_renderer (GtkNative *self)
+{
+  return NULL;
+}
+
+static void
+gtk_native_default_get_surface_transform (GtkNative *self,
+                                       int    *x,
+                                       int    *y)
+{
+  *x = 0;
+  *y = 0;
+}
+
+static void
+gtk_native_default_check_resize (GtkNative *self)
+{
+}
+
+static void
+gtk_native_default_init (GtkNativeInterface *iface)
+{
+  iface->get_renderer = gtk_native_default_get_renderer;
+  iface->get_surface_transform = gtk_native_default_get_surface_transform;
+  iface->check_resize = gtk_native_default_check_resize;
+}
+
+/**
+ * gtk_native_get_surface:
+ * @self: a #GtkNative
+ *
+ * Returns the surface of this #GtkNative.
+ *
+ * Returns: the surface of @self
+ */
+GdkSurface *
+gtk_native_get_surface (GtkNative *self)
+{
+  g_return_val_if_fail (GTK_IS_NATIVE (self), NULL);
+
+  return GTK_NATIVE_GET_IFACE (self)->get_surface (self);
+}
+
+/**
+ * gtk_native_get_renderer:
+ * @self: a #GtkNative
+ *
+ * Returns the renderer that is used for this #GtkNative.
+ *
+ * Returns: the renderer for @self
+ */
+GskRenderer *
+gtk_native_get_renderer (GtkNative *self)
+{
+  g_return_val_if_fail (GTK_IS_NATIVE (self), NULL);
+
+  return GTK_NATIVE_GET_IFACE (self)->get_renderer (self);
+}
+
+void
+gtk_native_get_surface_transform (GtkNative *self,
+                               int    *x,
+                               int    *y)
+{
+  g_return_if_fail (GTK_IS_NATIVE (self));
+  g_return_if_fail (x != 0);
+  g_return_if_fail (y != 0);
+
+  return GTK_NATIVE_GET_IFACE (self)->get_surface_transform (self, x, y);
+}
+
+void
+gtk_native_check_resize (GtkNative *self)
+{
+  g_return_if_fail (GTK_IS_NATIVE (self));
+
+  GTK_NATIVE_GET_IFACE (self)->check_resize (self);
+}
+
+/**
+ * gtk_native_get_for_surface:
+ * @surface: a #GdkSurface
+ *
+ * Finds the GtkNative associated with the surface.
+ *
+ * Returns: (transfer none): the #GtkNative that is associated with @surface
+ */
+GtkWidget *
+gtk_native_get_for_surface (GdkSurface *surface)
+{
+  GtkWidget *widget;
+
+  widget = (GtkWidget *)gdk_surface_get_widget (surface);
+
+  if (widget && GTK_IS_NATIVE (widget))
+    return widget;
+
+  return NULL;
+}
diff --git a/gtk/gtknative.h b/gtk/gtknative.h
new file mode 100644
index 0000000000..bca65089e3
--- /dev/null
+++ b/gtk/gtknative.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef __GTK_NATIVE_H__
+#define __GTK_NATIVE_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gdk/gdk.h>
+#include <gtk/gtkwidget.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_NATIVE               (gtk_native_get_type ())
+
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_INTERFACE (GtkNative, gtk_native, GTK, NATIVE, GtkWidget)
+
+/**
+ * GtkNativeIface:
+ *
+ * The list of functions that must be implemented for the #GtkNative interface.
+ */
+struct _GtkNativeInterface
+{
+  /*< private >*/
+  GTypeInterface g_iface;
+
+  /*< public >*/
+  GdkSurface *  (* get_surface)           (GtkNative    *self);
+  GskRenderer * (* get_renderer)          (GtkNative    *self);
+
+  void          (* get_surface_transform) (GtkNative    *self,
+                                           int          *x,
+                                           int          *y);
+
+  void          (* check_resize)          (GtkNative    *self);
+};
+
+GDK_AVAILABLE_IN_ALL
+GtkWidget * gtk_native_get_for_surface (GdkSurface *surface);
+
+GDK_AVAILABLE_IN_ALL
+void        gtk_native_check_resize    (GtkNative *self);
+
+GDK_AVAILABLE_IN_ALL
+GdkSurface *gtk_native_get_surface     (GtkNative *self);
+
+GDK_AVAILABLE_IN_ALL
+GskRenderer *gtk_native_get_renderer   (GtkNative *self);
+
+G_END_DECLS
+
+#endif /* __GTK_NATIVE_H__ */
diff --git a/gtk/gtknativeprivate.h b/gtk/gtknativeprivate.h
new file mode 100644
index 0000000000..c6b62bd67b
--- /dev/null
+++ b/gtk/gtknativeprivate.h
@@ -0,0 +1,14 @@
+#ifndef __GTK_NATIVE_PRIVATE_H__
+#define __GTK_NATIVE_PRIVATE_H__
+
+#include "gtknative.h"
+
+G_BEGIN_DECLS
+
+void          gtk_native_get_surface_transform (GtkNative *self,
+                                                int       *x,
+                                                int       *y);
+
+G_END_DECLS
+
+#endif /* __GTK_NATIVE_PRIVATE_H__ */
diff --git a/gtk/gtkroot.c b/gtk/gtkroot.c
index 249d7405b1..a02b17f121 100644
--- a/gtk/gtkroot.c
+++ b/gtk/gtkroot.c
@@ -46,27 +46,10 @@ gtk_root_default_get_display (GtkRoot *self)
   return gdk_display_get_default ();
 }
 
-static GskRenderer *
-gtk_root_default_get_renderer (GtkRoot *self)
-{
-  return NULL;
-}
-
-static void
-gtk_root_default_get_surface_transform (GtkRoot *self,
-                                        int     *x,
-                                        int     *y)
-{
-  *x = 0;
-  *y = 0;
-}
-
 static void
 gtk_root_default_init (GtkRootInterface *iface)
 {
   iface->get_display = gtk_root_default_get_display;
-  iface->get_renderer = gtk_root_default_get_renderer;
-  iface->get_surface_transform = gtk_root_default_get_surface_transform;
 
   g_object_interface_install_property (iface,
       g_param_spec_object ("focus-widget",
@@ -87,53 +70,6 @@ gtk_root_get_display (GtkRoot *self)
   return iface->get_display (self);
 }
 
-GskRenderer *
-gtk_root_get_renderer (GtkRoot *self)
-{
-  GtkRootInterface *iface;
-
-  g_return_val_if_fail (GTK_IS_ROOT (self), NULL);
-
-  iface = GTK_ROOT_GET_IFACE (self);
-  return iface->get_renderer (self);
-}
-
-void
-gtk_root_get_surface_transform (GtkRoot *self,
-                                int     *x,
-                                int     *y)
-{
-  GtkRootInterface *iface;
-
-  g_return_if_fail (GTK_IS_ROOT (self));
-  g_return_if_fail (x != 0);
-  g_return_if_fail (y != 0);
-
-  iface = GTK_ROOT_GET_IFACE (self);
-  return iface->get_surface_transform (self, x, y);
-}
-
-/**
- * gtk_root_get_for_surface:
- * @surface: a #GdkSurface
- *
- * Finds the GtkRoot associated with the surface.
- * 
- * Returns: (transfer none): the #GtkRoot that is associated with @surface
- */
-GtkWidget *
-gtk_root_get_for_surface (GdkSurface *surface)
-{
-  GtkWidget *widget;
-
-  widget = (GtkWidget *)gdk_surface_get_widget (surface);
-
-  if (widget && GTK_IS_ROOT (widget))
-    return widget;
-
-  return NULL;
-}
-
 /**
  * gtk_root_set_focus:
  * @self: a #GtkRoot
diff --git a/gtk/gtkroot.h b/gtk/gtkroot.h
index 4c7ae89e37..3136a00911 100644
--- a/gtk/gtkroot.h
+++ b/gtk/gtkroot.h
@@ -45,17 +45,9 @@ struct _GtkRootInterface
   GTypeInterface g_iface;
 
   /*< public >*/
-  GdkDisplay *          (* get_display)                 (GtkRoot                *self);
-  GskRenderer *         (* get_renderer)                (GtkRoot                *self);
-
-  void                  (* get_surface_transform)       (GtkRoot                *root,
-                                                         int                    *x,
-                                                         int                    *y);
+  GdkDisplay * (* get_display)  (GtkRoot *self);
 };
 
-GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_root_get_for_surface (GdkSurface *surface);
-
 GDK_AVAILABLE_IN_ALL
 void        gtk_root_set_focus (GtkRoot   *self,
                                 GtkWidget *focus);
diff --git a/gtk/gtkrootprivate.h b/gtk/gtkrootprivate.h
index 357bc6441f..ddf4fb01ef 100644
--- a/gtk/gtkrootprivate.h
+++ b/gtk/gtkrootprivate.h
@@ -5,12 +5,8 @@
 
 G_BEGIN_DECLS
 
-GdkDisplay *            gtk_root_get_display            (GtkRoot                *root);
-GskRenderer *           gtk_root_get_renderer           (GtkRoot                *self);
+GdkDisplay * gtk_root_get_display (GtkRoot *root);
 
-void                    gtk_root_get_surface_transform  (GtkRoot                *self,
-                                                         int                    *x,
-                                                         int                    *y);
 enum {
   GTK_ROOT_PROP_FOCUS_WIDGET,
   GTK_ROOT_NUM_PROPERTIES
diff --git a/gtk/meson.build b/gtk/meson.build
index 1075ccf725..bfb72d0db4 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -316,6 +316,7 @@ gtk_public_sources = files([
   'gtkrendernodepaintable.c',
   'gtkrevealer.c',
   'gtkroot.c',
+  'gtknative.c',
   'gtkroundedbox.c',
   'gtkscale.c',
   'gtkscalebutton.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]