From 89a371ec98c09bd21d9b744aa4994a1095e347f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 25 Sep 2014 06:44:45 +0200 Subject: [PATCH] frames: Use title style to set up title layout Sounds obvious, doesn't it? After this change when titlebar-uses-system-font is set, the "system font" used will not be a generic one, but match what GTK+ uses in client-side decorations. https://bugzilla.gnome.org/show_bug.cgi?id=741917 --- src/ui/frames.c | 9 ++---- src/ui/theme-private.h | 11 +++---- src/ui/theme.c | 66 ++++++++++++++++-------------------------- src/ui/ui.c | 17 ++++------- 4 files changed, 36 insertions(+), 67 deletions(-) diff --git a/src/ui/frames.c b/src/ui/frames.c index 04a033359..597b05503 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -416,21 +416,16 @@ meta_frames_ensure_layout (MetaFrames *frames, { gpointer key, value; PangoFontDescription *font_desc; - double scale; int size; - scale = meta_theme_get_title_scale (meta_theme_get_current (), - type, - flags); - frame->layout = gtk_widget_create_pango_layout (widget, frame->title); pango_layout_set_ellipsize (frame->layout, PANGO_ELLIPSIZE_END); pango_layout_set_auto_dir (frame->layout, FALSE); pango_layout_set_single_paragraph_mode (frame->layout, TRUE); - font_desc = meta_gtk_widget_get_font_desc (widget, scale, - meta_prefs_get_titlebar_font ()); + font_desc = meta_style_info_create_font_desc (frame->style_info); + meta_frame_style_apply_scale (style, font_desc); size = pango_font_description_get_size (font_desc); diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h index bd482bac7..ac5a31d97 100644 --- a/src/ui/theme-private.h +++ b/src/ui/theme-private.h @@ -1021,6 +1021,8 @@ MetaFrameStyle* meta_frame_style_new (MetaFrameStyle *parent); void meta_frame_style_ref (MetaFrameStyle *style); void meta_frame_style_unref (MetaFrameStyle *style); +void meta_frame_style_apply_scale (const MetaFrameStyle *style, + PangoFontDescription *font_desc); gboolean meta_frame_style_validate (MetaFrameStyle *style, guint current_theme_version, @@ -1042,15 +1044,13 @@ MetaFrameStyle* meta_theme_get_frame_style (MetaTheme *theme, MetaFrameType type, MetaFrameFlags flags); -double meta_theme_get_title_scale (MetaTheme *theme, - MetaFrameType type, - MetaFrameFlags flags); - MetaStyleInfo * meta_theme_create_style_info (GdkScreen *screen, const gchar *variant); MetaStyleInfo * meta_style_info_ref (MetaStyleInfo *style); void meta_style_info_unref (MetaStyleInfo *style_info); +PangoFontDescription * meta_style_info_create_font_desc (MetaStyleInfo *style_info); + void meta_theme_draw_frame (MetaTheme *theme, MetaStyleInfo *style_info, cairo_t *cr, @@ -1130,9 +1130,6 @@ gboolean meta_theme_replace_constants (MetaTheme *theme, /* random stuff */ -PangoFontDescription* meta_gtk_widget_get_font_desc (GtkWidget *widget, - double scale, - const PangoFontDescription *override); int meta_pango_font_desc_get_text_height (const PangoFontDescription *font_desc, PangoContext *context); diff --git a/src/ui/theme.c b/src/ui/theme.c index c9ba282e4..2529dcaf9 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -4032,6 +4032,15 @@ get_button (MetaFrameStyle *style, return op_list; } +void +meta_frame_style_apply_scale (const MetaFrameStyle *style, + PangoFontDescription *font_desc) +{ + int size = pango_font_description_get_size (font_desc); + pango_font_description_set_size (font_desc, + MAX (size * style->layout->title_scale, 1)); +} + gboolean meta_frame_style_validate (MetaFrameStyle *style, guint current_theme_version, @@ -4982,24 +4991,6 @@ meta_theme_get_frame_style (MetaTheme *theme, return style; } -double -meta_theme_get_title_scale (MetaTheme *theme, - MetaFrameType type, - MetaFrameFlags flags) -{ - MetaFrameStyle *style; - - g_return_val_if_fail (type < META_FRAME_TYPE_LAST, 1.0); - - style = theme_get_style (theme, type, flags); - - /* Parser is not supposed to allow this currently */ - if (style == NULL) - return 1.0; - - return style->layout->title_scale; -} - static GtkStyleContext * create_style_context (GType widget_type, GtkStyleContext *parent_style, @@ -5120,6 +5111,22 @@ meta_style_info_unref (MetaStyleInfo *style_info) } } +PangoFontDescription* +meta_style_info_create_font_desc (MetaStyleInfo *style_info) +{ + PangoFontDescription *font_desc; + const PangoFontDescription *override = meta_prefs_get_titlebar_font (); + + gtk_style_context_get (style_info->styles[META_STYLE_ELEMENT_TITLE], + GTK_STATE_FLAG_NORMAL, + "font", &font_desc, NULL); + + if (override) + pango_font_description_merge (font_desc, override, TRUE); + + return font_desc; +} + void meta_theme_draw_frame (MetaTheme *theme, MetaStyleInfo *style_info, @@ -5488,29 +5495,6 @@ meta_theme_lookup_color_constant (MetaTheme *theme, } } - -PangoFontDescription* -meta_gtk_widget_get_font_desc (GtkWidget *widget, - double scale, - const PangoFontDescription *override) -{ - GtkStyleContext *style; - PangoFontDescription *font_desc; - - g_return_val_if_fail (gtk_widget_get_realized (widget), NULL); - - style = gtk_widget_get_style_context (widget); - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL); - - if (override) - pango_font_description_merge (font_desc, override, TRUE); - - pango_font_description_set_size (font_desc, - MAX (pango_font_description_get_size (font_desc) * scale, 1)); - - return font_desc; -} - /** * meta_pango_font_desc_get_text_height: * @font_desc: the font diff --git a/src/ui/ui.c b/src/ui/ui.c index 438188072..e93d76464 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -576,7 +576,7 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, MetaFrameBorders *borders) { int text_height; - GtkStyleContext *style = NULL; + MetaStyleInfo *style_info = NULL; PangoContext *context; const PangoFontDescription *font_desc; PangoFontDescription *free_font_desc = NULL; @@ -590,16 +590,9 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, { GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay); GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen)); - GtkWidgetPath *widget_path; - style = gtk_style_context_new (); - gtk_style_context_set_screen (style, screen); - widget_path = gtk_widget_path_new (); - gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); - gtk_style_context_set_path (style, widget_path); - gtk_widget_path_free (widget_path); - - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); + style_info = meta_theme_create_style_info (screen, NULL); + free_font_desc = meta_style_info_create_font_desc (style_info); font_desc = (const PangoFontDescription *) free_font_desc; } @@ -617,8 +610,8 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, meta_frame_borders_clear (borders); } - if (style != NULL) - g_object_unref (style); + if (style_info != NULL) + meta_style_info_unref (style_info); } void