src/video/quartz/SDL_QuartzEvents.m
changeset 555 2536446a92de
parent 511 79c189f5bd76
child 561 4bcf7dd06c47
equal deleted inserted replaced
554:38b1a98aeb11 555:2536446a92de
    18 
    18 
    19     Sam Lantinga
    19     Sam Lantinga
    20     slouken@libsdl.org
    20     slouken@libsdl.org
    21 */
    21 */
    22 #include <stdlib.h>	// For getenv()
    22 #include <stdlib.h>	// For getenv()
       
    23 #include <IOKit/IOMessage.h> // For wake from sleep detection
       
    24 #include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection
    23 #include "SDL_QuartzKeys.h"
    25 #include "SDL_QuartzKeys.h"
    24 
    26 
    25 static void     QZ_InitOSKeymap (_THIS) {
    27 static void     QZ_InitOSKeymap (_THIS) {
    26     const void *KCHRPtr;
    28     const void *KCHRPtr;
    27     UInt32 state;
    29     UInt32 state;
   302     }
   304     }
   303 
   305 
   304     SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   306     SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
   305 }
   307 }
   306 
   308 
       
   309 void QZ_SleepNotificationHandler (void * refcon,
       
   310                                   io_service_t service,
       
   311                                   natural_t messageType,
       
   312                                   void * messageArgument )
       
   313 {
       
   314      SDL_VideoDevice *this = (SDL_VideoDevice*)refcon;
       
   315      
       
   316      switch(messageType)
       
   317      {
       
   318          case kIOMessageSystemWillSleep:
       
   319              IOAllowPowerChange(powerConnection, (long) messageArgument);
       
   320              break;
       
   321          case kIOMessageCanSystemSleep:
       
   322              IOAllowPowerChange(powerConnection, (long) messageArgument);
       
   323              break;
       
   324          case kIOMessageSystemHasPoweredOn:
       
   325 			/* awake */
       
   326             SDL_PrivateExpose();
       
   327             break;
       
   328      }
       
   329 }
       
   330 
       
   331 static void QZ_RegisterForSleepNotifications (_THIS)
       
   332 {
       
   333      CFRunLoopSourceRef rls;
       
   334      IONotificationPortRef thePortRef;
       
   335      io_object_t notifier;
       
   336 
       
   337      powerConnection = IORegisterForSystemPower (this, &thePortRef, QZ_SleepNotificationHandler, &notifier);
       
   338 
       
   339      if (powerConnection == 0)
       
   340          NSLog(@"SDL: QZ_SleepNotificationHandler() IORegisterForSystemPower failed.");
       
   341 
       
   342      rls = IONotificationPortGetRunLoopSource (thePortRef);
       
   343      CFRunLoopAddSource (CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
       
   344      CFRelease (rls);
       
   345 }
       
   346 
   307 static void QZ_PumpEvents (_THIS)
   347 static void QZ_PumpEvents (_THIS)
   308 {
   348 {
   309     int firstMouseEvent;
   349     int firstMouseEvent;
   310     CGMouseDelta dx, dy;
   350     CGMouseDelta dx, dy;
   311 
   351