Merge branch 'im-context-wayland-fixes' into 'master'

Im context wayland fixes

See merge request GNOME/gtk!1605
This commit is contained in:
Matthias Clasen 2020-04-02 13:29:32 +00:00
commit b6f6df9662

View File

@ -44,6 +44,7 @@
#include "gtkimcontextsimpleprivate.h"
#include "gtkimcontextsimpleseqs.h"
#include "gdk/gdkprofilerprivate.h"
/**
* SECTION:gtkimcontextsimple
@ -120,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)
@ -140,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*
@ -159,7 +163,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;
@ -173,7 +177,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;
}
@ -187,7 +194,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;
}
@ -233,7 +242,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;
}
@ -244,23 +257,24 @@ 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_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
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);
}
@ -1427,30 +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)
{
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);
}
/**
* gtk_im_context_simple_add_table: (skip)
* @context_simple: A #GtkIMContextSimple