[Xfce4-commits] <xfdesktop:master> Tooltip options in xfdesktop-settings

Eric Koegel noreply at xfce.org
Sun Oct 27 19:42:05 CET 2013


Updating branch refs/heads/master
         to 7b305eb5092ce88c32e019d6479903d630b9ae86 (commit)
       from d12988225513fff7c219df973dd11e18a4670a27 (commit)

commit 7b305eb5092ce88c32e019d6479903d630b9ae86
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Oct 21 11:22:16 2013 +0300

    Tooltip options in xfdesktop-settings
    
    There's now an option to toggle the display of tooltips on the
    desktop as well as a spinbox to choose the preview image size.
    The tooltip style is still present and if the user doesn't change
    the tooltip size then it will fallback to the style setting, and
    then finally default to the DEFAULT_TOOLTIP_SIZE.

 settings/main.c                      |   28 +++++++--
 settings/xfdesktop-settings-ui.glade |   47 +++++++++++++++
 src/xfdesktop-icon-view.c            |  110 +++++++++++++++++++++++++++++-----
 3 files changed, 167 insertions(+), 18 deletions(-)

diff --git a/settings/main.c b/settings/main.c
index 7122d35..3e92b16 100644
--- a/settings/main.c
+++ b/settings/main.c
@@ -75,6 +75,8 @@
 #define DESKTOP_ICONS_ICON_SIZE_PROP         "/desktop-icons/icon-size"
 #define DESKTOP_ICONS_FONT_SIZE_PROP         "/desktop-icons/font-size"
 #define DESKTOP_ICONS_CUSTOM_FONT_SIZE_PROP  "/desktop-icons/use-custom-font-size"
+#define DESKTOP_ICONS_SHOW_TOOLTIP_PROP      "/desktop-icons/show-tooltips"
+#define DESKTOP_ICONS_TOOLTIP_SIZE_PROP      "/desktop-icons/tooltip-size"
 #define DESKTOP_ICONS_SINGLE_CLICK_PROP      "/desktop-icons/single-click"
 
 typedef struct
@@ -867,9 +869,11 @@ xfdesktop_settings_get_active_workspace(AppearancePanel *panel,
     return workspace_num;
 }
 
+/* This works for both the custom font size and show tooltips check buttons,
+ * it just enables the associated spin button */
 static void
-cb_xfdesktop_chk_custom_font_size_toggled(GtkCheckButton *button,
-                                          gpointer user_data)
+cb_xfdesktop_chk_button_toggled(GtkCheckButton *button,
+                                gpointer user_data)
 {
     GtkWidget *spin_button = GTK_WIDGET(user_data);
 
@@ -1599,7 +1603,7 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
     GtkWidget *appearance_container, *chk_custom_font_size,
               *spin_font_size, *w, *box, *spin_icon_size,
               *chk_show_thumbnails, *chk_single_click, *appearance_settings,
-              *bnt_exit;
+              *chk_show_tooltips, *spin_tooltip_size, *bnt_exit;
     GtkBuilder *appearance_gxml;
     AppearancePanel *panel = g_new0(AppearancePanel, 1);
     GError *error = NULL;
@@ -1639,10 +1643,20 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
     chk_single_click = GTK_WIDGET(gtk_builder_get_object(main_gxml,
                                                          "chk_single_click"));
 
+    /* tooltip options */
+    chk_show_tooltips = GTK_WIDGET(gtk_builder_get_object(main_gxml, "chk_show_tooltips"));
+    spin_tooltip_size = GTK_WIDGET(gtk_builder_get_object(main_gxml, "spin_tooltip_size"));
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_tooltip_size), 128);
+
+    /* connect up the signals */
     g_signal_connect(G_OBJECT(chk_custom_font_size), "toggled",
-                     G_CALLBACK(cb_xfdesktop_chk_custom_font_size_toggled),
+                     G_CALLBACK(cb_xfdesktop_chk_button_toggled),
                      spin_font_size);
 
+    g_signal_connect(G_OBJECT(chk_show_tooltips), "toggled",
+                     G_CALLBACK(cb_xfdesktop_chk_button_toggled),
+                     spin_tooltip_size);
+
     /* thumbnails */
     chk_show_thumbnails = GTK_WIDGET(gtk_builder_get_object(main_gxml,
                                                             "chk_show_thumbnails"));
