From 458315df723f211956edcbbf96e8c84acc9da06c Mon Sep 17 00:00:00 2001 From: lukefromdc Date: Fri, 27 Oct 2017 00:40:50 -0400 Subject: Stop jumping applet as numbers change Hold the value labels to the largest size they have been unless the units have just been shown or hidden. --- sensors-applet/active-sensor.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'sensors-applet') diff --git a/sensors-applet/active-sensor.c b/sensors-applet/active-sensor.c index 78d03b6..f4097a3 100644 --- a/sensors-applet/active-sensor.c +++ b/sensors-applet/active-sensor.c @@ -493,8 +493,11 @@ void active_sensor_update(ActiveSensor *active_sensor, gdouble sensor_multiplier; gdouble sensor_offset; gdouble sensor_value; - GdkPixbuf *icon_pixbuf; - gchar *graph_color; + GdkPixbuf *icon_pixbuf; + gchar *graph_color; + gint label_min_width; + gint label_width; + GtkRequisition req; /* to build the list of labels as we go */ gchar *value_text = NULL; @@ -511,6 +514,7 @@ void active_sensor_update(ActiveSensor *active_sensor, /* hidden gsettings options */ gint font_size = 0; gboolean hide_units = FALSE; + gboolean hide_units_old = FALSE; g_assert(active_sensor); g_assert(active_sensor->sensor_row); @@ -565,7 +569,7 @@ void active_sensor_update(ActiveSensor *active_sensor, sensor_value = -1; } else { /* use hidden gsettings key for hide_units */ - + hide_units_old = hide_units; hide_units = g_settings_get_boolean(sensors_applet->settings, HIDE_UNITS); /* scale value and set text using this @@ -713,8 +717,22 @@ void active_sensor_update(ActiveSensor *active_sensor, value_text = g_strdup_printf("%s", font_size, old_value_text); g_free(old_value_text); } + /*Keep the label as large as previous size unless hide_units has changed */ + gtk_widget_get_preferred_size (GTK_WIDGET (active_sensor->value), + &req, NULL); + if (!(hide_units_old == hide_units)){ + label_min_width = 0; + } + else{ + label_min_width = req.width; + } gtk_label_set_markup(GTK_LABEL(active_sensor->value), value_text); + gtk_widget_get_preferred_size (GTK_WIDGET (active_sensor->value), + &req, NULL); + label_width = MAX(req.width, label_min_width); + gtk_widget_set_size_request (GTK_WIDGET (active_sensor->value), + label_min_width, req.height); if (tooltip) { gtk_widget_set_tooltip_text(active_sensor->value, tooltip); -- cgit v1.2.1