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. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40556
This commit is contained in:
parent
241cf39101
commit
e1ecdaaad4
3 changed files with 46 additions and 1 deletions
|
@ -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 @@ static void QZ_DoDeactivate (_THIS) {
|
|||
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, ¬ifier);
|
||||
|
||||
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;
|
||||
|
|
|
@ -131,7 +131,8 @@ typedef struct SDL_PrivateVideoData {
|
|||
SDLKey keymap[256]; /* Mac OS X to SDL key mapping */
|
||||
Uint32 current_mods; /* current keyboard modifiers, to track modifier state */
|
||||
Uint32 last_virtual_button;/* last virtual mouse button pressed */
|
||||
|
||||
io_connect_t powerConnection; /* used with IOKit to detect wake from sleep */
|
||||
|
||||
ImageDescriptionHandle yuv_idh;
|
||||
MatrixRecordPtr yuv_matrix;
|
||||
DecompressorComponent yuv_codec;
|
||||
|
@ -165,6 +166,7 @@ typedef struct SDL_PrivateVideoData {
|
|||
#define keymap (this->hidden->keymap)
|
||||
#define current_mods (this->hidden->current_mods)
|
||||
#define last_virtual_button (this->hidden->last_virtual_button)
|
||||
#define powerConnection (this->hidden->powerConnection)
|
||||
|
||||
#define yuv_idh (this->hidden->yuv_idh)
|
||||
#define yuv_matrix (this->hidden->yuv_matrix)
|
||||
|
|
|
@ -131,6 +131,9 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
|
|||
current_grab_mode = SDL_GRAB_OFF;
|
||||
in_foreground = YES;
|
||||
|
||||
/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
|
||||
QZ_RegisterForSleepNotifications (this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue