From a15746b9e73355c16750bd95c4a6ddc73e26d1ac Mon Sep 17 00:00:00 2001 From: Pablo Barciela Date: Sun, 8 Jul 2018 14:56:11 +0200 Subject: mateweather-dialog.c: avoid deprecated 'gtk_widget_override_font' --- mateweather/mateweather-dialog.c | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/mateweather/mateweather-dialog.c b/mateweather/mateweather-dialog.c index 8bdfc2e0..0c4ee3c9 100644 --- a/mateweather/mateweather-dialog.c +++ b/mateweather/mateweather-dialog.c @@ -506,6 +506,51 @@ static PangoFontDescription* get_system_monospace_font(void) return desc; } +static void +override_widget_font (GtkWidget *widget, + PangoFontDescription *font) +{ + static gboolean provider_added = FALSE; + GtkCssProvider *provider; + gchar *css; + gchar *family; + gchar *weight; + const gchar *style; + gchar *size; + + family = g_strdup_printf ("font-family: %s;", pango_font_description_get_family (font)); + + weight = g_strdup_printf ("font-weight: %d;", pango_font_description_get_weight (font)); + + if (pango_font_description_get_style (font) == PANGO_STYLE_NORMAL) + style = "font-style: normal;"; + else if (pango_font_description_get_style (font) == PANGO_STYLE_ITALIC) + style = "font-style: italic;"; + else + style = "font-style: oblique;"; + + size = g_strdup_printf ("font-size: %d%s;", + pango_font_description_get_size (font) / PANGO_SCALE, + pango_font_description_get_size_is_absolute (font) ? "px" : "pt"); + + provider = gtk_css_provider_get_default (); + + css = g_strdup_printf ("textview { %s %s %s %s }", family, weight, style, size); + gtk_css_provider_load_from_data (provider, css, -1, NULL); + + if (!provider_added) { + gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (widget), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + provider_added = TRUE; + } + + g_free (css); + g_free (family); + g_free (weight); + g_free (size); +} + void mateweather_dialog_update(MateWeatherDialog* dialog) { MateWeatherDialogPrivate *priv; @@ -546,7 +591,7 @@ void mateweather_dialog_update(MateWeatherDialog* dialog) if (gw_applet->mateweather_pref.location->zone_valid) { font_desc = get_system_monospace_font (); if (font_desc) { - gtk_widget_override_font (priv->forecast_text, font_desc); + override_widget_font (priv->forecast_text, font_desc); pango_font_description_free (font_desc); } -- cgit v1.2.1