diff src/video/quartz/SDL_QuartzEvents.m @ 555:2536446a92de

From: Darrell Walisser Subject: Re: [SDL] OS X and power save Here ya go. This works just fine. One might complain that it doesn't generate the event until after wake as completed (there is about 5 seconds between the screen coming up and the expose event), but I think that's OK.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 07 Dec 2002 06:48:49 +0000
parents 79c189f5bd76
children 4bcf7dd06c47
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzEvents.m	Mon Dec 02 03:11:36 2002 +0000
+++ b/src/video/quartz/SDL_QuartzEvents.m	Sat Dec 07 06:48:49 2002 +0000
@@ -20,6 +20,8 @@
     slouken@libsdl.org
 */
 #include <stdlib.h>	// For getenv()
+#include <IOKit/IOMessage.h> // For wake from sleep detection
+#include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection
 #include "SDL_QuartzKeys.h"
 
 static void     QZ_InitOSKeymap (_THIS) {
@@ -304,6 +306,44 @@
     SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
 }
 
+void QZ_SleepNotificationHandler (void * refcon,
+                                  io_service_t service,
+                                  natural_t messageType,
+                                  void * messageArgument )
+{
+     SDL_VideoDevice *this = (SDL_VideoDevice*)refcon;
+     
+     switch(messageType)
+     {
+         case kIOMessageSystemWillSleep:
+             IOAllowPowerChange(powerConnection, (long) messageArgument);
+             break;
+         case kIOMessageCanSystemSleep:
+             IOAllowPowerChange(powerConnection, (long) messageArgument);
+             break;
+         case kIOMessageSystemHasPoweredOn:
+			/* awake */
+            SDL_PrivateExpose();
+            break;
+     }
+}
+
+static void QZ_RegisterForSleepNotifications (_THIS)
+{
+     CFRunLoopSourceRef rls;
+     IONotificationPortRef thePortRef;
+     io_object_t notifier;
+
+     powerConnection = IORegisterForSystemPower (this, &thePortRef, QZ_SleepNotificationHandler, &notifier);
+
+     if (powerConnection == 0)
+         NSLog(@"SDL: QZ_SleepNotificationHandler() IORegisterForSystemPower failed.");
+
+     rls = IONotificationPortGetRunLoopSource (thePortRef);
+     CFRunLoopAddSource (CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
+     CFRelease (rls);
+}
+
 static void QZ_PumpEvents (_THIS)
 {
     int firstMouseEvent;