From 90d5f97a1e87aebbf87772ec5dba9e8a66a22cd6 Mon Sep 17 00:00:00 2001 From: Andrzej Date: Fri, 20 Jan 2012 01:50:25 +0900 Subject: [PATCH] Panel plugin: added support for changing orientation. New panel (4.9+) has two vertical modes, one with horizontal labels (deskbar mode) and one with vertical/rotated labels (vertical mode). This patch rotates clock labels to follow this convention. Also, labels (if there are more than 1) are no longer stretched in wide panels. --- panel-plugin/xfce4-orageclock-plugin.c | 63 +++++++++++++++++++++++++++++++- panel-plugin/xfce4-orageclock-plugin.h | 1 + 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/panel-plugin/xfce4-orageclock-plugin.c b/panel-plugin/xfce4-orageclock-plugin.c index 4a6ad8f..6575e47 100644 --- a/panel-plugin/xfce4-orageclock-plugin.c +++ b/panel-plugin/xfce4-orageclock-plugin.c @@ -306,6 +306,29 @@ static void oc_update_size(Clock *clock, int size) } } +static void oc_update_orientation(Clock *clock, GtkOrientation orientation) +{ + ClockLine *line; + GList *tmp_list; + + for (tmp_list = g_list_first(clock->lines); + tmp_list; + tmp_list = g_list_next(tmp_list)) { + line = tmp_list->data; + if (orientation == GTK_ORIENTATION_VERTICAL) { + gtk_box_reorder_child(GTK_BOX(clock->vbox), line->label, -1); + } else { + gtk_box_reorder_child(GTK_BOX(clock->vbox), line->label, 0); + } + gtk_label_set_angle(GTK_LABEL(line->label), + orientation == GTK_ORIENTATION_VERTICAL ? + 0 : 270); + } + + gtk_orientable_set_orientation (GTK_ORIENTABLE (clock->vbox), orientation); + gtk_orientable_set_orientation (GTK_ORIENTABLE (clock->outer_vbox), orientation); +} + static gboolean popup_program(GtkWidget *widget, gchar *program, Clock *clock , guint event_time) { @@ -405,6 +428,20 @@ static gboolean oc_set_size(XfcePanelPlugin *plugin, int size, Clock *clock) return(TRUE); } +#if defined(LIBXFCE4PANEL_CHECK_VERSION) && LIBXFCE4PANEL_CHECK_VERSION (4,9,0) +static void oc_set_mode(XfcePanelPlugin *plugin, XfcePanelPluginMode mode, Clock *clock) +{ + GtkOrientation orientation; + + orientation = + (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? + GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; + + oc_update_orientation(clock, orientation); + oc_update_size(clock, xfce_panel_plugin_get_size(plugin)); +} +#endif + static void oc_free_data(XfcePanelPlugin *plugin, Clock *clock) { GtkWidget *dlg = g_object_get_data(G_OBJECT(plugin), "dialog"); @@ -600,9 +637,14 @@ Clock *orage_oc_new(XfcePanelPlugin *plugin) gtk_container_add(GTK_CONTAINER(clock->ebox), clock->frame); gtk_widget_show(clock->frame); + clock->outer_vbox = gtk_vbox_new(TRUE, 0); + gtk_widget_show(clock->outer_vbox); + gtk_container_add(GTK_CONTAINER(clock->frame), clock->outer_vbox); + clock->vbox = gtk_vbox_new(TRUE, 0); gtk_widget_show(clock->vbox); - gtk_container_add(GTK_CONTAINER(clock->frame), clock->vbox); + gtk_box_pack_start(GTK_BOX(clock->outer_vbox), clock->vbox, + TRUE, FALSE, 0); clock->show_frame = TRUE; clock->fg_set = FALSE; @@ -696,6 +738,10 @@ static void oc_construct(XfcePanelPlugin *plugin) { Clock *clock; +#if defined(LIBXFCE4PANEL_CHECK_VERSION) && LIBXFCE4PANEL_CHECK_VERSION (4,9,0) + GtkOrientation orientation; +#endif + xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); clock = orage_oc_new(plugin); @@ -714,6 +760,14 @@ static void oc_construct(XfcePanelPlugin *plugin) oc_init_timer(clock); +#if defined(LIBXFCE4PANEL_CHECK_VERSION) && LIBXFCE4PANEL_CHECK_VERSION (4,9,0) + orientation = + (xfce_panel_plugin_get_mode(plugin) == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? + GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; + + oc_update_orientation(clock, orientation); +#endif + oc_update_size(clock, xfce_panel_plugin_get_size(XFCE_PANEL_PLUGIN(plugin))); @@ -726,7 +780,12 @@ static void oc_construct(XfcePanelPlugin *plugin) g_signal_connect(plugin, "size-changed", G_CALLBACK(oc_set_size), clock); - + +#if defined(LIBXFCE4PANEL_CHECK_VERSION) && LIBXFCE4PANEL_CHECK_VERSION (4,9,0) + g_signal_connect(plugin, "mode-changed", + G_CALLBACK(oc_set_mode), clock); +#endif + g_signal_connect(plugin, "free-data", G_CALLBACK(oc_free_data), clock); diff --git a/panel-plugin/xfce4-orageclock-plugin.h b/panel-plugin/xfce4-orageclock-plugin.h index 7b923e7..16a6448 100644 --- a/panel-plugin/xfce4-orageclock-plugin.h +++ b/panel-plugin/xfce4-orageclock-plugin.h @@ -30,6 +30,7 @@ typedef struct _clock GtkWidget *ebox; GtkWidget *frame; + GtkWidget *outer_vbox; GtkWidget *vbox; gboolean show_frame; gboolean fg_set; -- 1.7.5.4