[gtk/wip/otte/boxes: 45/52] root: Add GtkRoot:get_display vfunc



commit 2fbdd8b849b97ed8a5d3b6f69c065577efb2fb38
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jul 29 04:11:14 2018 +0200

    root: Add GtkRoot:get_display vfunc
    
    And use it.

 gtk/gtkinvisible.c        | 25 +++++++++----------------
 gtk/gtkinvisibleprivate.h |  2 --
 gtk/gtkroot.c             | 20 +++++++++++++++++++-
 gtk/gtkroot.h             |  1 +
 gtk/gtkrootprivate.h      | 12 ++++++++++++
 gtk/gtkwidgetprivate.h    | 15 +++++----------
 gtk/gtkwindow.c           | 18 ++++++++++--------
 gtk/gtkwindowprivate.h    |  2 --
 8 files changed, 56 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkinvisible.c b/gtk/gtkinvisible.c
index 910b406376..9b66f3a9c8 100644
--- a/gtk/gtkinvisible.c
+++ b/gtk/gtkinvisible.c
@@ -71,9 +71,18 @@ static void gtk_invisible_get_property  (GObject           *object,
                                         GParamSpec        *pspec);
 static void gtk_invisible_constructed   (GObject           *object);
 
+static GdkDisplay *
+gtk_invisible_root_get_display (GtkRoot *root)
+{
+  GtkInvisible *invisible = GTK_INVISIBLE (root);
+
+  return invisible->priv->display;
+}
+
 static void
 gtk_invisible_root_interface_init (GtkRootInterface *iface)
 {
+  iface->get_display = gtk_invisible_root_get_display;
 }
 
 G_DEFINE_TYPE_WITH_CODE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET,
@@ -210,22 +219,6 @@ gtk_invisible_set_display (GtkInvisible *invisible,
     gtk_widget_realize (widget);
 }
 
-/**
- * gtk_invisible_get_display:
- * @invisible: a #GtkInvisible.
- *
- * Returns the #GdkDisplay object associated with @invisible
- *
- * Returns: (transfer none): the associated #GdkDisplay.
- **/
-GdkDisplay *
-gtk_invisible_get_display (GtkInvisible *invisible)
-{
-  g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
-
-  return invisible->priv->display;
-}
-
 static void
 gtk_invisible_realize (GtkWidget *widget)
 {
diff --git a/gtk/gtkinvisibleprivate.h b/gtk/gtkinvisibleprivate.h
index f625a35684..c65053bca0 100644
--- a/gtk/gtkinvisibleprivate.h
+++ b/gtk/gtkinvisibleprivate.h
@@ -74,8 +74,6 @@ GtkWidget* gtk_invisible_new_for_display(GdkDisplay   *display);
 GDK_AVAILABLE_IN_ALL
 void      gtk_invisible_set_display    (GtkInvisible *invisible,
                                         GdkDisplay   *display);
-GDK_AVAILABLE_IN_ALL
-GdkDisplay*gtk_invisible_get_display   (GtkInvisible *invisible);
 
 G_END_DECLS
 
diff --git a/gtk/gtkroot.c b/gtk/gtkroot.c
index 3eecc97ec6..23674e48a1 100644
--- a/gtk/gtkroot.c
+++ b/gtk/gtkroot.c
@@ -19,7 +19,7 @@
 
 #include "config.h"
 
-#include "gtkroot.h"
+#include "gtkrootprivate.h"
 
 /**
  * SECTION:root
@@ -37,8 +37,26 @@
 
 G_DEFINE_INTERFACE (GtkRoot, gtk_root, GTK_TYPE_WIDGET)
 
+static GdkDisplay *
+gtk_root_default_get_display (GtkRoot *self)
+{
+  return gdk_display_get_default ();
+}
+
 static void
 gtk_root_default_init (GtkRootInterface *iface)
 {
+  iface->get_display = gtk_root_default_get_display;
+}
+
+GdkDisplay *
+gtk_root_get_display (GtkRoot *self)
+{
+  GtkRootInterface *iface;
+
+  g_return_val_if_fail (GTK_IS_ROOT (self), NULL);
+
+  iface = GTK_ROOT_GET_IFACE (self);
+  return iface->get_display (self);
 }
 
diff --git a/gtk/gtkroot.h b/gtk/gtkroot.h
index e4894ee46b..e1d7ee670d 100644
--- a/gtk/gtkroot.h
+++ b/gtk/gtkroot.h
@@ -45,6 +45,7 @@ struct _GtkRootInterface
   GTypeInterface g_iface;
 
   /*< public >*/
+  GdkDisplay *          (* get_display)                 (GtkRoot                *self);
 };
 
 
