Skip to content

Commit b2ca8c4

Browse files
sc0wraveit65
authored andcommitted
pluma-view: sync the font in context-menu with gsettings key
1 parent f952be3 commit b2ca8c4

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

pluma/pluma-view.c

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,24 +648,39 @@ pluma_view_scroll_to_cursor (PlumaView *view)
648648

649649
static PangoFontDescription* get_system_font (void)
650650
{
651-
PangoFontDescription *desc = NULL;
652-
GSettings *settings;
653-
char *name;
651+
PangoFontDescription *desc = NULL;
652+
GSettings *settings;
653+
char *name;
654654

655-
settings = g_settings_new ("org.mate.interface");
656-
name = g_settings_get_string (settings, "font-name");
655+
settings = g_settings_new ("org.mate.interface");
656+
name = g_settings_get_string (settings, "font-name");
657657

658-
if (name) {
659-
desc = pango_font_description_from_string (name);
660-
g_free (name);
661-
}
658+
if (name)
659+
{
660+
desc = pango_font_description_from_string (name);
661+
g_free (name);
662+
}
662663

663-
g_object_unref (settings);
664+
g_object_unref (settings);
664665

665-
return desc;
666+
return desc;
666667
}
667668

668669
static void
670+
contextmenu_font_changed_cb (GSettings *settings,
671+
gchar *key,
672+
gpointer user_data)
673+
{
674+
PangoFontDescription *sys_font_desc = NULL;
675+
sys_font_desc = get_system_font ();
676+
if (sys_font_desc)
677+
{
678+
pluma_override_font (".context-menu", GTK_WIDGET (user_data), sys_font_desc);
679+
pango_font_description_free (sys_font_desc);
680+
}
681+
}
682+
683+
void
669684
pluma_override_font (const gchar *item,
670685
GtkWidget *widget,
671686
PangoFontDescription *font)
@@ -699,13 +714,27 @@ pluma_override_font (const gchar *item,
699714
prov_str = gtk_css_provider_to_string (provider);
700715

701716
if (g_str_has_prefix (prov_str, "textview") && g_str_has_prefix (item, ".context-menu"))
717+
{
718+
if (strstr (prov_str, ".context-menu"))
719+
{
720+
prov_str = g_strdelimit (prov_str, "}", '\0');
721+
prov_str = g_strdup_printf ("%s}", prov_str);
722+
}
702723
css = g_strdup_printf ("%s %s { %s %s %s %s }", prov_str, item, family, weight, style, size);
724+
}
703725
else
704726
css = g_strdup_printf ("%s { %s %s %s %s }", item, family, weight, style, size);
705727

706728
gtk_css_provider_load_from_data (provider, css, -1, NULL);
707729

708-
if (!provider_added) {
730+
if (!provider_added)
731+
{
732+
GSettings *settings;
733+
settings = g_settings_new ("org.mate.interface");
734+
g_signal_connect (settings,
735+
"changed::" "font-name",
736+
G_CALLBACK (contextmenu_font_changed_cb), NULL);
737+
709738
gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (widget),
710739
GTK_STYLE_PROVIDER (provider),
711740
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

pluma/pluma-view.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ void pluma_view_select_all (PlumaView *view);
9999

100100
void pluma_view_scroll_to_cursor (PlumaView *view);
101101

102+
void pluma_override_font (const gchar *item,
103+
GtkWidget *widget,
104+
PangoFontDescription *font);
105+
102106
void pluma_view_set_font (PlumaView *view,
103107
gboolean def,
104108
const gchar *font_name);

0 commit comments

Comments
 (0)