From a9b4ac3d59f2e95a647cb9ce09fb4204cfe93c9b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Apr 2020 08:24:01 -0400 Subject: [PATCH 1/4] imcontextsimple: Add a profiler mark for IO We are loading a file here, thankfully in a thread, but we do it every time an entry is created. Add a profiler mark, to make this visible. --- gtk/gtkimcontextsimple.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index a96b3f0646..51229a54dc 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -44,6 +44,7 @@ #include "gtkimcontextsimpleprivate.h" #include "gtkimcontextsimpleseqs.h" +#include "gdk/gdkprofilerprivate.h" /** * SECTION:gtkimcontextsimple @@ -244,12 +245,17 @@ init_compose_table_thread_cb (GTask *task, gpointer task_data, GCancellable *cancellable) { + guint64 before = g_get_monotonic_time (); + if (g_task_return_error_if_cancelled (task)) return; g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (task_data)); gtk_im_context_simple_init_compose_table (GTK_IM_CONTEXT_SIMPLE (task_data)); + + if (GDK_PROFILER_IS_RUNNING) + gdk_profiler_end_mark (before, "im compose table load (thread)", NULL); } static void From 2a9911724f5ad1f3fa7eb8c7f48e7aaac45185f7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Apr 2020 08:47:02 -0400 Subject: [PATCH 2/4] imcontextsimple: Load ~/.Compose unconditionally There is nothing display-specific in the ~/.Compose file, so we can just try to load it without looking at the display we are on. --- gtk/gtkimcontextsimple.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 51229a54dc..1b809a12e5 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -1438,23 +1438,11 @@ gtk_im_context_simple_set_client_widget (GtkIMContext *context, GtkWidget *widget) { GtkIMContextSimple *im_context_simple = GTK_IM_CONTEXT_SIMPLE (context); - gboolean run_compose_table = FALSE; if (!widget) return; - /* Load compose table for X11 or Wayland. */ -#ifdef GDK_WINDOWING_X11 - if (GDK_IS_X11_DISPLAY (gtk_widget_get_display (widget))) - run_compose_table = TRUE; -#endif -#ifdef GDK_WINDOWING_WAYLAND - if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget))) - run_compose_table = TRUE; -#endif - - if (run_compose_table) - init_compose_table_async (im_context_simple, NULL, NULL, NULL); + init_compose_table_async (im_context_simple, NULL, NULL, NULL); } /** From 8ec254e2bbe030d9ccca2d6ba25198644335e09f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Apr 2020 08:56:21 -0400 Subject: [PATCH 3/4] imcontextsimple: Simpify Compose file loading We are not loading the Compose file for individual contexts, it just gets added to a global list. So don't pass an im context along. This will let us move the loading out of the initialization of individual contexts, and only do it once. --- gtk/gtkimcontextsimple.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 1b809a12e5..35ecce3d2e 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -160,7 +160,7 @@ get_x11_compose_file_dir (void) } static void -gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) +gtk_im_context_simple_init_compose_table (void) { gchar *path = NULL; const gchar *home; @@ -174,7 +174,10 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) path = g_build_filename (g_get_user_config_dir (), "gtk-4.0", "Compose", NULL); if (g_file_test (path, G_FILE_TEST_EXISTS)) { - gtk_im_context_simple_add_compose_file (im_context_simple, path); + G_LOCK (global_tables); + global_tables = gtk_compose_table_list_add_file (global_tables, path); + G_UNLOCK (global_tables); + g_free (path); return; } @@ -188,7 +191,9 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) path = g_build_filename (home, ".XCompose", NULL); if (g_file_test (path, G_FILE_TEST_EXISTS)) { - gtk_im_context_simple_add_compose_file (im_context_simple, path); + G_LOCK (global_tables); + global_tables = gtk_compose_table_list_add_file (global_tables, path); + G_UNLOCK (global_tables); g_free (path); return; } @@ -234,7 +239,11 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) g_strfreev (langs); if (path != NULL) - gtk_im_context_simple_add_compose_file (im_context_simple, path); + { + G_LOCK (global_tables); + global_tables = gtk_compose_table_list_add_file (global_tables, path); + G_UNLOCK (global_tables); + } g_free (path); path = NULL; } @@ -252,21 +261,19 @@ init_compose_table_thread_cb (GTask *task, g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (task_data)); - gtk_im_context_simple_init_compose_table (GTK_IM_CONTEXT_SIMPLE (task_data)); + gtk_im_context_simple_init_compose_table (); if (GDK_PROFILER_IS_RUNNING) gdk_profiler_end_mark (before, "im compose table load (thread)", NULL); } static void -init_compose_table_async (GtkIMContextSimple *im_context_simple, - GCancellable *cancellable, +init_compose_table_async (GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task = g_task_new (NULL, cancellable, callback, user_data); g_task_set_source_tag (task, init_compose_table_async); - g_task_set_task_data (task, g_object_ref (im_context_simple), g_object_unref); g_task_run_in_thread (task, init_compose_table_thread_cb); g_object_unref (task); } @@ -1437,12 +1444,7 @@ static void gtk_im_context_simple_set_client_widget (GtkIMContext *context, GtkWidget *widget) { - GtkIMContextSimple *im_context_simple = GTK_IM_CONTEXT_SIMPLE (context); - - if (!widget) - return; - - init_compose_table_async (im_context_simple, NULL, NULL, NULL); + init_compose_table_async (NULL, NULL, NULL); } /** From aaa4e40a1f72520d1691d41abdfd85d72bd51d28 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Apr 2020 09:01:33 -0400 Subject: [PATCH 4/4] imcontexsimple: Move Compose file loading to class_init This ensures that it is done only once. --- gtk/gtkimcontextsimple.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 35ecce3d2e..6c9c965f7d 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -121,8 +121,10 @@ static void gtk_im_context_simple_get_preedit_string (GtkIMContext gchar **str, PangoAttrList **attrs, gint *cursor_pos); -static void gtk_im_context_simple_set_client_widget (GtkIMContext *context, - GtkWidget *widget); + +static void init_compose_table_async (GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); G_DEFINE_TYPE_WITH_CODE (GtkIMContextSimple, gtk_im_context_simple, GTK_TYPE_IM_CONTEXT, G_ADD_PRIVATE (GtkIMContextSimple) @@ -141,8 +143,9 @@ gtk_im_context_simple_class_init (GtkIMContextSimpleClass *class) im_context_class->filter_keypress = gtk_im_context_simple_filter_keypress; im_context_class->reset = gtk_im_context_simple_reset; im_context_class->get_preedit_string = gtk_im_context_simple_get_preedit_string; - im_context_class->set_client_widget = gtk_im_context_simple_set_client_widget; gobject_class->finalize = gtk_im_context_simple_finalize; + + init_compose_table_async (NULL, NULL, NULL); } static gchar* @@ -259,8 +262,6 @@ init_compose_table_thread_cb (GTask *task, if (g_task_return_error_if_cancelled (task)) return; - g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (task_data)); - gtk_im_context_simple_init_compose_table (); if (GDK_PROFILER_IS_RUNNING) @@ -1440,13 +1441,6 @@ gtk_im_context_simple_get_preedit_string (GtkIMContext *context, *cursor_pos = len; } -static void -gtk_im_context_simple_set_client_widget (GtkIMContext *context, - GtkWidget *widget) -{ - init_compose_table_async (NULL, NULL, NULL); -} - /** * gtk_im_context_simple_add_table: (skip) * @context_simple: A #GtkIMContextSimple