@@ -1836,6 +1850,12 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
     xfconf_g_property_bind(channel, DESKTOP_ICONS_CUSTOM_FONT_SIZE_PROP,
                            G_TYPE_BOOLEAN, G_OBJECT(chk_custom_font_size),
                            "active");
+    xfconf_g_property_bind(channel, DESKTOP_ICONS_SHOW_TOOLTIP_PROP,
+                           G_TYPE_BOOLEAN, G_OBJECT(chk_show_tooltips),
+                           "active");
+    xfconf_g_property_bind(channel, DESKTOP_ICONS_TOOLTIP_SIZE_PROP, G_TYPE_DOUBLE,
+                           G_OBJECT(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin_tooltip_size))),
+                           "value");
     xfconf_g_property_bind(channel, DESKTOP_ICONS_SHOW_THUMBNAILS,
                            G_TYPE_BOOLEAN, G_OBJECT(chk_show_thumbnails),
                            "active");
diff --git a/settings/xfdesktop-settings-ui.glade b/settings/xfdesktop-settings-ui.glade
index b69fe4b..1e72179 100644
--- a/settings/xfdesktop-settings-ui.glade
+++ b/settings/xfdesktop-settings-ui.glade
@@ -17,6 +17,14 @@
     <property name="page_size">0</property>
     <property name="value">12</property>
   </object>
+  <object class="GtkAdjustment" id="adjustment_tooltip">
+    <property name="upper">256</property>
+    <property name="lower">0</property>
+    <property name="page_increment">10</property>
+    <property name="step_increment">1</property>
+    <property name="page_size">0</property>
+    <property name="value">128</property>
+  </object>
   <object class="GtkListStore" id="model3">
     <columns>
       <column type="gchararray"/>
@@ -635,6 +643,45 @@
                                   </object>
                                 </child>
                                 <child>
+                                  <object class="GtkHBox" id="hboxtooltip">
+                                    <property name="visible">True</property>
+                                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                    <property name="spacing">4</property>
+                                    <child>
+                                      <object class="GtkCheckButton" id="chk_show_tooltips">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                        <property name="label" translatable="yes">Show icon tooltips. Size:</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="draw_indicator">True</property>
+                                        <property name="active">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkSpinButton" id="spin_tooltip_size">
+                                        <property name="visible">True</property>
+                                        <property name="sensitive">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                        <property name="adjustment">adjustment_tooltip</property>
+                                        <property name="tooltip-text" translatable="yes">Size of the tooltip preview image.</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
+                                <child>
                                   <object class="GtkHBox" id="hbox9">
                                     <property name="visible">True</property>
                                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index 817db45..dd4a7e4 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -52,8 +52,10 @@
 #include <libxfce4ui/libxfce4ui.h>
 #include <xfconf/xfconf.h>
 
-#define DEFAULT_FONT_SIZE  12
-#define DEFAULT_ICON_SIZE  32
+#define DEFAULT_FONT_SIZE     12
+#define DEFAULT_ICON_SIZE     32
+#define DEFAULT_TOOLTIP_SIZE 128
+#define MAX_TOOLTIP_SIZE     512
 
 #define ICON_SIZE         (icon_view->priv->icon_size)
 #define TEXT_WIDTH        ((icon_view->priv->cell_text_width_proportion) * ICON_SIZE)
@@ -178,7 +180,13 @@ struct _XfdesktopIconViewPrivate
     gdouble cell_text_width_proportion;
 
     gboolean ellipsize_icon_labels;
-    guint    tooltip_size;
+
+    /* tooltip options - There's a style and an xfconf property.
+     * The order is xfconf, style, with a fall back of DEFAULT_TOOLTIP_SIZE.
+     * xfdesktop_icon_view_get_tooltip_size will return the correct size. */
+    gboolean show_tooltips;
+    gint   tooltip_size_from_style;
+    double tooltip_szie_from_xfconf;
 
     gboolean single_click;
 };
