[metacity/wip/gtk-theme: 3/51] theme-viewer: use the same GtkStyleContext as mutter usually renders
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity/wip/gtk-theme: 3/51] theme-viewer: use the same GtkStyleContext as mutter usually renders
- Date: Thu, 1 Jan 2015 20:39:27 +0000 (UTC)
commit ccfbb8980bf41a7d50c083a95909c96ca14d4783
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sun Dec 16 17:54:33 2012 -0500
theme-viewer: use the same GtkStyleContext as mutter usually renders
https://bugzilla.gnome.org/show_bug.cgi?id=690317
src/ui/frames.c | 42 ++++++------------------------------------
src/ui/preview-widget.c | 27 ++++++++++++++++++++++++++-
src/ui/preview-widget.h | 2 ++
src/ui/theme-viewer.c | 18 +++++++++++-------
src/ui/theme.c | 34 ++++++++++++++++++++++++++++++++++
src/ui/theme.h | 3 +++
6 files changed, 82 insertions(+), 44 deletions(-)
---
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 4fdf7ee..7f93eec 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -187,39 +187,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);
- }
-
- if (theme_name)
- g_free (theme_name);
-
- return style;
-}
-
-static GtkStyleContext *
meta_frames_get_theme_variant (MetaFrames *frames,
const gchar *variant)
{
@@ -228,7 +195,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);
}
@@ -240,15 +207,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);
}
diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c
index 39505e7..1d7aeb6 100644
--- a/src/ui/preview-widget.c
+++ b/src/ui/preview-widget.c
@@ -36,6 +36,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);
@@ -48,8 +50,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;
@@ -105,6 +109,16 @@ meta_preview_new (void)
}
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)
{
MetaPreview *preview;
@@ -217,7 +231,7 @@ meta_preview_draw (GtkWidget *widget,
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
meta_theme_draw_frame (preview->theme,
- gtk_widget_get_style_context (widget),
+ preview->style_context,
cr,
preview->type,
preview->flags,
@@ -236,6 +250,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
diff --git a/src/ui/preview-widget.h b/src/ui/preview-widget.h
index b59e231..db85b13 100644
--- a/src/ui/preview-widget.h
+++ b/src/ui/preview-widget.h
@@ -39,6 +39,8 @@ struct _MetaPreview
{
GtkBin bin;
+ GtkStyleContext *style_context;
+
MetaTheme *theme;
char *title;
MetaFrameType type;
diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c
index 351362c..22c618a 100644
--- a/src/ui/theme-viewer.c
+++ b/src/ui/theme-viewer.c
@@ -913,7 +913,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);
@@ -986,13 +987,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));
pango_font_description_free (font_desc);
@@ -1014,6 +1014,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] =
@@ -1038,9 +1039,11 @@ 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);
@@ -1082,13 +1085,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 (),
@@ -1116,6 +1119,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
diff --git a/src/ui/theme.c b/src/ui/theme.c
index c4e1abf..a5ddc0e 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -51,6 +51,7 @@
*/
#include <config.h>
+#include "frames.h" /* for META_TYPE_FRAMES */
#include "theme.h"
#include "theme-parser.h"
#include "util.h"
@@ -5438,6 +5439,39 @@ 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);
+ }
+
+ g_free (theme_name);
+
+ return style;
+}
+
void
meta_theme_draw_frame (MetaTheme *theme,
GtkStyleContext *style_gtk,
diff --git a/src/ui/theme.h b/src/ui/theme.h
index 6b08fea..5dc5028 100644
--- a/src/ui/theme.h
+++ b/src/ui/theme.h
@@ -1037,6 +1037,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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]