[Xfce4-commits] <xfce4-weather-plugin:master> Better handle single row and icon size in various panel modes.

Harald Judt noreply at xfce.org
Mon Mar 4 22:38:01 CET 2013


Updating branch refs/heads/master
         to a8ad9a7010e01f071f7cce797b06cd0d247c768e (commit)
       from 0d039920249e578bf464b84f6c7647a63f4e5cb0 (commit)

commit a8ad9a7010e01f071f7cce797b06cd0d247c768e
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Feb 25 22:35:51 2013 +0100

    Better handle single row and icon size in various panel modes.
    
    Add an option to set the single row property manually, defaulting to TRUE.
    In deskbar mode, enabling this means that the icon will always be in the same
    "row" as the scrollbox, and never get bigger than one row.
    
    If there are more than two rows, the icon will be scaled to 80%. This is
    just an arbitrary value, but most icons tend to look better if they do not
    fill the whole panel at bigger sizes.

 panel-plugin/weather-config.c |   38 +++++++++++++++++++++++++++++++++
 panel-plugin/weather-config.h |    1 +
 panel-plugin/weather-debug.c  |    8 +++---
 panel-plugin/weather.c        |   47 ++++++++++++++++++++++------------------
 panel-plugin/weather.h        |   10 +++++++-
 5 files changed, 77 insertions(+), 27 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 4161cbd..c2468f6 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -1088,6 +1088,21 @@ combo_icon_theme_changed(GtkWidget *combo,
 
 
 static void
+check_single_row_toggled(GtkWidget *button,
+                         gpointer user_data)
+{
+    xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
+    dialog->pd->single_row =
+        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
+#if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
+    xfceweather_set_mode(dialog->pd->plugin,
+                         xfce_panel_plugin_get_mode(dialog->pd->plugin),
+                         dialog->pd);
+#endif
+}
+
+
+static void
 combo_tooltip_style_changed(GtkWidget *combo,
                             gpointer user_data)
 {
@@ -1188,8 +1203,26 @@ create_appearance_page(xfceweather_dialog *dialog)
         }
     }
 
+    /* always use small icon in panel */
+    hbox = gtk_hbox_new(FALSE, BORDER);
+    dialog->check_single_row =
+        gtk_check_button_new_with_mnemonic(_("Use only a single _panel row"));
+    SET_TOOLTIP(dialog->check_single_row,
+                _("Check to always use only a single row on a multi-row panel "
+                  "and a small icon in deskbar mode."));
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->check_single_row),
+                                 dialog->pd->single_row);
+    gtk_box_pack_start(GTK_BOX(hbox), dialog->check_single_row,
+                       FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 0);
+
+    sep = gtk_hseparator_new();
+    gtk_box_pack_start(GTK_BOX(page), sep, FALSE, FALSE, BORDER * 2);
+
     /* tooltip style */
     hbox = gtk_hbox_new(FALSE, BORDER);
+    vbox = gtk_vbox_new(FALSE, BORDER);
     ADD_LABEL(_("_Tooltip style:"), sg);
     ADD_COMBO(dialog->combo_tooltip_style);
     ADD_COMBO_VALUE(dialog->combo_tooltip_style, _("Simple"));
@@ -1951,6 +1984,8 @@ setup_notebook_signals(xfceweather_dialog *dialog)
     /* appearance page */
     g_signal_connect(dialog->combo_icon_theme, "changed",
                      G_CALLBACK(combo_icon_theme_changed), dialog);