@@ -327,6 +335,7 @@ static gboolean xfdesktop_icon_view_icon_find_position(XfdesktopIconView *icon_v
 static gboolean xfdesktop_icon_view_shift_area_to_cell(XfdesktopIconView *icon_view,
                                                        XfdesktopIcon *icon,
                                                        GdkRectangle *text_area);
+static gint xfdesktop_icon_view_get_tooltip_size(XfdesktopIconView *icon_view);
 static gboolean xfdesktop_icon_view_show_tooltip(GtkWidget *widget,
                                                  gint x,
                                                  gint y,
@@ -361,6 +370,8 @@ enum
 {
     PROP_0 = 0,
     PROP_SINGLE_CLICK,
+    PROP_SHOW_TOOLTIPS,
+    PROP_TOOLTIP_SIZE,
 };
 
 
@@ -575,11 +586,11 @@ xfdesktop_icon_view_class_init(XfdesktopIconViewClass *klass)
                                                                 G_PARAM_READABLE));
 
     gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_uint("tooltip-size",
-                                                              "Tooltip Image Size",
-                                                              "The size of the tooltip image preview",
-                                                              0, 512, 128,
-                                                              G_PARAM_READABLE));
+                                            g_param_spec_int("tooltip-size",
+                                                             "Tooltip Image Size",
+                                                             "The size of the tooltip image preview",
+                                                             -1, MAX_TOOLTIP_SIZE, -1,
+                                                             G_PARAM_READABLE));
 
 #define XFDESKTOP_PARAM_FLAGS  (G_PARAM_READWRITE \
                                 | G_PARAM_CONSTRUCT \
@@ -594,6 +605,20 @@ xfdesktop_icon_view_class_init(XfdesktopIconViewClass *klass)
                                                          FALSE,
                                                          XFDESKTOP_PARAM_FLAGS));
 
+    g_object_class_install_property(gobject_class, PROP_SHOW_TOOLTIPS,
+                                    g_param_spec_boolean("show-tooltips",
+                                                         "show tooltips",
+                                                         "show tooltips for icons on the desktop",
+                                                         TRUE,
+                                                         XFDESKTOP_PARAM_FLAGS));
+
+    g_object_class_install_property(gobject_class, PROP_TOOLTIP_SIZE,
+                                    g_param_spec_double("tooltip-size",
+                                                        "tooltip size",
+                                                        "size of the tooltip image preview",
+                                                        -1, MAX_TOOLTIP_SIZE, -1,
+                                                        XFDESKTOP_PARAM_FLAGS));
+
 #undef XFDESKTOP_PARAM_FLAGS
 
     /* same binding entries as GtkIconView */
