icon-theme: Preload default icon themes in thread
authorAlexander Larsson <alexl@redhat.com>
Wed, 29 Jan 2020 10:38:05 +0000 (11:38 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 30 Jan 2020 09:53:43 +0000 (10:53 +0100)
This happens when we first get the theme for a display, or then the
icon theme setting changes.

This means we don't have to do this scan in the first snapshot
and can do the i/o it in parallel with other stuff. This moves
a 10msec block from the first snapshot cycle to early setup.

gtk/gtkicontheme.c

index e354f8c4fdb5572f0fc3f9a4e0bf718089c2236e..317a36a2f82201bd3bb77249cfe65df918758360 100644 (file)
@@ -733,6 +733,30 @@ gtk_icon_theme_get_default (void)
   return gtk_icon_theme_get_for_display (gdk_display_get_default ());
 }
 
+static void
+load_theme_thread  (GTask        *task,
+                    gpointer      source_object,
+                    gpointer      task_data,
+                    GCancellable *cancellable)
+{
+  GtkIconTheme *self = GTK_ICON_THEME (source_object);
+
+  gtk_icon_theme_lock (self);
+  ensure_valid_themes (self, FALSE);
+  gtk_icon_theme_unlock (self);
+  g_task_return_pointer (task, NULL, NULL);
+}
+
+static void
+gtk_icon_theme_load_in_thread (GtkIconTheme *self)
+{
+  GTask *task;
+
+  task = g_task_new (self, NULL, NULL, NULL);
+  g_task_set_task_data (task, g_object_ref (self), g_object_unref);
+  g_task_run_in_thread (task, load_theme_thread);
+}
+
 /**
  * gtk_icon_theme_get_for_display:
  * @display: a #GdkDisplay
@@ -767,6 +791,9 @@ gtk_icon_theme_get_for_display (GdkDisplay *display)
       self->is_display_singleton = TRUE;
 
       g_object_set_data (G_OBJECT (display), I_("gtk-icon-theme"), self);
+
+      /* Queue early read of the default themes, we read the icon theme name in _set_display(). */
+      gtk_icon_theme_load_in_thread (self);
     }
 
   return self;
@@ -873,7 +900,12 @@ theme_changed__mainthread_unlocked (GtkSettings  *settings,
   GtkIconTheme *self = gtk_icon_theme_ref_aquire (ref);
 
   if (self)
-    update_current_theme__mainthread (self);
+    {
+      update_current_theme__mainthread (self);
+
+      /* Queue early read of the new theme */
+      gtk_icon_theme_load_in_thread (self);
+    }
 
   gtk_icon_theme_ref_release (ref);
 }