Correct translation of Mac JIS Eisu & Kana keys
authorgsittyz <gsittyz@gmail.com>
Sat, 24 Jul 2021 06:39:10 +0000 (15:39 +0900)
committergsittyz <gsittyz@gmail.com>
Sat, 24 Jul 2021 11:59:18 +0000 (20:59 +0900)
Since UCKeyTranslate() converts these keys to Space key unexpectedly,
applications can't distinguish these keys by keysyms.
To solve it, this fix translates these keys by the same way with
function keys & keypad keys.
This patch is equivalent to the patch proposed in:
https://bugzilla.gnome.org/show_bug.cgi?id=702841

Closes #4117

gdk/macos/gdkmacoskeymap.c

index 4d54311874ae6b942b8639f2fa754a89ecfe8416..5cf34d3ed3de0c88141beffc2ccf8fff8fc9f2a2 100644 (file)
@@ -141,6 +141,29 @@ const static struct {
   { 92, GDK_KEY_9, GDK_KEY_KP_9 }
 };
 
+/* Keys only in JIS layout.
+ * The rationale of these key codes is <HIToolbox/Events.h> in Carbon.
+ */
+const static struct {
+  guint keycode;
+  guint keyval;
+} jis_keys[] = {
+#if 0
+  /* Although These keys are also defined in <HIToolbox/Events.h>, they can be
+   * translated by UCKeyTranslate correctly.
+   */
+  { 0x5D, GDK_KEY_yen },
+  { 0x5E, GDK_KEY_underscore },
+  { 0x5F, GDK_KEY_comma },
+#endif
+  /* These keys are unexpectedly translated to Space key by UCKeyTranslate,
+   * and there is no suitable ucs value for them to add to special_ucs_table.
+   * So we should translate them particularly.
+   */
+  { 0x66 /* 102 */, GDK_KEY_Eisu_toggle },
+  { 0x68 /* 104 */, GDK_KEY_Hiragana }
+};
+
 /* These values aren't covered by gdk_unicode_to_keyval */
 const static struct {
   gunichar ucs_value;
@@ -346,6 +369,13 @@ gdk_macos_keymap_update (GdkMacosKeymap *self)
       if (p[0] == known_numeric_keys[i].normal_keyval)
         p[0] = known_numeric_keys[i].keypad_keyval;
     }
+      
+  for (i = 0; i < G_N_ELEMENTS (jis_keys); i++)
+    {
+      p = keyval_array + jis_keys[i].keycode * KEYVALS_PER_KEYCODE;
+      p[0] = jis_keys[i].keyval;
+      p[1] = p[2] = p[3] = 0;
+    }
 
   g_signal_emit_by_name (self, "keys-changed");
 }