[gtk/gtk-3-24: 1/2] GDK W32: Support switching input modules at runtime



commit d26c11f0991f18eaba389decefd2c964480ed963
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date:   Tue Oct 2 09:34:22 2018 +0000

    GDK W32: Support switching input modules at runtime
    
    This leverages the normal input module 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 module
    loading code, which, not being able to load the desired module
    (which is and empty string), falls back to looking at current
    keyboard layout.
    
    Paired with the code that signals gtk-im-module change on keyboard layout
    switches, this is sufficient to make GTK capable of loading appropriate
    input modules at runtime. At least, the kinds of modules that specify
    languages for which they are loaded automatically by default, and the
    IME module.
    
    Loading other kinds of input modules might still work via specifying
    the gtk-im-module setting in gtk ini file, but doing so will likely
    make GTK incapable of loading the IME input module 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   | 20 ++++++++++++++++++++
 gdk/win32/gdkproperty-win32.c |  9 +++++++++
 2 files changed, 29 insertions(+)
---
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index a410d5acce..70f7c782d8 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -2242,6 +2242,25 @@ _gdk_win32_window_fill_min_max_info (GdkWindow  *window,
   return TRUE;
 }
 
+static void
+gdk_settings_notify (GdkWindow        *window,
+                     const char       *name,
+                     GdkSettingAction  action)
+{
+  GdkEvent *new_event;
+
+  if (!g_str_has_prefix (name, "gtk-"))
+    return;
+
+  new_event = gdk_event_new (GDK_SETTING);
+  new_event->setting.window = window;
+  new_event->setting.send_event = FALSE;
+  new_event->setting.action = action;
+  new_event->setting.name = (char*) name;
+
+  _gdk_win32_append_event (new_event);
+}
+
 #define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
                             GDK_BUTTON2_MASK | \
                             GDK_BUTTON3_MASK | \
@@ -2456,6 +2475,7 @@ gdk_event_translate (MSG  *msg,
                         (gulong) msg->wParam,
                         (gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
                         _gdk_input_codepage));
+      gdk_settings_notify (window, "gtk-im-module", GDK_SETTING_ACTION_CHANGED);
       break;
 
     case WM_SYSKEYUP:
diff --git a/gdk/win32/gdkproperty-win32.c b/gdk/win32/gdkproperty-win32.c
index 06e8bb79fb..3524cd13a2 100644
--- a/gdk/win32/gdkproperty-win32.c
+++ b/gdk/win32/gdkproperty-win32.c
@@ -389,6 +389,15 @@ _gdk_win32_screen_get_setting (GdkScreen   *screen,
             }
         }
     }
+  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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]