/*
SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2009 Sam Lantinga
+ Copyright (C) 1997-2012 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
#endif
void QZ_InitOSKeymap (_THIS) {
- const void *KCHRPtr;
+ BOOL saw_layout = NO;
UInt32 state;
UInt32 value;
- int i;
+ Uint16 i;
int world = SDLK_WORLD_0;
for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
why we keep the static table, too.
*/
- /* Get a pointer to the systems cached KCHR */
- KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
- if (KCHRPtr)
- {
- /* Loop over all 127 possible scan codes */
- for (i = 0; i < 0x7F; i++)
- {
- /* We pretend a clean start to begin with (i.e. no dead keys active */
- state = 0;
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
+ if (TISCopyCurrentKeyboardLayoutInputSource != NULL) {
+ TISInputSourceRef src = TISCopyCurrentKeyboardLayoutInputSource();
+ if (src != NULL) {
+ CFDataRef data = (CFDataRef)
+ TISGetInputSourceProperty(src,
+ kTISPropertyUnicodeKeyLayoutData);
+ if (data != NULL) {
+ const UCKeyboardLayout *layout = (const UCKeyboardLayout *)
+ CFDataGetBytePtr(data);
+ if (layout != NULL) {
+ const UInt32 kbdtype = LMGetKbdType();
+ saw_layout = YES;
+
+ /* Loop over all 127 possible scan codes */
+ for (i = 0; i < 0x7F; i++) {
+ UniChar buf[16];
+ UniCharCount count = 0;
+
+ /* We pretend a clean start to begin with (i.e. no dead keys active */
+ state = 0;
+
+ if (UCKeyTranslate(layout, i, kUCKeyActionDown, 0, kbdtype,
+ 0, &state, 16, &count, buf) != noErr) {
+ continue;
+ }
+
+ /* If the state become 0, it was a dead key. We need to
+ translate again, passing in the new state, to get
+ the actual key value */
+ if (state != 0) {
+ if (UCKeyTranslate(layout, i, kUCKeyActionDown, 0, kbdtype,
+ 0, &state, 16, &count, buf) != noErr) {
+ continue;
+ }
+ }
+
+ if (count != 1) {
+ continue; /* no multi-char. Use SDL 1.3 instead. :) */
+ }
+
+ value = (UInt32) buf[0];
+ if (value >= 128) {
+ /* Some non-ASCII char, map it to SDLK_WORLD_* */
+ if (world < 0xFF) {
+ keymap[i] = world++;
+ }
+ } else if (value >= 32) { /* non-control ASCII char */
+ keymap[i] = value;
+ }
+ }
+ }
+ }
+ CFRelease(src);
+ }
+ }
+#endif
- /* Now translate the key code to a key value */
- value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1050)
+ if (!saw_layout) {
+ /* Get a pointer to the systems cached KCHR */
+ const void *KCHRPtr = (const void *)GetScriptManagerVariable(smKCHRCache);
+ if (KCHRPtr)
+ {
+ /* Loop over all 127 possible scan codes */
+ for (i = 0; i < 0x7F; i++)
+ {
+ /* We pretend a clean start to begin with (i.e. no dead keys active */
+ state = 0;
- /* If the state become 0, it was a dead key. We need to translate again,
- passing in the new state, to get the actual key value */
- if (state != 0)
+ /* Now translate the key code to a key value */
value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
- /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
- if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
- keymap[i] = world++;
- else if (value >= 32) /* non-control ASCII char */
- keymap[i] = value;
+ /* If the state become 0, it was a dead key. We need to translate again,
+ passing in the new state, to get the actual key value */
+ if (state != 0)
+ value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
+
+ /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
+ if (value >= 128) { /* Some non-ASCII char, map it to SDLK_WORLD_* */
+ if (world < 0xFF) {
+ keymap[i] = world++;
+ }
+ } else if (value >= 32) { /* non-control ASCII char */
+ keymap[i] = value;
+ }
+ }
}
}
+#endif
/*
The keypad codes are re-setup here, because the loop above cannot
QZ_GetMouseLocation (this, &p);
SDL_PrivateMouseMotion (0, 0, p.x, p.y);
}
+
+ QZ_UpdateCursor(this);
}
void QZ_DoDeactivate (_THIS) {
void QZ_PumpEvents (_THIS)
{
- CGMouseDelta dx, dy;
+ int32_t dx, dy;
NSDate *distantPast;
NSEvent *event;
so we have to call the lowlevel window server
function. This is less accurate but works OK.
*/
- CGMouseDelta dx1, dy1;
+ int32_t dx1, dy1;
CGGetLastMouseDelta (&dx1, &dy1);
dx += dx1;
dy += dy1;