theme-context: Use interface font instead of hardcoded default

With this, gnome-shell will now follow the interface setting instead
of hardcoding a default font, unless when overwritten by the CSS.

https://bugzilla.gnome.org/show_bug.cgi?id=688288
This commit is contained in:
Florian Müllner 2019-04-08 17:50:08 +02:00 committed by Florian Müllner
parent cd84fa824f
commit f28f041a95

View File

@ -22,6 +22,7 @@
#include <config.h> #include <config.h>
#include "st-private.h" #include "st-private.h"
#include "st-settings.h"
#include "st-texture-cache.h" #include "st-texture-cache.h"
#include "st-theme.h" #include "st-theme.h"
#include "st-theme-context.h" #include "st-theme-context.h"
@ -42,8 +43,6 @@ struct _StThemeContext {
int scale_factor; int scale_factor;
}; };
#define DEFAULT_FONT "sans-serif 10"
enum enum
{ {
PROP_0, PROP_0,
@ -61,6 +60,10 @@ static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (StThemeContext, st_theme_context, G_TYPE_OBJECT) G_DEFINE_TYPE (StThemeContext, st_theme_context, G_TYPE_OBJECT)
static PangoFontDescription *get_interface_font_description (void);
static void on_font_name_changed (StSettings *settings,
GParamSpec *pspec,
StThemeContext *context);
static void on_icon_theme_changed (StTextureCache *cache, static void on_icon_theme_changed (StTextureCache *cache,
StThemeContext *context); StThemeContext *context);
static void st_theme_context_changed (StThemeContext *context); static void st_theme_context_changed (StThemeContext *context);
@ -79,6 +82,9 @@ st_theme_context_finalize (GObject *object)
{ {
StThemeContext *context = ST_THEME_CONTEXT (object); StThemeContext *context = ST_THEME_CONTEXT (object);
g_signal_handlers_disconnect_by_func (st_settings_get (),
(gpointer) on_font_name_changed,
context);
g_signal_handlers_disconnect_by_func (st_texture_cache_get_default (), g_signal_handlers_disconnect_by_func (st_texture_cache_get_default (),
(gpointer) on_icon_theme_changed, (gpointer) on_icon_theme_changed,
context); context);
@ -134,8 +140,12 @@ st_theme_context_class_init (StThemeContextClass *klass)
static void static void
st_theme_context_init (StThemeContext *context) st_theme_context_init (StThemeContext *context)
{ {
context->font = pango_font_description_from_string (DEFAULT_FONT); context->font = get_interface_font_description ();
g_signal_connect (st_settings_get (),
"notify::font-name",
G_CALLBACK (on_font_name_changed),
context);
g_signal_connect (st_texture_cache_get_default (), g_signal_connect (st_texture_cache_get_default (),
"icon-theme-changed", "icon-theme-changed",
G_CALLBACK (on_icon_theme_changed), G_CALLBACK (on_icon_theme_changed),
@ -215,6 +225,16 @@ st_theme_context_new (void)
return context; return context;
} }
static PangoFontDescription *
get_interface_font_description (void)
{
StSettings *settings = st_settings_get ();
g_autofree char *font_name = NULL;
g_object_get (settings, "font-name", &font_name, NULL);
return pango_font_description_from_string (font_name);
}
static void static void
on_stage_destroy (ClutterStage *stage) on_stage_destroy (ClutterStage *stage)
{ {
@ -237,6 +257,17 @@ st_theme_context_changed (StThemeContext *context)
g_object_unref (old_root); g_object_unref (old_root);
} }
static void
on_font_name_changed (StSettings *settings,
GParamSpec *pspect,
StThemeContext *context)
{
PangoFontDescription *font_desc = get_interface_font_description ();
st_theme_context_set_font (context, font_desc);
pango_font_description_free (font_desc);
}
static gboolean static gboolean
changed_idle (gpointer userdata) changed_idle (gpointer userdata)
{ {