summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-08-25 15:13:39 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-08-25 15:51:04 -0400
commit740559a54f61561e87b163295534c65ad8e7602a (patch)
tree1c951acd03c9adfbbb98a2875f3ef00dcec9c711
parent612d2ea1f0fa09c4537cf51dfc905af1106afff0 (diff)
downloadgtk+-740559a54f61561e87b163295534c65ad8e7602a.tar.gz
fontchooser: Populate the list incrementally
By adding 20 fonts / frame to the font list, we can get the font chooser dialog to show up much faster. This change gets the font chooser up in 265ms here.
-rw-r--r--gtk/gtkfontchooserwidget.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 480cd88d54..4351316300 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -54,6 +54,7 @@
#include "gtkroot.h"
#include "gtkfilterlistmodel.h"
#include "gtkflattenlistmodel.h"
+#include "gtkslicelistmodel.h"
#include "gtkmaplistmodel.h"
#include <hb-ot.h>
@@ -770,6 +771,40 @@ axis_free (gpointer v)
g_free (a);
}
+/* We incrementally populate our fontlist to prevent blocking
+ * the font chooser for a long time with expensive FcFontSort
+ * calls in pango for every row in the list).
+ */
+static gboolean
+add_to_fontlist (GtkWidget *widget,
+ GdkFrameClock *clock,
+ gpointer user_data)
+{
+ GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
+ GtkSliceListModel *model = user_data;
+ GListModel *child_model;
+ guint n;
+
+ if (gtk_filter_list_model_get_model (self->filter_model) != G_LIST_MODEL (model))
+ return G_SOURCE_REMOVE;
+
+ child_model = gtk_slice_list_model_get_model (model);
+
+ n = gtk_slice_list_model_get_size (model);
+
+ n += 10;
+
+ if (n >= g_list_model_get_n_items (child_model))
+ n = G_MAXUINT;
+
+ gtk_slice_list_model_set_size (model, n);
+
+ if (n == G_MAXUINT)
+ return G_SOURCE_REMOVE;
+ else
+ return G_SOURCE_CONTINUE;
+}
+
static void
update_fontlist (GtkFontChooserWidget *self)
{
@@ -784,6 +819,10 @@ update_fontlist (GtkFontChooserWidget *self)
model = g_object_ref (G_LIST_MODEL (fontmap));
else
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (g_object_ref (fontmap))));
+
+ model = G_LIST_MODEL (gtk_slice_list_model_new (model, 0, 20));
+ gtk_widget_add_tick_callback (GTK_WIDGET (self), add_to_fontlist, g_object_ref (model), g_object_unref);
+
gtk_filter_list_model_set_model (self->filter_model, model);
g_object_unref (model);
}