Skip to content
Permalink
Browse files

Clock: ensure weather icon resizes with panel

Connect to the "change_size" signal and reload the icon at the correct size
  • Loading branch information...
lukefromdc committed Dec 31, 2018
1 parent 9484b05 commit 8d0f753559918251d5ba3a841803e5369a90bb17
Showing with 37 additions and 4 deletions.
  1. +37 −4 applets/clock/clock.c
@@ -179,6 +179,8 @@ struct _ClockData {
gboolean can_handle_format_12;

GSettings *settings;

const gchar *weather_icon_name;
};

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

static void
weather_icon_updated_cb (MatePanelApplet *applet,
gint icon_size,
gpointer data)
{
ClockData *cd = data;
GtkIconTheme *theme;
cairo_surface_t *surface;
gint icon_scale;

if (cd->weather_icon_name == NULL)
return;

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

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

surface = gtk_icon_theme_load_surface (theme, cd->weather_icon_name, icon_size, icon_scale,
NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);

gtk_image_set_from_surface (GTK_IMAGE (cd->panel_weather_icon), surface);

cairo_surface_destroy (surface);
}

static void
location_weather_updated_cb (ClockLocation *location,
WeatherInfo *info,
gpointer data)
{
ClockData *cd = data;
const gchar *icon_name;
const gchar *temp;
GtkIconTheme *theme;
cairo_surface_t *surface;
@@ -1987,16 +2014,16 @@ location_weather_updated_cb (ClockLocation *location,
if (!clock_location_is_current (location))
return;

icon_name = weather_info_get_icon_name (info);
if (icon_name == NULL)
cd->weather_icon_name = weather_info_get_icon_name (info);
if (cd->weather_icon_name == NULL)
return;

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

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

surface = gtk_icon_theme_load_surface (theme, icon_name, icon_size, icon_scale,
surface = gtk_icon_theme_load_surface (theme, cd->weather_icon_name, icon_size, icon_scale,
NULL, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);

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

/* Make sure the weather icon gets updated when the panel size changes*/
g_signal_connect (cd->applet,
"change_size",
G_CALLBACK (weather_icon_updated_cb),
cd);

return TRUE;
}

0 comments on commit 8d0f753

Please sign in to comment.
You can’t perform that action at this time.