inspector: Make css editor respect inspected display

Stop using gdk_display_get_default and use the
inspected display instead.
This commit is contained in:
Matthias Clasen 2019-12-07 11:48:39 -05:00
parent 1437b0856c
commit 174d8b72a5
5 changed files with 43 additions and 12 deletions

View File

@ -23,6 +23,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include "window.h"
#include "css-editor.h"
#include "gtkcssprovider.h"
@ -42,6 +43,7 @@ struct _GtkInspectorCssEditorPrivate
{
GtkWidget *view;
GtkTextBuffer *text;
GdkDisplay *display;
GtkCssProvider *provider;
GtkToggleButton *disable_button;
guint timeout;
@ -157,11 +159,14 @@ static void
disable_toggled (GtkToggleButton *button,
GtkInspectorCssEditor *ce)
{
if (!ce->priv->display)
return;
if (gtk_toggle_button_get_active (button))
gtk_style_context_remove_provider_for_display (gdk_display_get_default (),
gtk_style_context_remove_provider_for_display (ce->priv->display,
GTK_STYLE_PROVIDER (ce->priv->provider));
else
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
gtk_style_context_add_provider_for_display (ce->priv->display,
GTK_STYLE_PROVIDER (ce->priv->provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
}
@ -326,22 +331,35 @@ static void
create_provider (GtkInspectorCssEditor *ce)
{
ce->priv->provider = gtk_css_provider_new ();
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
GTK_STYLE_PROVIDER (ce->priv->provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
g_signal_connect (ce->priv->provider, "parsing-error",
G_CALLBACK (show_parsing_error), ce);
}
static void
destroy_provider (GtkInspectorCssEditor *ce)
{
gtk_style_context_remove_provider_for_display (gdk_display_get_default (),
GTK_STYLE_PROVIDER (ce->priv->provider));
g_signal_handlers_disconnect_by_func (ce->priv->provider, show_parsing_error, ce);
g_clear_object (&ce->priv->provider);
}
static void
add_provider (GtkInspectorCssEditor *ce,
GdkDisplay *display)
{
gtk_style_context_add_provider_for_display (display,
GTK_STYLE_PROVIDER (ce->priv->provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
}
static void
remove_provider (GtkInspectorCssEditor *ce,
GdkDisplay *display)
{
gtk_style_context_remove_provider_for_display (display,
GTK_STYLE_PROVIDER (ce->priv->provider));
}
static void
gtk_inspector_css_editor_init (GtkInspectorCssEditor *ce)
{
@ -355,7 +373,6 @@ constructed (GObject *object)
GtkInspectorCssEditor *ce = GTK_INSPECTOR_CSS_EDITOR (object);
create_provider (ce);
set_initial_text (ce);
}
static void
@ -366,6 +383,8 @@ finalize (GObject *object)
if (ce->priv->timeout != 0)
g_source_remove (ce->priv->timeout);
if (ce->priv->display)
remove_provider (ce, ce->priv->display);
destroy_provider (ce);
g_list_free_full (ce->priv->errors, css_error_free);
@ -392,4 +411,13 @@ gtk_inspector_css_editor_class_init (GtkInspectorCssEditorClass *klass)
gtk_widget_class_bind_template_callback (widget_class, query_tooltip_cb);
}
void
gtk_inspector_css_editor_set_display (GtkInspectorCssEditor *ce,
GdkDisplay *display)
{
ce->priv->display = display;
add_provider (ce, display);
set_initial_text (ce);
}
// vim: set et sw=2 ts=2:

View File

@ -49,8 +49,8 @@ typedef struct _GtkInspectorCssEditorClass
G_BEGIN_DECLS
GType gtk_inspector_css_editor_get_type (void);
void gtk_inspector_css_editor_set_object (GtkInspectorCssEditor *ce,
GObject *object);
void gtk_inspector_css_editor_set_display (GtkInspectorCssEditor *ce,
GdkDisplay *display);
G_END_DECLS

View File

@ -267,6 +267,7 @@ gtk_inspector_window_constructed (GObject *object)
g_object_set_data (G_OBJECT (iw->inspected_display), "-gtk-inspector", iw);
gtk_inspector_object_tree_set_display (GTK_INSPECTOR_OBJECT_TREE (iw->object_tree), iw->inspected_display);
gtk_inspector_css_editor_set_display (GTK_INSPECTOR_CSS_EDITOR (iw->css_editor), iw->inspected_display);
}
static void
@ -416,6 +417,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, controllers);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, magnifier);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, sidebar_revealer);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, css_editor);
gtk_widget_class_bind_template_callback (widget_class, gtk_inspector_on_inspect);
gtk_widget_class_bind_template_callback (widget_class, on_object_activated);

View File

@ -71,6 +71,7 @@ typedef struct
GtkWidget *controllers;
GtkWidget *magnifier;
GtkWidget *sidebar_revealer;
GtkWidget *css_editor;
GtkWidget *selected_widget;

View File

@ -519,7 +519,7 @@
<property name="name">css</property>
<property name="title" translatable="yes">CSS</property>
<property name="child">
<object class="GtkInspectorCssEditor"/>
<object class="GtkInspectorCssEditor" id="css_editor"/>
</property>
</object>
</child>