27 #include <IOKit/IOMessage.h>
28 #include <IOKit/pwr_mgt/IOPMLib.h>
34 #if defined(__LP64__) && !defined(__POWER__)
50 #include <IOKit/hidsystem/IOLLEvent.h>
55 #ifndef NX_DEVICERCTLKEYMASK
56 #define NX_DEVICELCTLKEYMASK 0x00000001
58 #ifndef NX_DEVICELSHIFTKEYMASK
59 #define NX_DEVICELSHIFTKEYMASK 0x00000002
61 #ifndef NX_DEVICERSHIFTKEYMASK
62 #define NX_DEVICERSHIFTKEYMASK 0x00000004
64 #ifndef NX_DEVICELCMDKEYMASK
65 #define NX_DEVICELCMDKEYMASK 0x00000008
67 #ifndef NX_DEVICERCMDKEYMASK
68 #define NX_DEVICERCMDKEYMASK 0x00000010
70 #ifndef NX_DEVICELALTKEYMASK
71 #define NX_DEVICELALTKEYMASK 0x00000020
73 #ifndef NX_DEVICERALTKEYMASK
74 #define NX_DEVICERALTKEYMASK 0x00000040
76 #ifndef NX_DEVICERCTLKEYMASK
77 #define NX_DEVICERCTLKEYMASK 0x00002000
215 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
216 if (TISCopyCurrentKeyboardLayoutInputSource !=
NULL) {
217 TISInputSourceRef
src = TISCopyCurrentKeyboardLayoutInputSource();
219 CFDataRef
data = (CFDataRef)
220 TISGetInputSourceProperty(src,
221 kTISPropertyUnicodeKeyLayoutData);
223 const UCKeyboardLayout *layout = (
const UCKeyboardLayout *)
224 CFDataGetBytePtr(data);
225 if (layout !=
NULL) {
226 const UInt32 kbdtype = LMGetKbdType();
230 for (i = 0; i < 0x7F; i++) {
232 UniCharCount
count = 0;
237 if (UCKeyTranslate(layout, i, kUCKeyActionDown, 0, kbdtype,
238 0, &state, 16, &count, buf) != noErr) {
246 if (UCKeyTranslate(layout, i, kUCKeyActionDown, 0, kbdtype,
247 0, &state, 16, &count, buf) != noErr) {
256 value = (UInt32) buf[0];
262 }
else if (value >= 32) {
273 #if (MAC_OS_X_VERSION_MIN_REQUIRED < 1050)
276 const void *KCHRPtr = (
const void *)GetScriptManagerVariable(smKCHRCache);
280 for (i = 0; i < 0x7F; i++)
286 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
291 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
298 }
else if (value >= 32) {
335 NSString *chars =
NULL;
336 unsigned int i, numChars;
348 [field_edit interpretKeyEvents:[NSArray arrayWithObject:event]];
349 chars = [ event characters ];
350 numChars = [ chars length ];
352 [field_edit setString:@""];
366 else if (numChars >= 1) {
370 key.
unicode = [ chars characterAtIndex:0 ];
375 for (i = 1; i < numChars; i++) {
379 key.
unicode = [ chars characterAtIndex:i];
387 [ NSApp sendEvent:event ];
407 for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++
i) {
409 unsigned int currentMask, newMask;
412 newMask = newMods & bit;
415 currentMask != newMask ) {
417 key.
sym = mapping[i];
419 if (bit == NSAlphaShiftKeyMask)
424 currentMask != newMask ) {
426 key.
sym = mapping[i];
429 if (bit == NSAlphaShiftKeyMask)
440 unsigned int currentMask, newMask;
452 newMask = newMods & device_independent_mask;
455 currentMask != newMask ) {
459 currentMask != newMask ) {
468 unsigned int key_sym,
469 unsigned int sided_device_dependent_mask ) {
472 unsigned int current_dep_mask, new_dep_mask;
482 current_dep_mask =
current_mods & sided_device_dependent_mask;
483 new_dep_mask = newMods & sided_device_dependent_mask;
490 current_dep_mask != new_dep_mask ) {
504 unsigned int newMods,
505 unsigned int left_key_sym,
506 unsigned int right_key_sym,
507 unsigned int left_device_dependent_mask,
508 unsigned int right_device_dependent_mask ) {
509 unsigned int device_dependent_mask = 0;
510 unsigned int diff_mod = 0;
512 device_dependent_mask = left_device_dependent_mask | right_device_dependent_mask;
517 if ( (device_dependent_mask & newMods) == 0 ) {
525 ^ (device_dependent_mask & newMods);
532 if ( left_device_dependent_mask & diff_mod ) {
535 if ( right_device_dependent_mask & diff_mod ) {
547 unsigned int device_independent_mask,
548 unsigned int newMods,
549 unsigned int left_key_sym,
550 unsigned int right_key_sym,
551 unsigned int left_device_dependent_mask,
552 unsigned int right_device_dependent_mask ) {
553 unsigned int device_dependent_mask = 0;
561 device_dependent_mask = left_device_dependent_mask | right_device_dependent_mask;
570 key.
sym = left_key_sym;
583 if ( left_device_dependent_mask & current_mods ) {
584 key.
sym = left_key_sym;
587 if ( right_device_dependent_mask & current_mods ) {
588 key.
sym = right_key_sym;
597 unsigned int currentMask, newMask;
606 newMask = newMods & NSAlphaShiftKeyMask;
609 currentMask != newMask ) {
615 currentMask != newMask ) {
642 for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++
i) {
644 unsigned int currentMask, newMask;
647 newMask = newMods & bit;
656 left_device_mapping[i],
657 right_device_mapping[i] );
662 else if ( currentMask &&
663 currentMask != newMask ) {
667 left_device_mapping[i],
668 right_device_mapping[i] );
699 *p = [ NSEvent mouseLocation ];
736 CGAssociateMouseAndMouseCursorPosition (1);
742 io_service_t service,
743 natural_t messageType,
744 void * messageArgument )
750 case kIOMessageSystemWillSleep:
753 case kIOMessageCanSystemSleep:
756 case kIOMessageSystemHasPoweredOn:
765 CFRunLoopSourceRef rls;
766 IONotificationPortRef thePortRef;
767 io_object_t notifier;
772 NSLog(
@"SDL: QZ_SleepNotificationHandler() IORegisterForSystemPower failed.");
774 rls = IONotificationPortGetRunLoopSource (thePortRef);
775 CFRunLoopAddSource (CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
805 NSAutoreleasePool *pool;
812 static Uint32 screensaverTicks;
814 if ((nowTicks - screensaverTicks) > 5000)
816 UpdateSystemActivity(UsrActivity);
817 screensaverTicks = nowTicks;
821 pool = [ [ NSAutoreleasePool alloc ] init ];
822 distantPast = [ NSDate distantPast ];
833 event = [ NSApp nextEventMatchingMask:NSAnyEventMask
834 untilDate:distantPast
835 inMode: NSDefaultRunLoopMode dequeue:YES ];
842 #define DO_MOUSE_DOWN(button) do { \
843 if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { \
844 SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \
845 expect_mouse_up |= 1<<button; \
847 [ NSApp sendEvent:event ]; \
850 #define DO_MOUSE_UP(button) do { \
851 if ( expect_mouse_up & (1<<button) ) { \
852 SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); \
853 expect_mouse_up &= ~(1<<button); \
855 [ NSApp sendEvent:event ]; \
858 type = [ event type ];
864 case NSLeftMouseDown:
872 else if ( NSAlternateKeyMask & current_mods ) {
892 case NSOtherMouseDown:
893 case NSRightMouseDown:
904 case NSSystemDefined:
912 case NSLeftMouseDragged:
913 case NSRightMouseDragged:
914 case NSOtherMouseDragged:
924 CGGetLastMouseDelta (&dx1, &dy1);
962 if ( p.x >= winRect.size.width )
963 p.x = winRect.size.width-1;
965 if ( p.y >= winRect.size.height )
966 p.y = winRect.size.height-1;
989 CGAssociateMouseAndMouseCursorPosition (1);
1002 CGAssociateMouseAndMouseCursorPosition (0);
1007 if ( isInGameWin ) {
1010 dy = [ event deltaY ];
1011 dx = [ event deltaX ];
1014 else if ( dy < 0.0 )
1029 case NSFlagsChanged:
1031 case NSAppKitDefined:
1032 [ NSApp sendEvent:event ];
1037 [ sdlc->wm_cursor->nscursor set ];
1045 [ NSApp sendEvent:event ];
1048 }
while (event != nil);
1051 if (dx != 0 || dy != 0)