[gnome-disk-utility] Unify mix color handling



commit 5c860ae87e2ef1bbaba2854ba5f2f7a9fc01b9d8
Author: David Zeuthen <davidz redhat com>
Date:   Fri Mar 12 13:45:33 2010 -0500

    Unify mix color handling

 src/gdu-gtk/gdu-ata-smart-dialog.c       |   57 +++++------------
 src/gdu-gtk/gdu-button-table.c           |  106 +++---------------------------
 src/gdu-gtk/gdu-details-table.c          |    6 ++-
 src/gdu-gtk/gdu-disk-selection-widget.c  |   22 +-----
 src/gdu-gtk/gdu-edit-linux-lvm2-dialog.c |   22 +-----
 src/gdu-gtk/gdu-edit-linux-md-dialog.c   |   22 +-----
 src/gdu-gtk/gdu-gtk.c                    |   30 +++++++++
 src/gdu-gtk/gdu-gtk.h                    |    5 ++
 src/gdu-gtk/gdu-pool-tree-view.c         |   25 ++------
 9 files changed, 79 insertions(+), 216 deletions(-)
---
diff --git a/src/gdu-gtk/gdu-ata-smart-dialog.c b/src/gdu-gtk/gdu-ata-smart-dialog.c
index 9e96060..9cb77f3 100644
--- a/src/gdu-gtk/gdu-ata-smart-dialog.c
+++ b/src/gdu-gtk/gdu-ata-smart-dialog.c
@@ -666,43 +666,6 @@ selection_changed (GtkTreeSelection *tree_selection,
         g_free (attr_name);
 }
 
