mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
theme-viewer: use the same GtkStyleContext as mutter usually renders
https://bugzilla.gnome.org/show_bug.cgi?id=690317
This commit is contained in:
parent
22a3126a2b
commit
5c33b0d768
@ -44,6 +44,8 @@ struct _MetaPreview
|
||||
{
|
||||
GtkBin bin;
|
||||
|
||||
GtkStyleContext *style_context;
|
||||
|
||||
MetaTheme *theme;
|
||||
char *title;
|
||||
MetaFrameType type;
|
||||
|
@ -185,38 +185,6 @@ prefs_changed_callback (MetaPreference pref,
|
||||
}
|
||||
}
|
||||
|
||||
static GtkStyleContext *
|
||||
create_style_context (MetaFrames *frames,
|
||||
const gchar *variant)
|
||||
{
|
||||
GtkStyleContext *style;
|
||||
GdkScreen *screen;
|
||||
char *theme_name;
|
||||
|
||||
screen = gtk_widget_get_screen (GTK_WIDGET (frames));
|
||||
g_object_get (gtk_settings_get_for_screen (screen),
|
||||
"gtk-theme-name", &theme_name,
|
||||
NULL);
|
||||
|
||||
style = gtk_style_context_new ();
|
||||
gtk_style_context_set_path (style,
|
||||
gtk_widget_get_path (GTK_WIDGET (frames)));
|
||||
|
||||
if (theme_name && *theme_name)
|
||||
{
|
||||
GtkCssProvider *provider;
|
||||
|
||||
provider = gtk_css_provider_get_named (theme_name, variant);
|
||||
gtk_style_context_add_provider (style,
|
||||
GTK_STYLE_PROVIDER (provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
|
||||
}
|
||||
|
||||
g_free (theme_name);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
static GtkStyleContext *
|
||||
meta_frames_get_theme_variant (MetaFrames *frames,
|
||||
const gchar *variant)
|
||||
@ -226,7 +194,7 @@ meta_frames_get_theme_variant (MetaFrames *frames,
|
||||
style = g_hash_table_lookup (frames->style_variants, variant);
|
||||
if (style == NULL)
|
||||
{
|
||||
style = create_style_context (frames, variant);
|
||||
style = meta_theme_create_style_context (gtk_widget_get_screen (GTK_WIDGET (frames)), variant);
|
||||
g_hash_table_insert (frames->style_variants, g_strdup (variant), style);
|
||||
}
|
||||
|
||||
@ -238,15 +206,18 @@ update_style_contexts (MetaFrames *frames)
|
||||
{
|
||||
GtkStyleContext *style;
|
||||
GList *variants, *variant;
|
||||
GdkScreen *screen;
|
||||
|
||||
screen = gtk_widget_get_screen (GTK_WIDGET (frames));
|
||||
|
||||
if (frames->normal_style)
|
||||
g_object_unref (frames->normal_style);
|
||||
frames->normal_style = create_style_context (frames, NULL);
|
||||
frames->normal_style = meta_theme_create_style_context (screen, NULL);
|
||||
|
||||
variants = g_hash_table_get_keys (frames->style_variants);
|
||||
for (variant = variants; variant; variant = variants->next)
|
||||
{
|
||||
style = create_style_context (frames, (char *)variant->data);
|
||||
style = meta_theme_create_style_context (screen, (char *)variant->data);
|
||||
g_hash_table_insert (frames->style_variants,
|
||||
g_strdup (variant->data), style);
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ static void meta_preview_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
static gboolean meta_preview_draw (GtkWidget *widget,
|
||||
cairo_t *cr);
|
||||
static void meta_preview_realize (GtkWidget *widget);
|
||||
static void meta_preview_dispose (GObject *object);
|
||||
static void meta_preview_finalize (GObject *object);
|
||||
|
||||
G_DEFINE_TYPE (MetaPreview, meta_preview, GTK_TYPE_BIN);
|
||||
@ -51,8 +53,10 @@ meta_preview_class_init (MetaPreviewClass *class)
|
||||
|
||||
widget_class = (GtkWidgetClass*) class;
|
||||
|
||||
gobject_class->dispose = meta_preview_dispose;
|
||||
gobject_class->finalize = meta_preview_finalize;
|
||||
|
||||
widget_class->realize = meta_preview_realize;
|
||||
widget_class->draw = meta_preview_draw;
|
||||
widget_class->get_preferred_width = meta_preview_get_preferred_width;
|
||||
widget_class->get_preferred_height = meta_preview_get_preferred_height;
|
||||
@ -107,6 +111,16 @@ meta_preview_new (void)
|
||||
return GTK_WIDGET (preview);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_preview_dispose (GObject *object)
|
||||
{
|
||||
MetaPreview *preview = META_PREVIEW (object);
|
||||
|
||||
g_clear_object (&preview->style_context);
|
||||
|
||||
G_OBJECT_CLASS (meta_preview_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_preview_finalize (GObject *object)
|
||||
{
|
||||
@ -212,7 +226,7 @@ meta_preview_draw (GtkWidget *widget,
|
||||
client_height = 1;
|
||||
|
||||
meta_theme_draw_frame (preview->theme,
|
||||
gtk_widget_get_style_context (widget),
|
||||
preview->style_context,
|
||||
cr,
|
||||
preview->type,
|
||||
preview->flags,
|
||||
@ -231,6 +245,17 @@ meta_preview_draw (GtkWidget *widget,
|
||||
return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_preview_realize (GtkWidget *widget)
|
||||
{
|
||||
MetaPreview *preview = META_PREVIEW (widget);
|
||||
|
||||
GTK_WIDGET_CLASS (meta_preview_parent_class)->realize (widget);
|
||||
|
||||
preview->style_context = meta_theme_create_style_context (gtk_widget_get_screen (widget),
|
||||
NULL);
|
||||
}
|
||||
|
||||
#define NO_CHILD_WIDTH 80
|
||||
#define NO_CHILD_HEIGHT 20
|
||||
|
||||
|
@ -1022,6 +1022,9 @@ double meta_theme_get_title_scale (MetaTheme *theme,
|
||||
MetaFrameType type,
|
||||
MetaFrameFlags flags);
|
||||
|
||||
GtkStyleContext * meta_theme_create_style_context (GdkScreen *screen,
|
||||
const gchar *variant);
|
||||
|
||||
void meta_theme_draw_frame (MetaTheme *theme,
|
||||
GtkStyleContext *style_gtk,
|
||||
cairo_t *cr,
|
||||
|
@ -854,7 +854,8 @@ main (int argc, char **argv)
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
gtk_widget_realize (window);
|
||||
style = gtk_widget_get_style_context (window);
|
||||
|
||||
style = meta_theme_create_style_context (gtk_widget_get_screen (window), NULL);
|
||||
gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL);
|
||||
|
||||
g_assert (style);
|
||||
@ -927,13 +928,12 @@ get_flags (GtkWidget *widget)
|
||||
}
|
||||
|
||||
static int
|
||||
get_text_height (GtkWidget *widget)
|
||||
get_text_height (GtkWidget *widget,
|
||||
GtkStyleContext *style)
|
||||
{
|
||||
GtkStyleContext *style;
|
||||
PangoFontDescription *font_desc;
|
||||
int text_height;
|
||||
|
||||
style = gtk_widget_get_style_context (widget);
|
||||
gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL);
|
||||
text_height = meta_pango_font_desc_get_text_height (font_desc,
|
||||
gtk_widget_get_pango_context (widget));
|
||||
@ -955,6 +955,7 @@ static void
|
||||
run_theme_benchmark (void)
|
||||
{
|
||||
GtkWidget* widget;
|
||||
GtkStyleContext *style_context;
|
||||
cairo_surface_t *pixmap;
|
||||
MetaFrameBorders borders;
|
||||
MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
|
||||
@ -978,13 +979,15 @@ run_theme_benchmark (void)
|
||||
|
||||
widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_widget_realize (widget);
|
||||
|
||||
|
||||
style_context = meta_theme_create_style_context (gtk_widget_get_screen (widget), NULL);
|
||||
|
||||
meta_theme_get_frame_borders (global_theme,
|
||||
META_FRAME_TYPE_NORMAL,
|
||||
get_text_height (widget),
|
||||
get_text_height (widget, style_context),
|
||||
get_flags (widget),
|
||||
&borders);
|
||||
|
||||
|
||||
layout = create_title_layout (widget);
|
||||
|
||||
i = 0;
|
||||
@ -1024,13 +1027,13 @@ run_theme_benchmark (void)
|
||||
cr = cairo_create (pixmap);
|
||||
|
||||
meta_theme_draw_frame (global_theme,
|
||||
gtk_widget_get_style_context (widget),
|
||||
style_context,
|
||||
cr,
|
||||
META_FRAME_TYPE_NORMAL,
|
||||
get_flags (widget),
|
||||
client_width, client_height,
|
||||
layout,
|
||||
get_text_height (widget),
|
||||
get_text_height (widget, style_context),
|
||||
&button_layout,
|
||||
button_states,
|
||||
meta_preview_get_mini_icon (),
|
||||
@ -1058,6 +1061,7 @@ run_theme_benchmark (void)
|
||||
|
||||
g_timer_destroy (timer);
|
||||
g_object_unref (G_OBJECT (layout));
|
||||
g_object_unref (style_context);
|
||||
gtk_widget_destroy (widget);
|
||||
|
||||
#undef ITERATIONS
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#include <config.h>
|
||||
#include "theme-private.h"
|
||||
#include "frames.h" /* for META_TYPE_FRAMES */
|
||||
#include <meta/util.h>
|
||||
#include <meta/gradient.h>
|
||||
#include <meta/prefs.h>
|
||||
@ -5438,6 +5439,37 @@ meta_theme_get_title_scale (MetaTheme *theme,
|
||||
return style->layout->title_scale;
|
||||
}
|
||||
|
||||
GtkStyleContext *
|
||||
meta_theme_create_style_context (GdkScreen *screen,
|
||||
const gchar *variant)
|
||||
{
|
||||
GtkWidgetPath *path;
|
||||
GtkStyleContext *style;
|
||||
char *theme_name;
|
||||
|
||||
g_object_get (gtk_settings_get_for_screen (screen),
|
||||
"gtk-theme-name", &theme_name,
|
||||
NULL);
|
||||
|
||||
style = gtk_style_context_new ();
|
||||
path = gtk_widget_path_new ();
|
||||
gtk_widget_path_append_type (path, META_TYPE_FRAMES);
|
||||
gtk_style_context_set_path (style, path);
|
||||
gtk_widget_path_unref (path);
|
||||
|
||||
if (theme_name && *theme_name)
|
||||
{
|
||||
GtkCssProvider *provider;
|
||||
|
||||
provider = gtk_css_provider_get_named (theme_name, variant);
|
||||
gtk_style_context_add_provider (style,
|
||||
GTK_STYLE_PROVIDER (provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
void
|
||||
meta_theme_draw_frame (MetaTheme *theme,
|
||||
GtkStyleContext *style_gtk,
|
||||
|
Loading…
Reference in New Issue
Block a user