From 8127525ab337944659c88b07b7ee24958db6b6f4 Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Mon, 21 May 2012 10:54:00 +0200 Subject: Set widgets orientation according to the panel orientation. This makes the plugin rotate its widgets in vertical mode and introduces support for panel-4.10 features, like the new deskbar mode. --- panel-plugin/datetime.c | 82 ++++++++++++++++++++++++++++++++++++++-------- panel-plugin/datetime.h | 2 +- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/panel-plugin/datetime.c b/panel-plugin/datetime.c index 30ee04a..aac90b2 100644 --- a/panel-plugin/datetime.c +++ b/panel-plugin/datetime.c @@ -40,6 +40,13 @@ #define DATETIME_MAX_STRLEN 256 +/* check for new Xfce 4.10 panel features */ +#ifdef LIBXFCE4PANEL_CHECK_VERSION +#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0) +#define HAS_PANEL_49 +#endif +#endif + /** * Convert a GTimeVal to milliseconds. * Fractions of a millisecond are truncated. @@ -442,13 +449,13 @@ void datetime_apply_layout(t_datetime *datetime, t_layout layout) switch(datetime->layout) { case LAYOUT_TIME_DATE: - gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->time_label, 0); - gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->date_label, 1); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->time_label, 0); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->date_label, 1); break; default: - gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->time_label, 1); - gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->date_label, 0); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->time_label, 1); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->date_label, 0); } datetime_set_update_interval(datetime); @@ -587,18 +594,53 @@ void datetime_write_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) } /* + * change widgets orientation when the panel orientation changes + */ +#ifdef HAS_PANEL_49 +static void datetime_set_mode(XfcePanelPlugin *plugin, XfcePanelPluginMode mode, t_datetime *datetime) +{ + GtkOrientation panel_orientation = xfce_panel_plugin_get_orientation (plugin); + GtkOrientation orientation = (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? + GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; +#else +static void datetime_set_orientation(XfcePanelPlugin *plugin, GtkOrientation orientation, t_datetime *datetime) +{ +#endif + if (orientation == GTK_ORIENTATION_VERTICAL) + { + xfce_hvbox_set_orientation(XFCE_HVBOX(datetime->box), GTK_ORIENTATION_HORIZONTAL); + gtk_label_set_angle(GTK_LABEL(datetime->time_label), -90); + gtk_label_set_angle(GTK_LABEL(datetime->date_label), -90); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->time_label, 0); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->date_label, 1); + } + else + { + xfce_hvbox_set_orientation(XFCE_HVBOX(datetime->box), GTK_ORIENTATION_VERTICAL); + gtk_label_set_angle(GTK_LABEL(datetime->time_label), 0); + gtk_label_set_angle(GTK_LABEL(datetime->date_label), 0); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->date_label, 0); + gtk_box_reorder_child(GTK_BOX(datetime->box), datetime->time_label, 1); + } +} + +/* * create the gtk-part of the datetime plugin */ static void datetime_create_widget(t_datetime * datetime) { + GtkOrientation orientation; + orientation = xfce_panel_plugin_get_orientation(datetime->plugin); + /* create button */ datetime->button = xfce_create_panel_toggle_button(); gtk_widget_show(datetime->button); - /* create vertical box */ - datetime->vbox = gtk_vbox_new(TRUE, 0); - gtk_widget_show(datetime->vbox); - gtk_container_add(GTK_CONTAINER(datetime->button), datetime->vbox); + /* create a box which can be easily adapted to the panel orientation */ + datetime->box = xfce_hvbox_new(GTK_ORIENTATION_VERTICAL, TRUE, 0); + + gtk_widget_show(datetime->box); + gtk_container_add(GTK_CONTAINER(datetime->button), datetime->box); /* create time and date lines */ datetime->time_label = gtk_label_new(""); @@ -606,17 +648,22 @@ static void datetime_create_widget(t_datetime * 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); - /* add time and date lines to the vbox */ - gtk_box_pack_start(GTK_BOX(datetime->vbox), + /* add time and date lines to the box */ + gtk_box_pack_start(GTK_BOX(datetime->box), datetime->time_label, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(datetime->vbox), + gtk_box_pack_start(GTK_BOX(datetime->box), datetime->date_label, FALSE, FALSE, 0); - gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->time_label, 0); - gtk_box_reorder_child(GTK_BOX(datetime->vbox), datetime->date_label, 1); /* connect widget signals to functions */ g_signal_connect(datetime->button, "button-press-event", G_CALLBACK(datetime_clicked), datetime); + + /* set orientation according to the panel orientation */ +#ifdef HAS_PANEL_49 + datetime_set_mode(datetime->plugin, orientation, datetime); +#else + datetime_set_orientation(datetime->plugin, orientation, datetime); +#endif } /* @@ -689,9 +736,14 @@ static void datetime_construct(XfcePanelPlugin *plugin) g_signal_connect(plugin, "free-data", G_CALLBACK(datetime_free), datetime); g_signal_connect(plugin, "size-changed", - G_CALLBACK (datetime_set_size), datetime); + G_CALLBACK(datetime_set_size), datetime); g_signal_connect(plugin, "configure-plugin", - G_CALLBACK (datetime_properties_dialog), datetime); + G_CALLBACK(datetime_properties_dialog), datetime); +#ifdef HAS_PANEL_49 + g_signal_connect(plugin, "mode-changed", G_CALLBACK(datetime_set_mode), datetime); +#else + g_signal_connect(plugin, "orientation-changed", G_CALLBACK(datetime_set_orientation), datetime); +#endif xfce_panel_plugin_menu_show_configure(plugin); } diff --git a/panel-plugin/datetime.h b/panel-plugin/datetime.h index 57de4b9..73aa4ed 100644 --- a/panel-plugin/datetime.h +++ b/panel-plugin/datetime.h @@ -43,7 +43,7 @@ typedef enum typedef struct { XfcePanelPlugin * plugin; GtkWidget *button; - GtkWidget *vbox; + GtkWidget *box; GtkWidget *date_label; GtkWidget *time_label; guint update_interval; /* time between updates in milliseconds */ -- 1.7.8.6