aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-datetime.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-03-01 15:15:07 -0600
committerTed Gould <ted@gould.cx>2010-03-01 15:15:07 -0600
commit5f455da15e21b95a8f8d5d4fdb5168e880d5e0b0 (patch)
tree3cdabafeb17d44a0cedca973a1cd35f3de519041 /src/indicator-datetime.c
parent21c86ebac1e28b32a1ce6908e9b76ab401a99205 (diff)
downloadayatana-indicator-datetime-5f455da15e21b95a8f8d5d4fdb5168e880d5e0b0.tar.gz
ayatana-indicator-datetime-5f455da15e21b95a8f8d5d4fdb5168e880d5e0b0.tar.bz2
ayatana-indicator-datetime-5f455da15e21b95a8f8d5d4fdb5168e880d5e0b0.zip
Adding in an idle function to try and make it so the label never shrinks
Diffstat (limited to 'src/indicator-datetime.c')
-rw-r--r--src/indicator-datetime.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index 00854a4..1fd559b 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -37,6 +37,9 @@ struct _IndicatorDatetimePrivate {
GtkMenuItem * date;
GtkMenuItem * calendar;
guint timer;
+
+ guint idle_measure;
+ gint max_width;
};
#define INDICATOR_DATETIME_GET_PRIVATE(o) \
@@ -85,6 +88,9 @@ indicator_datetime_init (IndicatorDatetime *self)
self->priv->calendar = NULL;
self->priv->timer = 0;
+ self->priv->idle_measure = 0;
+ self->priv->max_width = 0;
+
return;
}
@@ -113,6 +119,11 @@ indicator_datetime_dispose (GObject *object)
self->priv->timer = 0;
}
+ if (self->priv->idle_measure != 0) {
+ g_source_remove(self->priv->idle_measure);
+ self->priv->idle_measure = 0;
+ }
+
G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object);
return;
}
@@ -125,6 +136,28 @@ indicator_datetime_finalize (GObject *object)
return;
}
+/* Looks at the size of the label, if it grew beyond what we
+ thought was the max, make sure it doesn't shrink again. */
+static gboolean
+idle_measure (gpointer data)
+{
+ IndicatorDatetime * self = INDICATOR_DATETIME(data);
+ self->priv->idle_measure = 0;
+
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(GTK_WIDGET(self->priv->label), &allocation);
+
+ if (allocation.width > self->priv->max_width) {
+ if (self->priv->max_width != 0) {
+ g_warning("Guessed wrong. We thought the max would be %d but we're now at %d", self->priv->max_width, allocation.width);
+ }
+ self->priv->max_width = allocation.width;
+ gtk_widget_set_size_request(GTK_WIDGET(self->priv->label), self->priv->max_width, -1);
+ }
+
+ return FALSE;
+}
+
/* Updates the label to be the current time. */
static void
update_label (IndicatorDatetime * io)
@@ -151,6 +184,10 @@ update_label (IndicatorDatetime * io)
gtk_label_set_label(self->priv->label, utf8);
g_free(utf8);
+ if (self->priv->idle_measure == 0) {
+ self->priv->idle_measure = g_idle_add(idle_measure, io);
+ }
+
if (self->priv->date == NULL) return;
/* Note: may require some localization tweaks */