diff --git a/gtk/gtkrootprivate.h b/gtk/gtkrootprivate.h
new file mode 100644
index 0000000000..6d633cf2bc
--- /dev/null
+++ b/gtk/gtkrootprivate.h
@@ -0,0 +1,12 @@
+#ifndef __GTK_ROOT_PRIVATE_H__
+#define __GTK_ROOT_PRIVATE_H__
+
+#include "gtkroot.h"
+
+G_BEGIN_DECLS
+
+GdkDisplay *            gtk_root_get_display            (GtkRoot                *root);
+
+G_END_DECLS
+
+#endif /* __GTK_ROOT_PRIVATE_H__ */
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 14e23a16ea..0392c1bafb 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -32,7 +32,7 @@
 #include "gtkcsstypesprivate.h"
 #include "gtkeventcontroller.h"
 #include "gtklistlistmodelprivate.h"
-#include "gtkroot.h"
+#include "gtkrootprivate.h"
 #include "gtksizerequestcacheprivate.h"
 #include "gtkwindowprivate.h"
 #include "gtkinvisibleprivate.h"
@@ -431,17 +431,12 @@ _gtk_widget_get_root (GtkWidget *widget)
 static inline GdkDisplay *
 _gtk_widget_get_display (GtkWidget *widget)
 {
-  GtkWidget *toplevel = _gtk_widget_get_toplevel (widget);
+  GtkRoot *root = _gtk_widget_get_root (widget);
 
-  if (_gtk_widget_is_toplevel (toplevel))
-    {
-      if (GTK_IS_WINDOW (toplevel))
-        return gtk_window_get_display (GTK_WINDOW (toplevel));
-      else if (GTK_IS_INVISIBLE (toplevel))
-        return gtk_invisible_get_display (GTK_INVISIBLE (widget));
-    }
+  if (root == NULL)
+    return gdk_display_get_default ();
 
-  return gdk_display_get_default ();
+  return gtk_root_get_display (root);
 }
 
 static inline GtkStyleContext *
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 4eccf40b2d..2497c866c5 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2498,9 +2498,19 @@ gtk_window_buildable_custom_finished (GtkBuildable  *buildable,
     }
 }
 
+static GdkDisplay *
+gtk_window_root_get_display (GtkRoot *root)
+{
+  GtkWindow *window = GTK_WINDOW (root);
+  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
+
+  return priv->display;
+}
+
 static void
 gtk_window_root_interface_init (GtkRootInterface *iface)
 {
+  iface->get_display = gtk_window_root_get_display;
 }
 
 /**
@@ -9436,14 +9446,6 @@ gtk_window_on_theme_variant_changed (GtkSettings *settings,
 }
 #endif
 
-GdkDisplay *
-gtk_window_get_display (GtkWindow *window)
-{
-  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
-
-  return priv->display;
-}
-
 /**
  * gtk_window_is_active:
  * @window: a #GtkWindow
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index f57a1b377b..ce91bfa59f 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -121,8 +121,6 @@ GdkTexture *     gtk_window_get_icon_for_size (GtkWindow *window,
 void       gtk_window_set_hardcoded_surface (GtkWindow *window,
                                             GdkSurface *surface);
 
-GdkDisplay *gtk_window_get_display (GtkWindow *window);
-
 /* Exported handles */
 
 typedef void (*GtkWindowHandleExported)  (GtkWindow               *window,


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