-static gchar *
-get_grey_color (GtkTreeView *tree_view,
-                GtkTreeIter *iter)
-{
-        GtkTreeSelection *tree_selection;
-        GtkStyle *style;
-        GdkColor desc_gdk_color = {0};
-        GtkStateType state;
-        gchar *desc_color;
-
-        /* This color business shouldn't be this hard... */
-        tree_selection = gtk_tree_view_get_selection (tree_view);
-        style = gtk_widget_get_style (GTK_WIDGET (tree_view));
-        if (gtk_tree_selection_iter_is_selected (tree_selection, iter)) {
-                if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
-                        state = GTK_STATE_SELECTED;
-                else
-                        state = GTK_STATE_ACTIVE;
-        } else {
-                state = GTK_STATE_NORMAL;
-        }
-#define BLEND_FACTOR 0.7
-        desc_gdk_color.red   = style->text[state].red   * BLEND_FACTOR +
-                               style->base[state].red   * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.green = style->text[state].green * BLEND_FACTOR +
-                               style->base[state].green * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.blue  = style->text[state].blue  * BLEND_FACTOR +
-                               style->base[state].blue  * (1.0 - BLEND_FACTOR);
-#undef BLEND_FACTOR
-        desc_color = g_strdup_printf ("#%02x%02x%02x",
-                                      (desc_gdk_color.red >> 8),
-                                      (desc_gdk_color.green >> 8),
-                                      (desc_gdk_color.blue >> 8));
-
-        return desc_color;
-}
-
 static void
 format_markup_name (GtkCellLayout   *cell_layout,
                     GtkCellRenderer *renderer,
@@ -716,7 +679,6 @@ format_markup_name (GtkCellLayout   *cell_layout,
         gchar *name;
         gchar *desc;
         gchar *markup;
-        gchar *desc_color;
 
         gtk_tree_model_get (tree_model,
                             iter,
@@ -738,17 +700,31 @@ format_markup_name (GtkCellLayout   *cell_layout,
                 desc = g_strdup_printf (_("No description for attribute %d"), id);
         }
 
-        desc_color = get_grey_color (GTK_TREE_VIEW (dialog->priv->tree_view), iter);
         if (a->warn) {
                 markup = g_strdup_printf ("<b><span fgcolor='red'>%s</span></b>\n"
                                           "<span fgcolor='darkred'><small>%s</small></span>",
                                           name,
                                           desc);
         } else {
+                gchar color[16];
+                GtkTreeSelection *tree_selection;
+                GtkStateType state;
+
+                tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->tree_view));
+                if (gtk_tree_selection_iter_is_selected (tree_selection, iter)) {
+                        if (gtk_widget_has_focus (GTK_WIDGET (dialog->priv->tree_view)))
+                                state = GTK_STATE_SELECTED;
+                        else
+                                state = GTK_STATE_ACTIVE;
+                } else {
+                        state = GTK_STATE_NORMAL;
+                }
+                gdu_util_get_mix_color (GTK_WIDGET (dialog->priv->tree_view), state, color, sizeof (color));
+
                 markup = g_strdup_printf ("<b>%s</b>\n"
                                           "<span fgcolor=\"%s\"><small>%s</small></span>",
                                           name,
-                                          desc_color,
+                                          color,
                                           desc);
         }
 
@@ -760,7 +736,6 @@ format_markup_name (GtkCellLayout   *cell_layout,
         g_free (name);
         g_free (desc);
         g_free (markup);
-        g_free (desc_color);
 }
 
 static void
diff --git a/src/gdu-gtk/gdu-button-table.c b/src/gdu-gtk/gdu-button-table.c
index 7e81312..cb32f28 100644
--- a/src/gdu-gtk/gdu-button-table.c
+++ b/src/gdu-gtk/gdu-button-table.c
@@ -252,100 +252,6 @@ on_button_element_changed (GduButtonElement *element,
                            ElementData       *data)
 {
         do_relayout (data->table);
-#if 0
-        gchar *s;
-        GIcon *icon;
-        const gchar *text;
-        const gchar *action_text;
-        const gchar *action_uri;
-        const gchar *action_tooltip;
-        guint64 time;
-        gdouble progress;
-
-        s = g_strdup_printf ("<span fgcolor='#404040'>%s</span>",
-                             gdu_button_element_get_heading (element));
-        gtk_label_set_markup (GTK_LABEL (data->heading_label), s);
-        g_free (s);
-
-        text = gdu_button_element_get_text (element);
-        if (text != NULL) {
-                gtk_label_set_markup (GTK_LABEL (data->label), text);
-                gtk_widget_set_no_show_all (data->label, FALSE);
-                gtk_widget_show (data->label);
-        } else {
-                gtk_widget_set_no_show_all (data->label, TRUE);
-                gtk_widget_hide (data->label);
-        }
-
-        time = gdu_button_element_get_time (element);
-        if (time > 0) {
-                GTimeVal time_val;
-                time_val.tv_sec = time;
-                time_val.tv_usec = 0;
-                gdu_time_label_set_time (GDU_TIME_LABEL (data->time_label), &time_val);
-                gtk_widget_set_no_show_all (data->time_label, FALSE);
-                gtk_widget_show (data->time_label);
-        } else {
-                gtk_widget_set_no_show_all (data->time_label, TRUE);
-                gtk_widget_hide (data->time_label);
-        }
-
-        icon = gdu_button_element_get_icon (element);
-        if (icon != NULL) {
-                gtk_image_set_from_gicon (GTK_IMAGE (data->image),
-                                          icon,
-                                          GTK_ICON_SIZE_MENU);
-                gtk_widget_set_no_show_all (data->image, FALSE);
-                gtk_widget_show (data->image);
-                g_object_unref (icon);
-        } else {
-                gtk_widget_set_no_show_all (data->image, TRUE);
-                gtk_widget_hide (data->image);
-        }
-
-        action_text = gdu_button_element_get_action_text (element);
-        action_uri = gdu_button_element_get_action_uri (element);
-        action_tooltip = gdu_button_element_get_action_tooltip (element);
-
-        if (action_text != NULL) {
-                s = g_strdup_printf ("<a href=\"%s\" title=\"%s\">%s</a>",
-                                     action_uri != NULL ? action_uri : "",
-                                     action_tooltip != NULL ? action_tooltip : "",
-                                     action_text);
-                gtk_label_set_markup (GTK_LABEL (data->action_label), s);
-                g_free (s);
-                gtk_widget_set_no_show_all (data->action_label, FALSE);
-                gtk_widget_set_no_show_all (data->action_hyphen_label, FALSE);
-                gtk_widget_show (data->action_label);
-                gtk_widget_show (data->action_hyphen_label);
-        } else {
-                gtk_widget_set_no_show_all (data->action_label, TRUE);
-                gtk_widget_set_no_show_all (data->action_hyphen_label, TRUE);
-                gtk_widget_hide (data->action_label);
-                gtk_widget_hide (data->action_hyphen_label);
-        }
-
-        if (gdu_button_element_get_is_spinning (element)) {
-                gdu_spinner_start (GDU_SPINNER (data->spinner));
-                gtk_widget_set_no_show_all (data->spinner, FALSE);
-                gtk_widget_show (data->spinner);
-        } else {
-                gdu_spinner_stop (GDU_SPINNER (data->spinner));
-                gtk_widget_set_no_show_all (data->spinner, TRUE);
-                gtk_widget_hide (data->spinner);
-        }
-
-        progress = gdu_button_element_get_progress (element);
-        if (progress >= 0.0) {
-                gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data->progress_bar),
-                                               progress);
-                gtk_widget_set_no_show_all (data->progress_bar, FALSE);
-                gtk_widget_show (data->progress_bar);
-        } else {
-                gtk_widget_set_no_show_all (data->progress_bar, TRUE);
-                gtk_widget_hide (data->progress_bar);
-        }
-#endif
 }
 
 static void
