From 22fbf68f4d5b7c6e517a61450de1e3d8025e613b Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Thu, 24 May 2012 17:17:01 +0200 Subject: Support deskbar mode (for >=xfce4-panel-4.9). This makes the plugin adapt its widgets for the deskbar mode when supported by the panel. --- panel-plugin/netload.c | 77 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 68 insertions(+), 9 deletions(-) diff --git a/panel-plugin/netload.c b/panel-plugin/netload.c index 5517d68..a45fa86 100644 --- a/panel-plugin/netload.c +++ b/panel-plugin/netload.c @@ -33,6 +33,11 @@ #include #include +#ifdef LIBXFCE4PANEL_CHECK_VERSION +#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0) +#define HAS_PANEL_49 +#endif +#endif #define BORDER 8 #define LABEL_SIZE 60 @@ -144,8 +149,13 @@ typedef struct } t_global_monitor; +#ifdef HAS_PANEL_49 +static void monitor_set_mode (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, + t_global_monitor *global); +#else static void monitor_set_orientation (XfcePanelPlugin *plugin, GtkOrientation orientation, t_global_monitor *global); +#endif static gboolean monitor_set_size(XfcePanelPlugin *plugin, int size, t_global_monitor *global); static void setup_monitor(t_global_monitor *global, gboolean supress_warnings); @@ -292,18 +302,41 @@ static void run_update (t_global_monitor *global) /* ---------------------------------------------------------------------------------------------- */ +#ifdef HAS_PANEL_49 +static void monitor_set_mode (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, + t_global_monitor *global) +{ + GtkOrientation orientation = (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? + GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; + +#else static void monitor_set_orientation (XfcePanelPlugin *plugin, GtkOrientation orientation, t_global_monitor *global) { +#endif + gint i; if (global->timeout_id) - { g_source_remove(global->timeout_id); - } xfce_hvbox_set_orientation(XFCE_HVBOX(global->box), orientation); - if (orientation != GTK_ORIENTATION_VERTICAL) + +#ifdef HAS_PANEL_49 + if (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) + { + xfce_hvbox_set_orientation(XFCE_HVBOX(global->box), GTK_ORIENTATION_VERTICAL); + gtk_label_set_angle(GTK_LABEL(global->monitor->label), 0); + gtk_misc_set_alignment(GTK_MISC(global->monitor->rcv_label), 0.5f, 1.0f); + gtk_misc_set_alignment(GTK_MISC(global->monitor->sent_label), 0.5f, 0.0f); + gtk_label_set_angle(GTK_LABEL(global->monitor->rcv_label), 0); + gtk_label_set_angle(GTK_LABEL(global->monitor->sent_label), 0); + for (i = 0; i < SUM; i++) + gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(global->monitor->status[i]), + GTK_PROGRESS_LEFT_TO_RIGHT); + } else +#endif + if (orientation == GTK_ORIENTATION_HORIZONTAL) { gtk_label_set_angle(GTK_LABEL(global->monitor->label), 0); gtk_misc_set_alignment(GTK_MISC(global->monitor->rcv_label), 1.0f, 0.5f); @@ -311,12 +344,10 @@ static void monitor_set_orientation (XfcePanelPlugin *plugin, GtkOrientation ori gtk_label_set_angle(GTK_LABEL(global->monitor->rcv_label), 0); gtk_label_set_angle(GTK_LABEL(global->monitor->sent_label), 0); for (i = 0; i < SUM; i++) - { gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(global->monitor->status[i]), GTK_PROGRESS_BOTTOM_TO_TOP); - } } - else + else /* (orientation == GTK_ORIENTATION_VERTICAL) */ { gtk_label_set_angle(GTK_LABEL(global->monitor->label), 270); gtk_label_set_angle(GTK_LABEL(global->monitor->rcv_label), 270); @@ -324,10 +355,8 @@ static void monitor_set_orientation (XfcePanelPlugin *plugin, GtkOrientation ori gtk_misc_set_alignment(GTK_MISC(global->monitor->rcv_label), 0.5f, 1.0f); gtk_misc_set_alignment(GTK_MISC(global->monitor->sent_label), 0.5f, 0.0f); for (i = 0; i < SUM; i++) - { gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(global->monitor->status[i]), GTK_PROGRESS_LEFT_TO_RIGHT); - } } monitor_set_size(plugin, xfce_panel_plugin_get_size(plugin), global); run_update( global ); @@ -449,7 +478,11 @@ static t_global_monitor * monitor_new(XfcePanelPlugin *plugin) static void setup_monitor(t_global_monitor *global, gboolean supress_warnings) { gint i; +#ifdef HAS_PANEL_49 + XfcePanelPluginMode orientation = xfce_panel_plugin_get_mode(global->plugin); +#else GtkOrientation orientation = xfce_panel_plugin_get_orientation(global->plugin); +#endif if (global->timeout_id) g_source_remove(global->timeout_id); @@ -541,7 +574,11 @@ static void setup_monitor(t_global_monitor *global, gboolean supress_warnings) } global->monitor->options.old_network_device = g_strdup(global->monitor->options.network_device); +#ifdef HAS_PANEL_49 + monitor_set_mode(global->plugin, orientation, global); +#else monitor_set_orientation(global->plugin, orientation, global); +#endif run_update( global ); } @@ -670,8 +707,26 @@ static void monitor_write_config(XfcePanelPlugin *plugin, t_global_monitor *glob static gboolean monitor_set_size(XfcePanelPlugin *plugin, int size, t_global_monitor *global) { gint i; +#ifdef HAS_PANEL_49 + XfcePanelPluginMode mode = xfce_panel_plugin_get_mode(plugin); - if (xfce_panel_plugin_get_orientation (plugin) != GTK_ORIENTATION_VERTICAL) + /* Set small in all modes except deskbar mode */ + if (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) + xfce_panel_plugin_set_small(XFCE_PANEL_PLUGIN(plugin), FALSE); + else + xfce_panel_plugin_set_small(XFCE_PANEL_PLUGIN(plugin), TRUE); + + if (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR) + { + for (i = 0; i < SUM; i++) + gtk_widget_set_size_request(GTK_WIDGET(global->monitor->status[i]), + -1, PROGRESS_BAR_SIZE); + gtk_widget_set_size_request(GTK_WIDGET(global->monitor->rcv_label), size, -1); + gtk_widget_set_size_request(GTK_WIDGET(global->monitor->sent_label), size, -1); + gtk_widget_set_size_request(GTK_WIDGET(plugin), size, -1); + } else +#endif + if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL) { for (i = 0; i < SUM; i++) gtk_widget_set_size_request(GTK_WIDGET(global->monitor->status[i]), @@ -1245,7 +1300,11 @@ static void netload_construct (XfcePanelPlugin *plugin) g_signal_connect (plugin, "size-changed", G_CALLBACK (monitor_set_size), global); +#ifdef HAS_PANEL_49 + g_signal_connect (plugin, "mode-changed", G_CALLBACK (monitor_set_mode), global); +#else g_signal_connect (plugin, "orientation-changed", G_CALLBACK (monitor_set_orientation), global); +#endif gtk_container_add(GTK_CONTAINER(plugin), global->ebox); -- 1.7.8.6