From ca120fd455b1a5dca2d855556875f5b5c2f2b142 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 19 Oct 2010 20:06:30 +0200 Subject: [PATCH] don't overflow narrow panel with date string When selecting the "time and date" format and then switching to a vertical panel, the date gets cropped. The "proper" fix is for the user to change the plugin configuration to "time only" or to widen the panel so that the date string will fit. This patch adds some automatism for making vertical panels "just work" with any size, without the need to reconfigure the plugin. This patch hides the date whenever there is too little space to display it. http://bugzilla.xfce.org/show_bug.cgi?id=6739 --- panel-plugin/datetime.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/panel-plugin/datetime.c b/panel-plugin/datetime.c index 30ee04a..5267cf8 100644 --- a/panel-plugin/datetime.c +++ b/panel-plugin/datetime.c @@ -128,6 +128,21 @@ static gboolean datetime_format_has_seconds(const gchar *format) return len1 != len2 || strcmp(buf1, buf2) != 0; } +static gboolean date_label_allocate(GtkWidget *widget, + GtkAllocation *alloc, + t_datetime *datetime) +{ + GtkRequisition req; + gtk_widget_size_request (widget, &req); + + if (alloc->width > 1 && req.width >= alloc->width) + { + g_debug("date_label_allocate: we are too narrow (allocated width %i, reqested with %i), hiding date", alloc->width, req.width); + gtk_label_set_text(GTK_LABEL(widget), ""); + } + return TRUE; +} + /* * set date and time labels */ @@ -508,6 +523,7 @@ static int datetime_set_size(XfcePanelPlugin *plugin, gint size, t_datetime *datetime) { + datetime_update(datetime); /* return true to please the signal handler ;) */ return TRUE; } @@ -603,6 +619,8 @@ static void datetime_create_widget(t_datetime * datetime) /* create time and date lines */ datetime->time_label = gtk_label_new(""); datetime->date_label = gtk_label_new(""); + gtk_signal_connect(GTK_OBJECT(datetime->date_label), "size-allocate", + G_CALLBACK(date_label_allocate), datetime); gtk_label_set_justify(GTK_LABEL(datetime->time_label), GTK_JUSTIFY_CENTER); gtk_label_set_justify(GTK_LABEL(datetime->date_label), GTK_JUSTIFY_CENTER); -- 1.7.1