From: Jjgod Jiang <gzjjgod@gmail.com>
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Sep 2009 09:55:25 +0000
changeset 32472dcfb4e07a57
parent 3246 c843261f74a4
child 3248 cde30895105d
From: Jjgod Jiang <gzjjgod@gmail.com>
Date: Sat, 5 Sep 2009 17:32:28 +0800

Replace old Keyboard Layout APIs with new Text Input Sources APIs for 10.{5,6}
src/video/cocoa/SDL_cocoakeyboard.m
     1.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Sat Sep 05 09:54:45 2009 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Sat Sep 05 09:55:25 2009 +0000
     1.3 @@ -351,14 +351,22 @@
     1.4  static void
     1.5  UpdateKeymap(SDL_VideoData *data)
     1.6  {
     1.7 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
     1.8 +    TISInputSourceRef key_layout;
     1.9 +#else
    1.10      KeyboardLayoutRef key_layout;
    1.11 +#endif
    1.12      const void *chr_data;
    1.13      int i;
    1.14      SDL_scancode scancode;
    1.15      SDLKey keymap[SDL_NUM_SCANCODES];
    1.16  
    1.17      /* See if the keymap needs to be updated */
    1.18 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
    1.19 +    key_layout = TISCopyCurrentKeyboardLayoutInputSource();
    1.20 +#else
    1.21      KLGetCurrentKeyboardLayout(&key_layout);
    1.22 +#endif
    1.23      if (key_layout == data->key_layout) {
    1.24          return;
    1.25      }
    1.26 @@ -367,7 +375,15 @@
    1.27      SDL_GetDefaultKeymap(keymap);
    1.28  
    1.29      /* Try Unicode data first (preferred as of Mac OS X 10.5) */
    1.30 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
    1.31 +    CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
    1.32 +    if (uchrDataRef)
    1.33 +        chr_data = CFDataGetBytePtr(uchrDataRef);
    1.34 +    else
    1.35 +        goto cleanup;
    1.36 +#else
    1.37      KLGetKeyboardLayoutProperty(key_layout, kKLuchrData, &chr_data);
    1.38 +#endif
    1.39      if (chr_data) {
    1.40          UInt32 keyboard_type = LMGetKbdType();
    1.41          OSStatus err;
    1.42 @@ -385,7 +401,8 @@
    1.43              }
    1.44  
    1.45              dead_key_state = 0;
    1.46 -            err = UCKeyTranslate (chr_data, i, kUCKeyActionDown,
    1.47 +            err = UCKeyTranslate ((UCKeyboardLayout *) chr_data,
    1.48 +                                  i, kUCKeyActionDown,
    1.49                                    0, keyboard_type,
    1.50                                    kUCKeyTranslateNoDeadKeysMask,
    1.51                                    &dead_key_state, 8, &len, s);
    1.52 @@ -400,6 +417,10 @@
    1.53          return;
    1.54      }
    1.55  
    1.56 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
    1.57 +cleanup:
    1.58 +    CFRelease(key_layout);
    1.59 +#else
    1.60      /* Fall back to older style key map data */
    1.61      KLGetKeyboardLayoutProperty(key_layout, kKLKCHRData, &chr_data);
    1.62      if (chr_data) {
    1.63 @@ -449,6 +470,7 @@
    1.64          SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
    1.65          return;
    1.66      }
    1.67 +#endif
    1.68  }
    1.69  
    1.70  void