@@ -726,6 +751,14 @@ xfce_icon_view_set_property(GObject *object,
             icon_view->priv->single_click = g_value_get_boolean (value);
             break;
 
+        case PROP_SHOW_TOOLTIPS:
+            icon_view->priv->show_tooltips = g_value_get_boolean(value);
+            break;
+
+        case PROP_TOOLTIP_SIZE:
+            icon_view->priv->tooltip_szie_from_xfconf = g_value_get_double(value);
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
             break;
@@ -745,6 +778,14 @@ xfce_icon_view_get_property(GObject *object,
             g_value_set_boolean(value, icon_view->priv->single_click);
             break;
 
+        case PROP_SHOW_TOOLTIPS:
+            g_value_set_boolean(value, icon_view->priv->show_tooltips);
+            break;
+
+        case PROP_TOOLTIP_SIZE:
+            g_value_set_double(value, icon_view->priv->tooltip_szie_from_xfconf);
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
             break;
@@ -922,6 +963,27 @@ xfdesktop_icon_view_get_single_click(XfdesktopIconView *icon_view)
     return icon_view->priv->single_click;
 }
 
+static gint
+xfdesktop_icon_view_get_tooltip_size(XfdesktopIconView *icon_view)
+{
+    g_return_val_if_fail(XFDESKTOP_IS_ICON_VIEW(icon_view), DEFAULT_TOOLTIP_SIZE);
+
+    /* Check if we're showing tooltips at all */
+    if(!icon_view->priv->show_tooltips)
+        return 0;
+
+    /* If the xfconf size is set and sane, use it */
+    if(icon_view->priv->tooltip_szie_from_xfconf >= 0)
+        return icon_view->priv->tooltip_szie_from_xfconf;
+
+    /* if the style size is set and sane, use it */
+    if(icon_view->priv->tooltip_size_from_style >= 0)
+        return icon_view->priv->tooltip_size_from_style;
+
+    /* Fall back */
+    return DEFAULT_TOOLTIP_SIZE;
+}
+
 static gboolean
 xfdesktop_icon_view_button_release(GtkWidget *widget,
                                    GdkEventButton *evt,
@@ -1091,24 +1153,32 @@ xfdesktop_icon_view_show_tooltip(GtkWidget *widget,
     XfdesktopIconView *icon_view = XFDESKTOP_ICON_VIEW(widget);
     const gchar *tip_text;
     gchar *padded_tip_text = NULL;
+    gint tooltip_size;
     
     if(!icon_view->priv->item_under_pointer
        || icon_view->priv->definitely_dragging)
     {
         return FALSE;
     }
-    
+
+    /* not showing tooltips */
+    if(!icon_view->priv->show_tooltips)
+        return FALSE;
+
+    tooltip_size = xfdesktop_icon_view_get_tooltip_size(icon_view);
+    DBG("tooltip size %d", tooltip_size);
+
     tip_text = xfdesktop_icon_peek_tooltip(icon_view->priv->item_under_pointer);
     if(!tip_text)
         return FALSE;
 
     padded_tip_text = g_strdup_printf("%s\t", tip_text);
 
-    if(icon_view->priv->tooltip_size > 0) {
+    if(tooltip_size > 0) {
         gtk_tooltip_set_icon(tooltip,
                 xfdesktop_icon_peek_tooltip_pixbuf(icon_view->priv->item_under_pointer,
-                                                   icon_view->priv->tooltip_size * 1.5f,
-                                                   icon_view->priv->tooltip_size));
+                                                   tooltip_size * 1.5f,
+                                                   tooltip_size));
     }
 
     gtk_tooltip_set_text(tooltip, padded_tip_text);
@@ -1884,7 +1954,7 @@ xfdesktop_icon_view_style_set(GtkWidget *widget,
                          "cell-padding", &icon_view->priv->cell_padding,
                          "cell-text-width-proportion", &icon_view->priv->cell_text_width_proportion,
                          "ellipsize-icon-labels", &icon_view->priv->ellipsize_icon_labels,
-                         "tooltip-size", &icon_view->priv->tooltip_size,
+                         "tooltip-size", &icon_view->priv->tooltip_size_from_style,
                          "label-radius", &icon_view->priv->label_radius,
                          NULL);
 
@@ -1892,7 +1962,7 @@ xfdesktop_icon_view_style_set(GtkWidget *widget,
     DBG("cell padding is %d", icon_view->priv->cell_padding);
     DBG("cell text width proportion is %f", icon_view->priv->cell_text_width_proportion);
     DBG("ellipsize icon label is %s", icon_view->priv->ellipsize_icon_labels?"true":"false");
-    DBG("tooltip size is %d", icon_view->priv->tooltip_size);
+    DBG("tooltip size is %d", icon_view->priv->tooltip_size_from_style);
     DBG("label radius is %f", icon_view->priv->label_radius);
 
     if(icon_view->priv->selection_box_color) {
@@ -3596,6 +3666,18 @@ xfdesktop_icon_view_new(XfdesktopIconViewManager *manager)
                            G_TYPE_BOOLEAN,
                            G_OBJECT(icon_view),
                            "single_click");
+
+    xfconf_g_property_bind(icon_view->priv->channel,
+                           "/desktop-icons/show-tooltips",
+                           G_TYPE_BOOLEAN,
+                           G_OBJECT(icon_view),
+                           "show_tooltips");
+
+    xfconf_g_property_bind(icon_view->priv->channel,
+                           "/desktop-icons/tooltip-size",
+                           G_TYPE_DOUBLE,
+                           G_OBJECT(icon_view),
+                           "tooltip_size");
     
     return GTK_WIDGET(icon_view);
 }


More information about the Xfce4-commits mailing list