+    g_signal_connect(dialog->check_single_row, "toggled",
+                     G_CALLBACK(check_single_row_toggled), dialog);
     g_signal_connect(dialog->combo_tooltip_style, "changed",
                      G_CALLBACK(combo_tooltip_style_changed), dialog);
     g_signal_connect(dialog->combo_forecast_layout, "changed",
@@ -2021,6 +2056,9 @@ create_config_dialog(plugin_data *data,
     gtk_box_pack_start(GTK_BOX(vbox), dialog->notebook, TRUE, TRUE, 0);
     gtk_widget_show(GTK_WIDGET(vbox));
     gtk_widget_hide(GTK_WIDGET(dialog->update_spinner));
+#if !LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
+    gtk_widget_hide(GTK_WIDGET(dialog->check_single_row));
+#endif
 
     /* automatically detect current location if it is yet unknown */
     if (!(dialog->pd->lat && dialog->pd->lon))
diff --git a/panel-plugin/weather-config.h b/panel-plugin/weather-config.h
index edfaeb8..4c8def5 100644
--- a/panel-plugin/weather-config.h
+++ b/panel-plugin/weather-config.h
@@ -56,6 +56,7 @@ typedef struct {
     GtkWidget *combo_forecast_layout;
     GtkWidget *spin_forecast_days;
     GtkWidget *check_round_values;
+    GtkWidget *check_single_row;
 
     /* scrollbox page */
     GtkWidget *check_scrollbox_show;
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index df671f2..288e766 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -405,9 +405,9 @@ weather_dump_plugindata(const plugin_data *data)
     g_string_append_printf(out,
                            "  --------------------------------------------\n"
                            "  panel size: %d px\n"
-                           "  plugin size: %d px\n"
+                           "  panel rows: %d px\n"
+                           "  single row: %s\n"
                            "  panel orientation: %d\n"
-                           "  plugin orientation: %d\n"
                            "  --------------------------------------------\n"
 #ifdef HAVE_UPOWER_GLIB
                            "  upower on battery: %s\n"
@@ -450,9 +450,9 @@ weather_dump_plugindata(const plugin_data *data)
                            "  animate scrollbox: %s\n"
                            "  --------------------------------------------",
                            data->panel_size,
-                           data->size,
+                           data->panel_rows,
+                           YESNO(data->single_row),
                            data->panel_orientation,
-                           data->orientation,
 #ifdef HAVE_UPOWER_GLIB
                            YESNO(data->upower_on_battery),
                            YESNO(data->upower_lid_closed),
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 2e15565..8dfeb15 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -288,12 +288,11 @@ update_icon(plugin_data *data)
     gchar *str;
     gint size;
 
-    size = data->size;
+    size = data->panel_size;
 #if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
-    /* make icon double-size in deskbar mode */
-    if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_DESKBAR &&
-        data->size != data->panel_size)
-        size *= 2;
+    /* make icon smaller when not single-row in multi-row panels */
+    if (!data->single_row && data->panel_rows > 2)
+        size *= 0.80;
 #endif
     /* take into account the border of the toggle button */
     size -= 2;
@@ -855,6 +854,8 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
 
     data->round = xfce_rc_read_bool_entry(rc, "round", TRUE);
 
+    data->single_row = xfce_rc_read_bool_entry(rc, "single_row", TRUE);
+
     data->tooltip_style = xfce_rc_read_int_entry(rc, "tooltip_style",
                                                  TOOLTIP_VERBOSE);
 
@@ -964,6 +965,8 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
 
     xfce_rc_write_bool_entry(rc, "round", data->round);
 
+    xfce_rc_write_bool_entry(rc, "single_row", data->single_row);
+
     xfce_rc_write_int_entry(rc, "tooltip_style", data->tooltip_style);
 
     xfce_rc_write_int_entry(rc, "forecast_layout", data->forecast_layout);
@@ -1790,7 +1793,8 @@ xfceweather_create_control(XfcePanelPlugin *plugin)
 
     data->scrollbox = gtk_scrollbox_new();
 
-    data->size = xfce_panel_plugin_get_size(plugin);
+    data->panel_size = xfce_panel_plugin_get_size(plugin);
+    data->panel_rows = xfce_panel_plugin_get_nrows(plugin);
     data->icon_theme = icon_theme_load(NULL);
     icon = get_icon(data->icon_theme, NULL, 16, FALSE);
     if (G_LIKELY(icon)) {
@@ -1914,11 +1918,12 @@ xfceweather_set_size(XfcePanelPlugin *panel,
                      gint size,
                      plugin_data *data)
 {
-    data->panel_size = size;
 #if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
-    size /= xfce_panel_plugin_get_nrows(panel);
+    data->panel_rows = xfce_panel_plugin_get_nrows(panel);
+    if (data->single_row)
+        size /= data->panel_rows;
 #endif
-    data->size = size;
+    data->panel_size = size;
 
     update_icon(data);
     update_scrollbox(data, FALSE);
@@ -1931,16 +1936,16 @@ xfceweather_set_size(XfcePanelPlugin *panel,
 
 
 #if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
-static gboolean
+gboolean
 xfceweather_set_mode(XfcePanelPlugin *panel,
                      XfcePanelPluginMode mode,
                      plugin_data *data)
 {
     data->panel_orientation = xfce_panel_plugin_get_mode(panel);
-    data->orientation = (mode != XFCE_PANEL_PLUGIN_MODE_VERTICAL)
-        ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
 
-    if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) {
+    if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL ||
+        (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_DESKBAR &&
+         data->single_row)) {
         xfce_hvbox_set_orientation(XFCE_HVBOX(data->alignbox),
                                    GTK_ORIENTATION_HORIZONTAL);
         gtk_misc_set_alignment(GTK_MISC(data->iconimage), 1, 0.5);
@@ -1950,16 +1955,17 @@ xfceweather_set_mode(XfcePanelPlugin *panel,
         gtk_misc_set_alignment(GTK_MISC(data->iconimage), 0.5, 1);
     }
 
-    if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
-        xfce_panel_plugin_set_small(XFCE_PANEL_PLUGIN(panel), FALSE);
+    if (mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
+        xfce_panel_plugin_set_small(panel, FALSE);
     else
-        xfce_panel_plugin_set_small(XFCE_PANEL_PLUGIN(panel), TRUE);
+        xfce_panel_plugin_set_small(panel, data->single_row);
 
     gtk_scrollbox_set_orientation(GTK_SCROLLBOX(data->scrollbox),
-                                  data->orientation);
+                                  (mode != XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+                                  ? GTK_ORIENTATION_HORIZONTAL
+                                  : GTK_ORIENTATION_VERTICAL);
 
-    update_icon(data);
-    update_scrollbox(data, FALSE);
+    xfceweather_set_size(panel, xfce_panel_plugin_get_size(panel), data);
 
     weather_dump(weather_dump_plugindata, data);
 
@@ -1976,7 +1982,6 @@ xfceweather_set_orientation(XfcePanelPlugin *panel,
                             GtkOrientation orientation,
                             plugin_data *data)
 {
-    data->orientation = GTK_ORIENTATION_HORIZONTAL;
     data->panel_orientation = orientation;
 
     if (data->panel_orientation == GTK_ORIENTATION_HORIZONTAL) {
@@ -2068,7 +2073,7 @@ weather_construct(XfcePanelPlugin *plugin)
 #else
     xfceweather_set_orientation(plugin, xfce_panel_plugin_get_orientation(plugin), data);
 #endif
-    xfceweather_set_size(plugin, xfce_panel_plugin_get_size(plugin), data);
+    xfceweather_set_size(plugin, data->panel_size, data);
 
     g_signal_connect(G_OBJECT(plugin), "free-data",
                      G_CALLBACK(xfceweather_free), data);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 1b7336e..69c2e8f 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -82,9 +82,9 @@ typedef struct {
     guint summary_remember_tab;
 
     gint panel_size;
-    gint size;
-    GtkOrientation orientation;
+    guint panel_rows;
     GtkOrientation panel_orientation;
+    gboolean single_row;
     xml_weather *weatherdata;
     xml_astro *astrodata;
 
@@ -149,6 +149,12 @@ void update_weatherdata_with_reset(plugin_data *data);
 
 GArray *labels_clear(GArray *array);
 
+#if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
+gboolean xfceweather_set_mode(XfcePanelPlugin *panel,
+                              XfcePanelPluginMode mode,
+                              plugin_data *data);
+#endif
+
 G_END_DECLS
 
 #endif


More information about the Xfce4-commits mailing list