Fixed bug 3503 - osx builds don't run on 10.6 as of rev. 10651
authorSam Lantinga <slouken@libsdl.org>
Thu, 01 Dec 2016 11:52:47 -0800
changeset 1066970a77b67e8e2
parent 10668 1889c850fafc
child 10670 bb7d3a4f58b0
Fixed bug 3503 - osx builds don't run on 10.6 as of rev. 10651

Ozkan Sezer

With rev. 10651, i.e. http://hg.libsdl.org/SDL/rev/f0065b8e6541 ,
SDL2 - OS X builds fail to run on 10.6 (my setup: i686 / 10.6.8)
because the symbol _IOPMAssertionCreateWithDescription is missing.
The SDK listing it for 10.7+ does seem correct. Reverting r10651
and rebuilding makes it to function again.
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoavideo.h
src/video/cocoa/SDL_cocoavideo.m
     1.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Wed Nov 30 22:06:05 2016 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Thu Dec 01 11:52:47 2016 -0800
     1.3 @@ -394,6 +394,17 @@
     1.4  Cocoa_PumpEvents(_THIS)
     1.5  { @autoreleasepool
     1.6  {
     1.7 +    /* Update activity every 30 seconds to prevent screensaver */
     1.8 +    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
     1.9 +    if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
    1.10 +        Uint32 now = SDL_GetTicks();
    1.11 +        if (!data->screensaver_activity ||
    1.12 +            SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
    1.13 +            UpdateSystemActivity(UsrActivity);
    1.14 +            data->screensaver_activity = now;
    1.15 +        }
    1.16 +    }
    1.17 +
    1.18      for ( ; ; ) {
    1.19          NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    1.20          if ( event == nil ) {
    1.21 @@ -415,6 +426,10 @@
    1.22  {
    1.23      SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
    1.24  
    1.25 +    if (!data->screensaver_use_iopm) {
    1.26 +        return;
    1.27 +    }
    1.28 +
    1.29      if (data->screensaver_assertion) {
    1.30          IOPMAssertionRelease(data->screensaver_assertion);
    1.31          data->screensaver_assertion = 0;
     2.1 --- a/src/video/cocoa/SDL_cocoavideo.h	Wed Nov 30 22:06:05 2016 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoavideo.h	Thu Dec 01 11:52:47 2016 -0800
     2.3 @@ -52,6 +52,7 @@
     2.4      SDLTranslatorResponder *fieldEdit;
     2.5      NSInteger clipboard_count;
     2.6      Uint32 screensaver_activity;
     2.7 +    BOOL screensaver_use_iopm;
     2.8      IOPMAssertionID screensaver_assertion;
     2.9  
    2.10  } SDL_VideoData;
     3.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Wed Nov 30 22:06:05 2016 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Thu Dec 01 11:52:47 2016 -0800
     3.3 @@ -152,6 +152,9 @@
     3.4  
     3.5      data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
     3.6  
     3.7 +    /* The IOPM assertion API can disable the screensaver as of 10.7. */
     3.8 +    data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
     3.9 +
    3.10      return 0;
    3.11  }
    3.12