From 66c0336ead9fd27cb93354336d113e8855406b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Tue, 2 Oct 2018 09:34:22 +0000 Subject: [PATCH] GDK W32: Support switching IM contexts at runtime This leverages the normal input context switching mechanism in GTK by making it think that the gtk-im-module setting changed. The backend returns gtk-im-module value as "ime" if W32 IME API says that an IME is in use. Otherwise it returns and empty string - this still triggers an input context switching code, which, not being able to create the desired context (which is and empty string), falls back to looking at current keyboard layout (currently that code is still a FIXME). Paired with the code that signals gtk-im-module change on keyboard layout switches, this is sufficient to make GTK capable of switching to the appropriate IM context at runtime. At least, the kinds of context that specify languages for which they are used automatically by default (once locale matching is implemented), and the IME context. Loading other kinds of IM context might still work via specifying the gtk-im-module setting in gtk ini file, but doing so will likely make GTK incapable of using the IME context that is used for Korean, Chinese and Japanese (and some other languages). Until someone figures out a way to actually change gtk-im-module setting on Windows at runtime with meaningful values, the behaviour introduced by this commit seems like a sufficient workaround. --- gdk/win32/gdkevents-win32.c | 1 + gdk/win32/gdkproperty-win32.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c index 40df7de157..73529b8ef9 100644 --- a/gdk/win32/gdkevents-win32.c +++ b/gdk/win32/gdkevents-win32.c @@ -2124,6 +2124,7 @@ gdk_event_translate (MSG *msg, (gulong) msg->wParam, (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "", _gdk_input_codepage)); + gdk_display_setting_changed (display, "gtk-im-module"); break; case WM_SYSKEYUP: diff --git a/gdk/win32/gdkproperty-win32.c b/gdk/win32/gdkproperty-win32.c index 17729300df..be37ef7d0c 100644 --- a/gdk/win32/gdkproperty-win32.c +++ b/gdk/win32/gdkproperty-win32.c @@ -180,6 +180,15 @@ _gdk_win32_get_setting (const gchar *name, } } } + else if (strcmp ("gtk-im-module", name) == 0) + { + if (_gdk_input_locale_is_ime) + g_value_set_string (value, "ime"); + else + g_value_set_string (value, ""); + + return TRUE; + } return FALSE; }