From b2ca8c4cb34f8efae18d4849eb25369c6a6b935b Mon Sep 17 00:00:00 2001 From: Pablo Barciela Date: Tue, 24 Jul 2018 00:54:36 +0200 Subject: pluma-view: sync the font in context-menu with gsettings key --- pluma/pluma-view.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ pluma/pluma-view.h | 4 ++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/pluma/pluma-view.c b/pluma/pluma-view.c index 9daa0c73..7aec69e3 100644 --- a/pluma/pluma-view.c +++ b/pluma/pluma-view.c @@ -648,24 +648,39 @@ pluma_view_scroll_to_cursor (PlumaView *view) static PangoFontDescription* get_system_font (void) { - PangoFontDescription *desc = NULL; - GSettings *settings; - char *name; + PangoFontDescription *desc = NULL; + GSettings *settings; + char *name; - settings = g_settings_new ("org.mate.interface"); - name = g_settings_get_string (settings, "font-name"); + settings = g_settings_new ("org.mate.interface"); + name = g_settings_get_string (settings, "font-name"); - if (name) { - desc = pango_font_description_from_string (name); - g_free (name); - } + if (name) + { + desc = pango_font_description_from_string (name); + g_free (name); + } - g_object_unref (settings); + g_object_unref (settings); - return desc; + return desc; } static void +contextmenu_font_changed_cb (GSettings *settings, + gchar *key, + gpointer user_data) +{ + PangoFontDescription *sys_font_desc = NULL; + sys_font_desc = get_system_font (); + if (sys_font_desc) + { + pluma_override_font (".context-menu", GTK_WIDGET (user_data), sys_font_desc); + pango_font_description_free (sys_font_desc); + } +} + +void pluma_override_font (const gchar *item, GtkWidget *widget, PangoFontDescription *font) @@ -699,13 +714,27 @@ pluma_override_font (const gchar *item, prov_str = gtk_css_provider_to_string (provider); if (g_str_has_prefix (prov_str, "textview") && g_str_has_prefix (item, ".context-menu")) + { + if (strstr (prov_str, ".context-menu")) + { + prov_str = g_strdelimit (prov_str, "}", '\0'); + prov_str = g_strdup_printf ("%s}", prov_str); + } css = g_strdup_printf ("%s %s { %s %s %s %s }", prov_str, item, family, weight, style, size); + } else css = g_strdup_printf ("%s { %s %s %s %s }", item, family, weight, style, size); gtk_css_provider_load_from_data (provider, css, -1, NULL); - if (!provider_added) { + if (!provider_added) + { + GSettings *settings; + settings = g_settings_new ("org.mate.interface"); + g_signal_connect (settings, + "changed::" "font-name", + G_CALLBACK (contextmenu_font_changed_cb), NULL); + gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (widget), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); diff --git a/pluma/pluma-view.h b/pluma/pluma-view.h index 7cb0094c..c8877d5f 100644 --- a/pluma/pluma-view.h +++ b/pluma/pluma-view.h @@ -99,6 +99,10 @@ void pluma_view_select_all (PlumaView *view); void pluma_view_scroll_to_cursor (PlumaView *view); +void pluma_override_font (const gchar *item, + GtkWidget *widget, + PangoFontDescription *font); + void pluma_view_set_font (PlumaView *view, gboolean def, const gchar *font_name); -- cgit v1.2.1