@@ -357,7 +263,8 @@ on_button_clicked (GtkButton  *button,
 }
 
 static GtkWidget *
-create_button (const gchar *icon_name,
+create_button (GtkWidget   *widget,
+               const gchar *icon_name,
                const gchar *button_primary,
                const gchar *button_secondary)
 {
@@ -366,6 +273,9 @@ create_button (const gchar *icon_name,
         GtkWidget *image;
         GtkWidget *button;
         gchar *s;
+        gchar color[16];
+
+        gdu_util_get_mix_color (widget, GTK_STATE_NORMAL, color, sizeof (color));
 
         image = gtk_image_new_from_icon_name (icon_name,
                                               GTK_ICON_SIZE_BUTTON);
@@ -377,8 +287,9 @@ create_button (const gchar *icon_name,
         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
         gtk_label_set_single_line_mode (GTK_LABEL (label), FALSE);
         s = g_strdup_printf ("%s\n"
-                             "<span fgcolor='#404040'><small>%s</small></span>",
+                             "<span fgcolor='%s'><small>%s</small></span>",
                              button_primary,
+                             color,
                              button_secondary);
         gtk_label_set_markup (GTK_LABEL (label), s);
         gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
@@ -466,7 +377,8 @@ do_relayout (GduButtonTable *table)
                 column_table = table->priv->column_tables->pdata[column_table_number];
                 m++;
 
-                data->button = create_button (gdu_button_element_get_icon_name (element),
+                data->button = create_button (GTK_WIDGET (table),
+                                              gdu_button_element_get_icon_name (element),
                                               gdu_button_element_get_primary_text (element),
                                               gdu_button_element_get_secondary_text (element));
                 gtk_widget_show (data->button);
diff --git a/src/gdu-gtk/gdu-details-table.c b/src/gdu-gtk/gdu-details-table.c
index 17c273c..8336d37 100644
--- a/src/gdu-gtk/gdu-details-table.c
+++ b/src/gdu-gtk/gdu-details-table.c
@@ -266,8 +266,12 @@ on_details_element_changed (GduDetailsElement *element,
         guint64 time;
         gdouble progress;
         GtkWidget *widget;
+        gchar color[16];
 
-        s = g_strdup_printf ("<span fgcolor='#404040'>%s</span>",
+        gdu_util_get_mix_color (data->heading_label, GTK_STATE_NORMAL, color, sizeof (color));
+
+        s = g_strdup_printf ("<span fgcolor='%s'>%s</span>",
+                             color,
                              gdu_details_element_get_heading (element));
         gtk_label_set_markup (GTK_LABEL (data->heading_label), s);
         g_free (s);
diff --git a/src/gdu-gtk/gdu-disk-selection-widget.c b/src/gdu-gtk/gdu-disk-selection-widget.c
index a3e4416..af3cf3f 100644
--- a/src/gdu-gtk/gdu-disk-selection-widget.c
+++ b/src/gdu-gtk/gdu-disk-selection-widget.c
@@ -659,9 +659,7 @@ disk_name_data_func (GtkCellLayout   *cell_layout,
         gchar *name;
         gchar *vpd_name;
         gchar *markup;
-        GtkStyle *style;
-        GdkColor desc_gdk_color = {0};
-        gchar *desc_color;
+        gchar color[16];
         GtkStateType state;
         gboolean sensitive;
         GduPresentable *p;
@@ -678,8 +676,6 @@ disk_name_data_func (GtkCellLayout   *cell_layout,
         if (p != NULL && GDU_IS_DRIVE (p))
                 sensitive = is_drive_selectable (widget, GDU_DRIVE (p), NULL);
 
-        /* This color business shouldn't be this hard... */
-        style = gtk_widget_get_style (GTK_WIDGET (widget->priv->tree_view));
         if (gtk_tree_selection_iter_is_selected (tree_selection, iter)) {
                 if (gtk_widget_has_focus (GTK_WIDGET (widget->priv->tree_view)))
                         state = GTK_STATE_SELECTED;
@@ -688,24 +684,13 @@ disk_name_data_func (GtkCellLayout   *cell_layout,
         } else {
                 state = GTK_STATE_NORMAL;
         }
-#define BLEND_FACTOR 0.7
-        desc_gdk_color.red   = style->text[state].red   * BLEND_FACTOR +
-                               style->base[state].red   * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.green = style->text[state].green * BLEND_FACTOR +
-                               style->base[state].green * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.blue  = style->text[state].blue  * BLEND_FACTOR +
-                               style->base[state].blue  * (1.0 - BLEND_FACTOR);
-#undef BLEND_FACTOR
-        desc_color = g_strdup_printf ("#%02x%02x%02x",
-                                      (desc_gdk_color.red >> 8),
-                                      (desc_gdk_color.green >> 8),
-                                      (desc_gdk_color.blue >> 8));
+        gdu_util_get_mix_color (GTK_WIDGET (widget->priv->tree_view), state, color, sizeof (color));
 
         if (sensitive) {
                 markup = g_strdup_printf ("<small><b>%s</b>\n"
                                           "<span fgcolor=\"%s\">%s</span></small>",
                                           name,
-                                          desc_color,
+                                          color,
                                           vpd_name);
         } else {
                 markup = g_strdup_printf ("<small><b>%s</b>\n"
@@ -724,7 +709,6 @@ disk_name_data_func (GtkCellLayout   *cell_layout,
         g_free (name);
         g_free (vpd_name);
         g_free (markup);
-        g_free (desc_color);
 
         if (p != NULL)
                 g_object_unref (p);
diff --git a/src/gdu-gtk/gdu-edit-linux-lvm2-dialog.c b/src/gdu-gtk/gdu-edit-linux-lvm2-dialog.c
index 352d0a6..dc028d5 100644
--- a/src/gdu-gtk/gdu-edit-linux-lvm2-dialog.c
+++ b/src/gdu-gtk/gdu-edit-linux-lvm2-dialog.c
@@ -188,9 +188,7 @@ format_markup (GtkCellLayout   *cell_layout,
         GduPresentable *drive_for_pv;
         gchar *pv_uuid;
         gchar *markup;
-        GtkStyle *style;
-        GdkColor desc_gdk_color = {0};
-        gchar *desc_color;
+        gchar color[16];
         GtkStateType state;
 
         tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->pvs_tree_view));
@@ -202,8 +200,6 @@ format_markup (GtkCellLayout   *cell_layout,
                             LINUX_LVM2_PV_UUID_COLUMN, &pv_uuid,
                             -1);
 
-        /* This color business shouldn't be this hard... */
-        style = gtk_widget_get_style (GTK_WIDGET (dialog->priv->pvs_tree_view));
         if (gtk_tree_selection_iter_is_selected (tree_selection, iter)) {
                 if (gtk_widget_has_focus (GTK_WIDGET (dialog->priv->pvs_tree_view)))
                         state = GTK_STATE_SELECTED;
@@ -212,18 +208,7 @@ format_markup (GtkCellLayout   *cell_layout,
         } else {
                 state = GTK_STATE_NORMAL;
         }
-#define BLEND_FACTOR 0.7
-        desc_gdk_color.red   = style->text[state].red   * BLEND_FACTOR +
-                               style->base[state].red   * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.green = style->text[state].green * BLEND_FACTOR +
-                               style->base[state].green * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.blue  = style->text[state].blue  * BLEND_FACTOR +
-                               style->base[state].blue  * (1.0 - BLEND_FACTOR);
-#undef BLEND_FACTOR
-        desc_color = g_strdup_printf ("#%02x%02x%02x",
-                                      (desc_gdk_color.red >> 8),
-                                      (desc_gdk_color.green >> 8),
-                                      (desc_gdk_color.blue >> 8));
+        gdu_util_get_mix_color (GTK_WIDGET (dialog->priv->pvs_tree_view), state, color, sizeof (color));
 
         if (volume_for_pv != NULL) {
                 name = gdu_presentable_get_vpd_name (volume_for_pv);
@@ -240,7 +225,7 @@ format_markup (GtkCellLayout   *cell_layout,
         markup = g_strdup_printf ("<b>%s</b>\n"
                                   "<span fgcolor=\"%s\"><small>%s</small></span>",
                                   name,
-                                  desc_color,
+                                  color,
                                   drive_name);
 
         g_object_set (renderer,
@@ -250,7 +235,6 @@ format_markup (GtkCellLayout   *cell_layout,
         g_free (name);
         g_free (drive_name);
         g_free (markup);
-        g_free (desc_color);
         if (volume_for_pv != NULL)
                 g_object_unref (volume_for_pv);
         if (drive_for_pv != NULL)
diff --git a/src/gdu-gtk/gdu-edit-linux-md-dialog.c b/src/gdu-gtk/gdu-edit-linux-md-dialog.c
index a2f30f9..e331cd9 100644
--- a/src/gdu-gtk/gdu-edit-linux-md-dialog.c
+++ b/src/gdu-gtk/gdu-edit-linux-md-dialog.c
@@ -234,9 +234,7 @@ format_markup (GtkCellLayout   *cell_layout,
         GduPresentable *volume_for_slave;
         GduPresentable *drive_for_slave;
         gchar *markup;
-        GtkStyle *style;
-        GdkColor desc_gdk_color = {0};
-        gchar *desc_color;
+        gchar color[16];
         GtkStateType state;
 
         tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->components_tree_view));
@@ -247,8 +245,6 @@ format_markup (GtkCellLayout   *cell_layout,
                             MD_LINUX_SLAVE_DRIVE_COLUMN, &drive_for_slave,
                             -1);
 
-        /* This color business shouldn't be this hard... */
-        style = gtk_widget_get_style (GTK_WIDGET (dialog->priv->components_tree_view));
         if (gtk_tree_selection_iter_is_selected (tree_selection, iter)) {
                 if (gtk_widget_has_focus (GTK_WIDGET (dialog->priv->components_tree_view)))
                         state = GTK_STATE_SELECTED;
@@ -257,18 +253,7 @@ format_markup (GtkCellLayout   *cell_layout,
         } else {
                 state = GTK_STATE_NORMAL;
         }
-#define BLEND_FACTOR 0.7
-        desc_gdk_color.red   = style->text[state].red   * BLEND_FACTOR +
-                               style->base[state].red   * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.green = style->text[state].green * BLEND_FACTOR +
-                               style->base[state].green * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.blue  = style->text[state].blue  * BLEND_FACTOR +
-                               style->base[state].blue  * (1.0 - BLEND_FACTOR);
-#undef BLEND_FACTOR
-        desc_color = g_strdup_printf ("#%02x%02x%02x",
-                                      (desc_gdk_color.red >> 8),
-                                      (desc_gdk_color.green >> 8),
-                                      (desc_gdk_color.blue >> 8));
+        gdu_util_get_mix_color (GTK_WIDGET (dialog->priv->components_tree_view), state, color, sizeof (color));
 
         name = gdu_presentable_get_vpd_name (volume_for_slave);
         if (drive_for_slave != NULL) {
@@ -280,7 +265,7 @@ format_markup (GtkCellLayout   *cell_layout,
         markup = g_strdup_printf ("<b>%s</b>\n"
                                   "<span fgcolor=\"%s\"><small>%s</small></span>",
                                   name,
-                                  desc_color,
+                                  color,
                                   drive_name);
 
         g_object_set (renderer,
@@ -290,7 +275,6 @@ format_markup (GtkCellLayout   *cell_layout,
         g_free (name);
         g_free (drive_name);
         g_free (markup);
-        g_free (desc_color);
         g_object_unref (volume_for_slave);
         if (drive_for_slave != NULL)
                 g_object_unref (drive_for_slave);
diff --git a/src/gdu-gtk/gdu-gtk.c b/src/gdu-gtk/gdu-gtk.c
index a821405..95eabd2 100644
--- a/src/gdu-gtk/gdu-gtk.c
+++ b/src/gdu-gtk/gdu-gtk.c
@@ -1728,3 +1728,33 @@ gdu_util_get_pixbuf_for_presentable_at_pixel_size (GduPresentable *presentable,
         return pixbuf;
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+void
+gdu_util_get_mix_color (GtkWidget    *widget,
+                        GtkStateType  state,
+                        gchar        *color_buf,
+                        gsize         color_buf_size)
+{
+        GtkStyle *style;
+        GdkColor color = {0};
+
+        g_return_if_fail (GTK_IS_WIDGET (widget));
+        g_return_if_fail (color_buf != NULL);
+
+        /* This color business shouldn't be this hard... */
+        style = gtk_widget_get_style (widget);
+#define BLEND_FACTOR 0.7
+        color.red   = style->text[state].red   * BLEND_FACTOR +
+                      style->base[state].red   * (1.0 - BLEND_FACTOR);
+        color.green = style->text[state].green * BLEND_FACTOR +
+                      style->base[state].green * (1.0 - BLEND_FACTOR);
+        color.blue  = style->text[state].blue  * BLEND_FACTOR +
+                      style->base[state].blue  * (1.0 - BLEND_FACTOR);
+#undef BLEND_FACTOR
+        snprintf (color_buf,
+                  color_buf_size, "#%02x%02x%02x",
+                  (color.red >> 8),
+                  (color.green >> 8),
+                  (color.blue >> 8));
+}
diff --git a/src/gdu-gtk/gdu-gtk.h b/src/gdu-gtk/gdu-gtk.h
index cd450d9..11c2fd3 100644
--- a/src/gdu-gtk/gdu-gtk.h
+++ b/src/gdu-gtk/gdu-gtk.h
@@ -124,6 +124,11 @@ GdkPixbuf *gdu_util_get_pixbuf_for_presentable (GduPresentable *presentable, Gtk
 
 GdkPixbuf *gdu_util_get_pixbuf_for_presentable_at_pixel_size (GduPresentable *presentable, gint pixel_size);
 
+void       gdu_util_get_mix_color (GtkWidget    *widget,
+                                   GtkStateType  state,
+                                   gchar        *color_buf,
+                                   gsize         color_buf_size);
+
 
 G_END_DECLS
 
diff --git a/src/gdu-gtk/gdu-pool-tree-view.c b/src/gdu-gtk/gdu-pool-tree-view.c
index ccc8ae7..aa7655a 100644
--- a/src/gdu-gtk/gdu-pool-tree-view.c
+++ b/src/gdu-gtk/gdu-pool-tree-view.c
@@ -25,6 +25,7 @@
 
 #include <string.h>
 
+#include "gdu-gtk.h"
 #include "gdu-pool-tree-view.h"
 #include "gdu-pool-tree-model.h"
 #include "gdu-gtk-enumtypes.h"
@@ -152,9 +153,7 @@ format_markup (GtkCellLayout   *cell_layout,
         gchar *desc;
         GduPresentable *p;
         gchar *markup;
-        GtkStyle *style;
-        GdkColor desc_gdk_color = {0};
-        gchar *desc_color;
+        gchar color[16];
         GtkStateType state;
 
         tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
@@ -167,8 +166,6 @@ format_markup (GtkCellLayout   *cell_layout,
                             GDU_POOL_TREE_MODEL_COLUMN_DESCRIPTION, &desc,
                             -1);
 
-        /* This color business shouldn't be this hard... */
-        style = gtk_widget_get_style (GTK_WIDGET (view));
         if (gtk_tree_selection_iter_is_selected (tree_selection, iter)) {
                 if (gtk_widget_has_focus (GTK_WIDGET (view)))
                         state = GTK_STATE_SELECTED;
@@ -177,18 +174,7 @@ format_markup (GtkCellLayout   *cell_layout,
         } else {
                 state = GTK_STATE_NORMAL;
         }
-#define BLEND_FACTOR 0.7
-        desc_gdk_color.red   = style->text[state].red   * BLEND_FACTOR +
-                               style->base[state].red   * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.green = style->text[state].green * BLEND_FACTOR +
-                               style->base[state].green * (1.0 - BLEND_FACTOR);
-        desc_gdk_color.blue  = style->text[state].blue  * BLEND_FACTOR +
-                               style->base[state].blue  * (1.0 - BLEND_FACTOR);
-#undef BLEND_FACTOR
-        desc_color = g_strdup_printf ("#%02x%02x%02x",
-                                      (desc_gdk_color.red >> 8),
-                                      (desc_gdk_color.green >> 8),
-                                      (desc_gdk_color.blue >> 8));
+        gdu_util_get_mix_color (GTK_WIDGET (view), state, color, sizeof (color));
 
         /* Only include VPD name for drives */
         if (GDU_IS_DRIVE (p)) {
@@ -197,7 +183,7 @@ format_markup (GtkCellLayout   *cell_layout,
                                           "<span fgcolor=\"%s\">%s</span>"
                                           "</small>",
                                           name,
-                                          desc_color,
+                                          color,
                                           vpd_name);
         } else {
                 markup = g_strdup_printf ("<small>"
@@ -205,7 +191,7 @@ format_markup (GtkCellLayout   *cell_layout,
                                           "<span fgcolor=\"%s\">%s</span>"
                                           "</small>",
                                           name,
-                                          desc_color,
+                                          color,
                                           desc);
         }
 
@@ -219,7 +205,6 @@ format_markup (GtkCellLayout   *cell_layout,
         g_free (desc);
         g_free (vpd_name);
         g_free (markup);
-        g_free (desc_color);
         g_object_unref (p);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]