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.
This commit is contained in:
Matthias Clasen 2019-12-07 10:54:10 -05:00
parent 39a1d27960
commit a207a4b3cd
3 changed files with 96 additions and 9 deletions

View File

@ -9021,7 +9021,7 @@ gtk_window_set_debugging (GdkDisplay *display,
if (enable && inspector_window == NULL) if (enable && inspector_window == NULL)
{ {
inspector_window = gtk_inspector_window_new (); inspector_window = gtk_inspector_window_get (display);
if (warn) if (warn)
{ {

View File

@ -59,6 +59,13 @@
#include "gtkstylecontext.h" #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) G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
static gboolean static gboolean
@ -198,6 +205,8 @@ gtk_inspector_window_init (GtkInspectorWindow *iw)
iw, iw,
NULL); NULL);
gtk_window_set_hide_on_close (GTK_WINDOW (iw), TRUE);
gtk_window_group_add_window (gtk_window_group_new (), GTK_WINDOW (iw)); gtk_window_group_add_window (gtk_window_group_new (), GTK_WINDOW (iw));
extension_point = g_io_extension_point_lookup ("gtk-inspector-page"); 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_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 static void
gtk_inspector_window_dispose (GObject *object) 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); G_OBJECT_CLASS (gtk_inspector_window_parent_class)->dispose (object);
} }
@ -309,6 +320,46 @@ gtk_inspector_window_realize (GtkWidget *widget)
g_object_unref (provider); 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 static void
gtk_inspector_window_class_init (GtkInspectorWindowClass *klass) 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->constructed = gtk_inspector_window_constructed;
object_class->dispose = gtk_inspector_window_dispose; 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; 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_signal_new (g_intern_static_string ("event"),
G_OBJECT_CLASS_TYPE (object_class), G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
@ -416,14 +475,32 @@ get_inspector_display (void)
return display; return display;
} }
GtkWidget * static GtkInspectorWindow *
gtk_inspector_window_new (void) 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_get (GdkDisplay *display)
{
GtkWidget *iw;
gtk_inspector_init (); gtk_inspector_init ();
return GTK_WIDGET (g_object_new (GTK_TYPE_INSPECTOR_WINDOW, iw = GTK_WIDGET (g_object_get_data (G_OBJECT (display), "-gtk-inspector"));
"display", get_inspector_display (),
NULL)); if (!iw)
iw = GTK_WIDGET (gtk_inspector_window_new (display));
return iw;
} }
void void
@ -531,4 +608,11 @@ gtk_inspector_handle_event (GdkEvent *event)
return handled; return handled;
} }
GdkDisplay *
gtk_inspector_window_get_inspected_display (GtkInspectorWindow *iw)
{
return iw->inspected_display;
}
// vim: set et sw=2 ts=2: // vim: set et sw=2 ts=2:

View File

@ -84,6 +84,8 @@ typedef struct
GList *overlays; GList *overlays;
GdkDisplay *inspected_display;
} GtkInspectorWindow; } GtkInspectorWindow;
typedef struct typedef struct
@ -95,7 +97,7 @@ typedef struct
G_BEGIN_DECLS G_BEGIN_DECLS
GType gtk_inspector_window_get_type (void); 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, void gtk_inspector_flash_widget (GtkInspectorWindow *iw,
GtkWidget *widget); GtkWidget *widget);
@ -109,6 +111,7 @@ void gtk_inspector_window_remove_overlay
GtkInspectorOverlay *overlay); GtkInspectorOverlay *overlay);
void gtk_inspector_window_select_widget_under_pointer (GtkInspectorWindow *iw); 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); gboolean gtk_inspector_is_recording (GtkWidget *widget);
GskRenderNode * gtk_inspector_prepare_render (GtkWidget *widget, GskRenderNode * gtk_inspector_prepare_render (GtkWidget *widget,