[gnome-font-viewer] font-model: propagate the scale factor to the model



commit d7081cac0090debe8ff9ec5a844b94420268b6fb
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Aug 13 17:12:59 2013 +0200

    font-model: propagate the scale factor to the model
    
    So we can create surfaces with the correct scale for HiDpi displays.

 src/font-model.c |   31 ++++++++++++++++++++++++++++---
 src/font-model.h |    7 +++++--
 src/font-view.c  |   12 ++++++++++++
 3 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/src/font-model.c b/src/font-model.c
index a58dfbe..a970bf3 100644
--- a/src/font-model.c
+++ b/src/font-model.c
@@ -52,6 +52,9 @@ struct _FontViewModelPrivate {
     GList *monitors;
     GdkPixbuf *fallback_icon;
     GCancellable *cancellable;
+
+    gint scale_factor;
+    guint font_list_idle_id;
 };
 
 enum {
@@ -456,6 +459,16 @@ ensure_font_list_idle (gpointer user_data)
     return FALSE;
 }
 
+static void
+schedule_update_font_list (FontViewModel *self)
+{
+    if (self->priv->font_list_idle_id != 0)
+        return;
+
+    self->priv->font_list_idle_id =
+        g_idle_add (ensure_font_list_idle, self);
+}
+
 static int
 font_view_model_sort_func (GtkTreeModel *model,
                            GtkTreeIter *a,
@@ -571,9 +584,7 @@ font_view_model_init (FontViewModel *self)
                                      font_view_model_sort_func,
                                      NULL, NULL);
 
-    self->priv->fallback_icon = get_fallback_icon ();
-
-    g_idle_add (ensure_font_list_idle, self);
+    schedule_update_font_list (self);
     create_file_monitors (self);
 }
 
@@ -597,6 +608,11 @@ font_view_model_finalize (GObject *obj)
         self->priv->library = NULL;
     }
 
+    if (self->priv->font_list_idle_id != 0) {
+        g_source_remove (self->priv->font_list_idle_id);
+        self->priv->font_list_idle_id = 0;
+    }
+
     g_mutex_clear (&self->priv->font_list_mutex);
     g_clear_object (&self->priv->fallback_icon);
     g_list_free_full (self->priv->monitors, (GDestroyNotify) g_object_unref);
@@ -625,3 +641,12 @@ font_view_model_new (void)
 {
     return g_object_new (FONT_VIEW_TYPE_MODEL, NULL);
 }
+
+void
+font_view_model_set_scale_factor (FontViewModel *self,
+                                  gint           scale_factor)
+{
+    self->priv->scale_factor = scale_factor;
+
+    schedule_update_font_list (self);
+}
diff --git a/src/font-model.h b/src/font-model.h
index fca17d0..5710e9d 100644
--- a/src/font-model.h
+++ b/src/font-model.h
@@ -58,8 +58,11 @@ GType font_view_model_get_type (void);
 GtkTreeModel * font_view_model_new (void);
 
 gboolean font_view_model_get_iter_for_face (FontViewModel *self,
-                                            FT_Face face,
-                                            GtkTreeIter *iter);
+                                            FT_Face        face,
+                                            GtkTreeIter   *iter);
+
+void     font_view_model_set_scale_factor  (FontViewModel *self,
+                                            gint           scale_factor);
 
 G_END_DECLS
 
diff --git a/src/font-view.c b/src/font-view.c
index 9cbdef0..a5e8ce1 100644
--- a/src/font-view.c
+++ b/src/font-view.c
@@ -485,6 +485,14 @@ info_button_clicked_cb (GtkButton *button,
 }
 
 static void
+font_view_update_scale_factor (FontViewApplication *self)
+{
+    gint scale_factor = gtk_widget_get_scale_factor (self->main_window);
+    font_view_model_set_scale_factor (FONT_VIEW_MODEL (self->model),
+                                      scale_factor);
+}
+
+static void
 font_view_ensure_model (FontViewApplication *self)
 {
     if (self->model != NULL)
@@ -493,6 +501,10 @@ font_view_ensure_model (FontViewApplication *self)
     self->model = font_view_model_new ();
     g_signal_connect (self->model, "config-changed",
                       G_CALLBACK (font_model_config_changed_cb), self);
+
+    g_signal_connect (self->main_window, "notify::scale-factor",
+                      G_CALLBACK (font_view_update_scale_factor), self);
+    font_view_update_scale_factor (self);
 }
 
 static void


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