[gtk/inspector-display: 5/14] inspector: Attach inspector window to display



commit a207a4b3cd6d608968dee450971bf48ee7775b19
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Dec 7 10:54:10 2019 -0500

    inspector: Attach inspector window to display
    
    Give the inspector window a ::inspected-display
    property, and pass a display when obtaining an
    inspector window. Update the caller.

 gtk/gtkwindow.c        |  2 +-
 gtk/inspector/window.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++----
 gtk/inspector/window.h |  5 ++-
 3 files changed, 95 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0911c39285..fc0c1c6469 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -9021,7 +9021,7 @@ gtk_window_set_debugging (GdkDisplay *display,
 
   if (enable && inspector_window == NULL)
     {
-      inspector_window = gtk_inspector_window_new ();
+      inspector_window = gtk_inspector_window_get (display);
 
       if (warn)
         {
diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c
index 3b6afee60f..97acc43865 100644
--- a/gtk/inspector/window.c
+++ b/gtk/inspector/window.c
@@ -59,6 +59,13 @@
 #include "gtkstylecontext.h"
 
 
+enum {
+  PROP_INSPECTED_DISPLAY = 1,
+  NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES];
+
 G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
 
 static gboolean
@@ -198,6 +205,8 @@ gtk_inspector_window_init (GtkInspectorWindow *iw)
                                iw,
                                NULL);
 
+  gtk_window_set_hide_on_close (GTK_WINDOW (iw), TRUE);
+
   gtk_window_group_add_window (gtk_window_group_new (), GTK_WINDOW (iw));
 
   extension_point = g_io_extension_point_lookup ("gtk-inspector-page");
@@ -255,13 +264,15 @@ gtk_inspector_window_constructed (GObject *object)
 
   G_OBJECT_CLASS (gtk_inspector_window_parent_class)->constructed (object);
 
-  g_object_set_data (G_OBJECT (gdk_display_get_default ()), "-gtk-inspector", iw);
+  g_object_set_data (G_OBJECT (iw->inspected_display), "-gtk-inspector", iw);
 }
 
 static void
 gtk_inspector_window_dispose (GObject *object)
 {
-  g_object_set_data (G_OBJECT (gdk_display_get_default ()), "-gtk-inspector", NULL);
+  GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
+
+  g_object_set_data (G_OBJECT (iw->inspected_display), "-gtk-inspector", NULL);
 
   G_OBJECT_CLASS (gtk_inspector_window_parent_class)->dispose (object);
 }
@@ -309,6 +320,46 @@ gtk_inspector_window_realize (GtkWidget *widget)
   g_object_unref (provider);
 }
 
+static void
+gtk_inspector_window_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
+
+  switch (prop_id)
+    {
+    case PROP_INSPECTED_DISPLAY:
+      iw->inspected_display = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_inspector_window_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (object);
+
+  switch (prop_id)
+    {
+    case PROP_INSPECTED_DISPLAY:
+      g_value_set_object (value, iw->inspected_display);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 static void
 gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
 {
@@ -317,8 +368,16 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
 
   object_class->constructed = gtk_inspector_window_constructed;
   object_class->dispose = gtk_inspector_window_dispose;
+  object_class->set_property = gtk_inspector_window_set_property;
+  object_class->get_property = gtk_inspector_window_get_property;
   widget_class->realize = gtk_inspector_window_realize;
 
+  properties[PROP_INSPECTED_DISPLAY] =
+      g_param_spec_object ("inspected-display", "Inspected display", "Inspected display",
+                           GDK_TYPE_DISPLAY,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
+
   g_signal_new (g_intern_static_string ("event"),
                 G_OBJECT_CLASS_TYPE (object_class),
                 G_SIGNAL_RUN_LAST,
@@ -416,14 +475,32 @@ get_inspector_display (void)
   return display;
 }
 
+static GtkInspectorWindow *
+gtk_inspector_window_new (GdkDisplay *display)
+{
+  GtkInspectorWindow *iw;
+
+  iw = g_object_new (GTK_TYPE_INSPECTOR_WINDOW,
+                     "display", get_inspector_display (),
+                     "inspected-display", display,
+                     NULL);
+
+  return iw;
+}
+
 GtkWidget *
-gtk_inspector_window_new (void)
+gtk_inspector_window_get (GdkDisplay *display)
 {
+  GtkWidget *iw;
+
   gtk_inspector_init ();
 
-  return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_WINDOW,
-                                   "display", get_inspector_display (),
-                                   NULL));
+  iw = GTK_WIDGET (g_object_get_data (G_OBJECT (display), "-gtk-inspector"));
+
+  if (!iw)
+    iw = GTK_WIDGET (gtk_inspector_window_new (display)); 
+
+  return iw;
 }
 
 void
@@ -531,4 +608,11 @@ gtk_inspector_handle_event (GdkEvent *event)
   return handled;
 }
 
+GdkDisplay *
+gtk_inspector_window_get_inspected_display (GtkInspectorWindow *iw)
+{
+  return iw->inspected_display;
+}
+
 // vim: set et sw=2 ts=2:
+
diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h
index c227782cc2..f8ba6c5ef9 100644
--- a/gtk/inspector/window.h
+++ b/gtk/inspector/window.h
@@ -84,6 +84,8 @@ typedef struct
 
   GList *overlays;
 
+  GdkDisplay *inspected_display;
+
 } GtkInspectorWindow;
 
 typedef struct
@@ -95,7 +97,7 @@ typedef struct
 G_BEGIN_DECLS
 
 GType      gtk_inspector_window_get_type    (void);
-GtkWidget *gtk_inspector_window_new         (void);
+GtkWidget *gtk_inspector_window_get         (GdkDisplay *display);
 
 void       gtk_inspector_flash_widget       (GtkInspectorWindow *iw,
                                              GtkWidget          *widget);
@@ -109,6 +111,7 @@ void                    gtk_inspector_window_remove_overlay
                                                                                  GtkInspectorOverlay    
*overlay);
 
 void                    gtk_inspector_window_select_widget_under_pointer        (GtkInspectorWindow     *iw);
+GdkDisplay *            gtk_inspector_window_get_inspected_display              (GtkInspectorWindow     *iw);
 
 gboolean                gtk_inspector_is_recording                              (GtkWidget              
*widget);
 GskRenderNode *         gtk_inspector_prepare_render                            (GtkWidget              
*widget,


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