Skip to content

Commit a15746b

Browse files
sc0wlukefromdc
authored andcommitted
mateweather-dialog.c: avoid deprecated 'gtk_widget_override_font'
1 parent 881233e commit a15746b

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

Diff for: mateweather/mateweather-dialog.c

+46-1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,51 @@ static PangoFontDescription* get_system_monospace_font(void)
506506
return desc;
507507
}
508508

509+
static void
510+
override_widget_font (GtkWidget *widget,
511+
PangoFontDescription *font)
512+
{
513+
static gboolean provider_added = FALSE;
514+
GtkCssProvider *provider;
515+
gchar *css;
516+
gchar *family;
517+
gchar *weight;
518+
const gchar *style;
519+
gchar *size;
520+
521+
family = g_strdup_printf ("font-family: %s;", pango_font_description_get_family (font));
522+
523+
weight = g_strdup_printf ("font-weight: %d;", pango_font_description_get_weight (font));
524+
525+
if (pango_font_description_get_style (font) == PANGO_STYLE_NORMAL)
526+
style = "font-style: normal;";
527+
else if (pango_font_description_get_style (font) == PANGO_STYLE_ITALIC)
528+
style = "font-style: italic;";
529+
else
530+
style = "font-style: oblique;";
531+
532+
size = g_strdup_printf ("font-size: %d%s;",
533+
pango_font_description_get_size (font) / PANGO_SCALE,
534+
pango_font_description_get_size_is_absolute (font) ? "px" : "pt");
535+
536+
provider = gtk_css_provider_get_default ();
537+
538+
css = g_strdup_printf ("textview { %s %s %s %s }", family, weight, style, size);
539+
gtk_css_provider_load_from_data (provider, css, -1, NULL);
540+
541+
if (!provider_added) {
542+
gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (widget),
543+
GTK_STYLE_PROVIDER (provider),
544+
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
545+
provider_added = TRUE;
546+
}
547+
548+
g_free (css);
549+
g_free (family);
550+
g_free (weight);
551+
g_free (size);
552+
}
553+
509554
void mateweather_dialog_update(MateWeatherDialog* dialog)
510555
{
511556
MateWeatherDialogPrivate *priv;
@@ -546,7 +591,7 @@ void mateweather_dialog_update(MateWeatherDialog* dialog)
546591
if (gw_applet->mateweather_pref.location->zone_valid) {
547592
font_desc = get_system_monospace_font ();
548593
if (font_desc) {
549-
gtk_widget_override_font (priv->forecast_text, font_desc);
594+
override_widget_font (priv->forecast_text, font_desc);
550595
pango_font_description_free (font_desc);
551596
}
552597

0 commit comments

Comments
 (0)