Skip to content

Commit 8d0f753

Browse files
committed
Clock: ensure weather icon resizes with panel
Connect to the "change_size" signal and reload the icon at the correct size
1 parent 9484b05 commit 8d0f753

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

applets/clock/clock.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ struct _ClockData {
179179
gboolean can_handle_format_12;
180180

181181
GSettings *settings;
182+
183+
const gchar *weather_icon_name;
182184
};
183185

184186
/* Used to count the number of clock instances. It's there to know when we
@@ -1969,13 +1971,38 @@ show_temperature_changed (GSettings *settings,
19691971
update_weather_bool_value_and_toggle_from_gsettings (cd, key, &cd->show_temperature, "temperature_check");
19701972
}
19711973

1974+
static void
1975+
weather_icon_updated_cb (MatePanelApplet *applet,
1976+
gint icon_size,
1977+
gpointer data)
1978+
{
1979+
ClockData *cd = data;
1980+
GtkIconTheme *theme;
1981+
cairo_surface_t *surface;
1982+
gint icon_scale;
1983+
1984+
if (cd->weather_icon_name == NULL)
1985+
return;
1986+
1987+
theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (cd->applet)));
1988+
1989+
icon_size = mate_panel_applet_get_size (MATE_PANEL_APPLET (cd->applet));
1990+
icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (cd->applet));
1991+
1992+
surface = gtk_icon_theme_load_surface (theme, cd->weather_icon_name, icon_size, icon_scale,
1993+
NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
1994+
1995+
gtk_image_set_from_surface (GTK_IMAGE (cd->panel_weather_icon), surface);
1996+
1997+
cairo_surface_destroy (surface);
1998+
}
1999+
19722000
static void
19732001
location_weather_updated_cb (ClockLocation *location,
19742002
WeatherInfo *info,
19752003
gpointer data)
19762004
{
19772005
ClockData *cd = data;
1978-
const gchar *icon_name;
19792006
const gchar *temp;
19802007
GtkIconTheme *theme;
19812008
cairo_surface_t *surface;
@@ -1987,16 +2014,16 @@ location_weather_updated_cb (ClockLocation *location,
19872014
if (!clock_location_is_current (location))
19882015
return;
19892016

1990-
icon_name = weather_info_get_icon_name (info);
1991-
if (icon_name == NULL)
2017+
cd->weather_icon_name = weather_info_get_icon_name (info);
2018+
if (cd->weather_icon_name == NULL)
19922019
return;
19932020

19942021
theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (cd->applet)));
19952022

19962023
icon_size = mate_panel_applet_get_size (MATE_PANEL_APPLET (cd->applet));
19972024
icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (cd->applet));
19982025

1999-
surface = gtk_icon_theme_load_surface (theme, icon_name, icon_size, icon_scale,
2026+
surface = gtk_icon_theme_load_surface (theme, cd->weather_icon_name, icon_size, icon_scale,
20002027
NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
20012028

20022029
temp = weather_info_get_temp_summary (info);
@@ -2455,6 +2482,12 @@ fill_clock_applet (MatePanelApplet *applet)
24552482
gtk_action_set_visible (action, can_set_system_time ());
24562483
g_object_unref (action_group);
24572484

2485+
/* Make sure the weather icon gets updated when the panel size changes*/
2486+
g_signal_connect (cd->applet,
2487+
"change_size",
2488+
G_CALLBACK (weather_icon_updated_cb),
2489+
cd);
2490+
24582491
return TRUE;
24592492
}
24602493

0 commit comments

Comments
 (0)