[gnome-control-center] Make the text size control work



commit cff71c11ddb75009b7766c383a96289ffc2dffc7
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 20 18:23:51 2011 -0500

    Make the text size control work
    
    The code was using == to compare float products to doubles.
    Not a recipe for success.

 panels/universal-access/cc-ua-panel.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/panels/universal-access/cc-ua-panel.c b/panels/universal-access/cc-ua-panel.c
index fde6923..66efbf0 100644
--- a/panels/universal-access/cc-ua-panel.c
+++ b/panels/universal-access/cc-ua-panel.c
@@ -22,6 +22,7 @@
  *
  */
 
+#include <math.h>
 #include "cc-ua-panel.h"
 
 #include <gconf/gconf-client.h>
@@ -364,6 +365,8 @@ get_dpi_from_x_server ()
   return dpi;
 }
 
+static void dpi_combo_box_changed (GtkComboBox *box, CcUaPanel *panel);
+
 static void
 dpi_notify_cb (GSettings   *settings,
                const gchar *key,
@@ -376,6 +379,8 @@ dpi_notify_cb (GSettings   *settings,
   gboolean valid;
   gdouble conf_value;
   gdouble x_dpi;
+  GtkTreeIter best;
+  gdouble distance;
 
   if (!g_str_equal (key, "dpi"))
     return;
@@ -388,30 +393,31 @@ dpi_notify_cb (GSettings   *settings,
   /* get current value from screen */
   x_dpi = get_dpi_from_x_server ();
 
-  /* see if the calculated value matches in the combobox model */
+  /* find the closest match in the combobox model */
+  distance = 1e6;
   valid = gtk_tree_model_get_iter_first (model, &iter);
   while (valid)
     {
       gfloat factor;
+      gdouble d;
 
       gtk_tree_model_get (model, &iter,
                           DPI_MODEL_FACTOR_COLUMN, &factor,
                           -1);
 
-      if (conf_value == (float) (factor * x_dpi))
+      d = fabs (conf_value - factor * x_dpi);
+      if (d < distance)
         {
-          gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
-          break;
+          best = iter;
+          distance = d;
         }
 
       valid = gtk_tree_model_iter_next (model, &iter);
     }
 
-  /* if a matching value was not found in the combobox, set to "normal" */
-  if (!valid)
-    {
-      gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
-    }
+  g_signal_handlers_block_by_func (combo, dpi_combo_box_changed, panel);
+  gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &best);
+  g_signal_handlers_unblock_by_func (combo, dpi_combo_box_changed, panel);
 }
 
 static void



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