]> Pileus Git - ~andy/gtk/commitdiff
Bug 558586 – handling of keyboard under darwin (quartz)
authorRichard Hult <richard@imendio.com>
Thu, 6 Nov 2008 15:35:56 +0000 (15:35 +0000)
committerRichard Hult <rhult@src.gnome.org>
Thu, 6 Nov 2008 15:35:56 +0000 (15:35 +0000)
2008-11-06  Richard Hult  <richard@imendio.com>

Bug 558586 – handling of keyboard under darwin (quartz)

* gdk/quartz/gdkkeys-quartz.c: (maybe_update_keymap): Patch from
Arnaud Charlet to replace use of deprecated keyboard layout API
with the new TIS API available in 10.5. The old code is still used
when building for 10.4.

svn path=/trunk/; revision=21763

ChangeLog
gdk/quartz/gdkkeys-quartz.c

index 73dfbb01133d9d9f3a7458e6b0347ab19a400101..f947cc48862a8c2dd3e53758f2bc2176bd9a6899 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-11-06  Richard Hult  <richard@imendio.com>
+
+       Bug 558586 – handling of keyboard under darwin (quartz)
+
+       * gdk/quartz/gdkkeys-quartz.c: (maybe_update_keymap): Patch from
+       Arnaud Charlet to replace use of deprecated keyboard layout API
+       with the new TIS API available in 10.5. The old code is still used
+       when building for 10.4.
+
 2008-11-05  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkevents-quartz.c:
index a1993b4a061903a1005d546ba02c6b9db5fd8e5c..c195780c99a2fcc6c751a1c2d7c5340f6d0acb83 100644 (file)
 
 static GdkKeymap *default_keymap = NULL;
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
+static TISInputSourceRef current_layout = NULL;
+#else
 static KeyboardLayoutRef current_layout = NULL;
+#endif
 
 /* This is a table of all keyvals. Each keycode gets KEYVALS_PER_KEYCODE entries.
  * TThere is 1 keyval per modifier (Nothing, Shift, Alt, Shift+Alt);
@@ -179,28 +183,46 @@ const static struct {
 static void
 maybe_update_keymap (void)
 {
+  const void *chr_data = NULL;
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
+  TISInputSourceRef new_layout = TISCopyCurrentKeyboardLayoutInputSource ();
+  CFDataRef layout_data_ref;
+
+#else
   KeyboardLayoutRef new_layout;
+  KeyboardLayoutKind layout_kind;
 
   KLGetCurrentKeyboardLayout (&new_layout);
+#endif
 
   if (new_layout != current_layout)
     {
       guint *p;
       int i;
 
-      KeyboardLayoutKind layout_kind;
-      
       g_free (keyval_array);
       keyval_array = g_new0 (guint, NUM_KEYCODES * KEYVALS_PER_KEYCODE);
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
+      layout_data_ref = (CFDataRef) TISGetInputSourceProperty
+       (new_layout, kTISPropertyUnicodeKeyLayoutData);
+
+      if (layout_data_ref)
+       chr_data = CFDataGetBytePtr (layout_data_ref);
+
+      if (chr_data == NULL)
+       {
+         g_error ("cannot get keyboard layout data");
+         return;
+       }
+#else
       /* Get the layout kind */
       KLGetKeyboardLayoutProperty (new_layout, kKLKind, (const void **)&layout_kind);
 
       /* 8-bit-only keyabord layout */
       if (layout_kind == kKLKCHRKind)
        { 
-         const void *chr_data;
-         
          /* Get chr data */
          KLGetKeyboardLayoutProperty (new_layout, kKLKCHRData, (const void **)&chr_data);
          
@@ -282,10 +304,9 @@ maybe_update_keymap (void)
       /* unicode keyboard layout */
       else if (layout_kind == kKLKCHRuchrKind || layout_kind == kKLuchrKind)
        { 
-         const void *chr_data;
-         
          /* Get chr data */
          KLGetKeyboardLayoutProperty (new_layout, kKLuchrData, (const void **)&chr_data);
+#endif  /* MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 */
          
          for (i = 0; i < NUM_KEYCODES; i++) 
            {
@@ -361,12 +382,14 @@ maybe_update_keymap (void)
                  p[1] == p[3])
                p[2] = p[3] = 0;
            }
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
        }
       else
        {
          g_error ("unknown type of keyboard layout (neither KCHR nor uchr)"
                   " - not supported right now");
        }
+#endif
 
       for (i = 0; i < G_N_ELEMENTS (known_keys); i++)
        {