src/video/cocoa/SDL_cocoaevents.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 01 Jan 2017 18:33:28 -0800
changeset 10737 3406a0f8b041
parent 10669 70a77b67e8e2
child 11144 cccd37a9c28b
permissions -rw-r--r--
Updated copyright for 2017
slouken@1931
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@1931
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1931
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1931
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1931
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_COCOA
slouken@3120
    24
#include "SDL_timer.h"
slouken@1931
    25
slouken@1931
    26
#include "SDL_cocoavideo.h"
slouken@2738
    27
#include "../../events/SDL_events_c.h"
icculus@8648
    28
#include "SDL_assert.h"
alfred@9820
    29
#include "SDL_hints.h"
slouken@1931
    30
icculus@9364
    31
/* This define was added in the 10.9 SDK. */
icculus@9364
    32
#ifndef kIOPMAssertPreventUserIdleDisplaySleep
icculus@9364
    33
#define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
icculus@9364
    34
#endif
icculus@9364
    35
slouken@8239
    36
@interface SDLApplication : NSApplication
slouken@8239
    37
slouken@8239
    38
- (void)terminate:(id)sender;
slouken@10441
    39
- (void)sendEvent:(NSEvent *)theEvent;
slouken@8239
    40
slouken@8239
    41
@end
slouken@8239
    42
slouken@8239
    43
@implementation SDLApplication
slouken@8239
    44
slouken@8239
    45
// Override terminate to handle Quit and System Shutdown smoothly.
slouken@8239
    46
- (void)terminate:(id)sender
slouken@8239
    47
{
slouken@8239
    48
    SDL_SendQuit();
slouken@8239
    49
}
slouken@8239
    50
slouken@10535
    51
static SDL_bool s_bShouldHandleEventsInSDLApplication = SDL_FALSE;
slouken@10535
    52
slouken@10535
    53
static void Cocoa_DispatchEvent(NSEvent *theEvent)
slouken@10441
    54
{
slouken@10441
    55
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@10535
    56
slouken@10441
    57
    switch ([theEvent type]) {
slouken@10441
    58
        case NSLeftMouseDown:
slouken@10441
    59
        case NSOtherMouseDown:
slouken@10441
    60
        case NSRightMouseDown:
slouken@10441
    61
        case NSLeftMouseUp:
slouken@10441
    62
        case NSOtherMouseUp:
slouken@10441
    63
        case NSRightMouseUp:
slouken@10441
    64
        case NSLeftMouseDragged:
slouken@10441
    65
        case NSRightMouseDragged:
slouken@10441
    66
        case NSOtherMouseDragged: /* usually middle mouse dragged */
slouken@10441
    67
        case NSMouseMoved:
slouken@10441
    68
        case NSScrollWheel:
slouken@10441
    69
            Cocoa_HandleMouseEvent(_this, theEvent);
slouken@10441
    70
            break;
slouken@10441
    71
        case NSKeyDown:
slouken@10441
    72
        case NSKeyUp:
slouken@10441
    73
        case NSFlagsChanged:
slouken@10441
    74
            Cocoa_HandleKeyEvent(_this, theEvent);
slouken@10441
    75
            break;
slouken@10441
    76
        default:
slouken@10441
    77
            break;
slouken@10441
    78
    }
slouken@10535
    79
}
slouken@10535
    80
slouken@10535
    81
// Dispatch events here so that we can handle events caught by
slouken@10535
    82
// nextEventMatchingMask in SDL, as well as events caught by other
slouken@10535
    83
// processes (such as CEF) that are passed down to NSApp.
slouken@10535
    84
- (void)sendEvent:(NSEvent *)theEvent
slouken@10535
    85
{
slouken@10535
    86
    if (s_bShouldHandleEventsInSDLApplication) {
slouken@10535
    87
        Cocoa_DispatchEvent(theEvent);
slouken@10535
    88
    }
slouken@10535
    89
slouken@10441
    90
    [super sendEvent:theEvent];
slouken@10441
    91
}
slouken@10441
    92
slouken@8239
    93
@end // SDLApplication
slouken@8239
    94
slouken@1931
    95
/* setAppleMenu disappeared from the headers in 10.4 */
slouken@1931
    96
@interface NSApplication(NSAppleMenu)
slouken@1931
    97
- (void)setAppleMenu:(NSMenu *)menu;
slouken@1931
    98
@end
slouken@1931
    99
slouken@8986
   100
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
jorgen@7801
   101
@public
jorgen@7469
   102
    BOOL seenFirstActivate;
jorgen@7469
   103
}
jorgen@7469
   104
jorgen@7469
   105
- (id)init;
slouken@1937
   106
@end
slouken@1937
   107
slouken@1937
   108
@implementation SDLAppDelegate : NSObject
jorgen@7469
   109
- (id)init
jorgen@7469
   110
{
jorgen@7469
   111
    self = [super init];
jorgen@7469
   112
    if (self) {
icculus@9419
   113
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
icculus@9419
   114
jorgen@7469
   115
        seenFirstActivate = NO;
icculus@9419
   116
icculus@9419
   117
        [center addObserver:self
icculus@9419
   118
                   selector:@selector(windowWillClose:)
icculus@9419
   119
                       name:NSWindowWillCloseNotification
icculus@9419
   120
                     object:nil];
icculus@9419
   121
icculus@9419
   122
        [center addObserver:self
icculus@9419
   123
                   selector:@selector(focusSomeWindow:)
icculus@9419
   124
                       name:NSApplicationDidBecomeActiveNotification
icculus@9419
   125
                     object:nil];
jorgen@7469
   126
    }
jorgen@7469
   127
jorgen@7469
   128
    return self;
jorgen@7469
   129
}
jorgen@7469
   130
jorgen@7801
   131
- (void)dealloc
jorgen@7801
   132
{
icculus@9419
   133
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
icculus@9419
   134
icculus@9419
   135
    [center removeObserver:self name:NSWindowWillCloseNotification object:nil];
icculus@9419
   136
    [center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
icculus@9419
   137
jorgen@7801
   138
    [super dealloc];
jorgen@7801
   139
}
jorgen@7801
   140
icculus@9419
   141
- (void)windowWillClose:(NSNotification *)notification;
icculus@9419
   142
{
icculus@9419
   143
    NSWindow *win = (NSWindow*)[notification object];
icculus@9419
   144
icculus@9419
   145
    if (![win isKeyWindow]) {
icculus@9419
   146
        return;
icculus@9419
   147
    }
icculus@9419
   148
icculus@9419
   149
    /* HACK: Make the next window in the z-order key when the key window is
icculus@9419
   150
     * closed. The custom event loop and/or windowing code we have seems to
icculus@9419
   151
     * prevent the normal behavior: https://bugzilla.libsdl.org/show_bug.cgi?id=1825
icculus@9419
   152
     */
icculus@9419
   153
icculus@9419
   154
    /* +[NSApp orderedWindows] never includes the 'About' window, but we still
icculus@9419
   155
     * want to try its list first since the behavior in other apps is to only
icculus@9419
   156
     * make the 'About' window key if no other windows are on-screen.
icculus@9419
   157
     */
icculus@9419
   158
    for (NSWindow *window in [NSApp orderedWindows]) {
icculus@9419
   159
        if (window != win && [window canBecomeKeyWindow]) {
slime73@10176
   160
            if (![window isOnActiveSpace]) {
slime73@10176
   161
                continue;
icculus@9419
   162
            }
icculus@9419
   163
            [window makeKeyAndOrderFront:self];
icculus@9419
   164
            return;
icculus@9419
   165
        }
icculus@9419
   166
    }
icculus@9419
   167
slime73@10176
   168
    /* If a window wasn't found above, iterate through all visible windows in
slime73@10176
   169
     * the active Space in z-order (including the 'About' window, if it's shown)
slime73@10176
   170
     * and make the first one key.
icculus@9419
   171
     */
slime73@10176
   172
    for (NSNumber *num in [NSWindow windowNumbersWithOptions:0]) {
slime73@10176
   173
        NSWindow *window = [NSApp windowWithWindowNumber:[num integerValue]];
slime73@10176
   174
        if (window && window != win && [window canBecomeKeyWindow]) {
slime73@10176
   175
            [window makeKeyAndOrderFront:self];
slime73@10176
   176
            return;
icculus@9419
   177
        }
icculus@9419
   178
    }
icculus@9419
   179
}
icculus@9419
   180
jorgen@7801
   181
- (void)focusSomeWindow:(NSNotification *)aNotification
jorgen@7466
   182
{
jorgen@7469
   183
    /* HACK: Ignore the first call. The application gets a
jorgen@7469
   184
     * applicationDidBecomeActive: a little bit after the first window is
jorgen@7469
   185
     * created, and if we don't ignore it, a window that has been created with
icculus@9419
   186
     * SDL_WINDOW_MINIMIZED will ~immediately be restored.
jorgen@7469
   187
     */
jorgen@7469
   188
    if (!seenFirstActivate) {
jorgen@7469
   189
        seenFirstActivate = YES;
jorgen@7469
   190
        return;
jorgen@7469
   191
    }
jorgen@7469
   192
jorgen@7466
   193
    SDL_VideoDevice *device = SDL_GetVideoDevice();
slouken@8986
   194
    if (device && device->windows) {
jorgen@7466
   195
        SDL_Window *window = device->windows;
jorgen@7466
   196
        int i;
slouken@8986
   197
        for (i = 0; i < device->num_displays; ++i) {
jorgen@7466
   198
            SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
slouken@8986
   199
            if (fullscreen_window) {
jorgen@7466
   200
                if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
jorgen@7466
   201
                    SDL_RestoreWindow(fullscreen_window);
jorgen@7466
   202
                }
jorgen@7466
   203
                return;
jorgen@7466
   204
            }
jorgen@7466
   205
        }
jorgen@7466
   206
jorgen@7466
   207
        if (window->flags & SDL_WINDOW_MINIMIZED) {
jorgen@7466
   208
            SDL_RestoreWindow(window);
jorgen@7466
   209
        } else {
jorgen@7466
   210
            SDL_RaiseWindow(window);
jorgen@7466
   211
        }
jorgen@7466
   212
    }
jorgen@7466
   213
}
jorgen@7466
   214
slouken@6091
   215
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
slouken@6091
   216
{
icculus@10022
   217
    return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL);
slouken@6091
   218
}
slouken@1937
   219
@end
slouken@1937
   220
jorgen@7801
   221
static SDLAppDelegate *appDelegate = nil;
jorgen@7801
   222
slouken@1931
   223
static NSString *
slouken@1931
   224
GetApplicationName(void)
slouken@1931
   225
{
slouken@8237
   226
    NSString *appName;
slouken@1931
   227
slouken@1931
   228
    /* Determine the application name */
slouken@8237
   229
    appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
slouken@8986
   230
    if (!appName) {
slouken@8237
   231
        appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
slouken@8986
   232
    }
slouken@7191
   233
slouken@8986
   234
    if (![appName length]) {
slouken@1931
   235
        appName = [[NSProcessInfo processInfo] processName];
slouken@8986
   236
    }
slouken@1931
   237
slouken@1931
   238
    return appName;
slouken@1931
   239
}
slouken@1931
   240
slouken@1931
   241
static void
slouken@1931
   242
CreateApplicationMenus(void)
slouken@1931
   243
{
slouken@1931
   244
    NSString *appName;
slouken@1931
   245
    NSString *title;
slouken@1931
   246
    NSMenu *appleMenu;
slouken@6515
   247
    NSMenu *serviceMenu;
slouken@1931
   248
    NSMenu *windowMenu;
slouken@7952
   249
    NSMenu *viewMenu;
slouken@1931
   250
    NSMenuItem *menuItem;
icculus@8653
   251
    NSMenu *mainMenu;
slouken@7191
   252
slouken@7511
   253
    if (NSApp == nil) {
jorgen@7508
   254
        return;
jorgen@7508
   255
    }
icculus@8653
   256
icculus@8653
   257
    mainMenu = [[NSMenu alloc] init];
icculus@8653
   258
slouken@1931
   259
    /* Create the main menu bar */
icculus@8653
   260
    [NSApp setMainMenu:mainMenu];
icculus@8653
   261
icculus@8653
   262
    [mainMenu release];  /* we're done with it, let NSApp own it. */
icculus@8653
   263
    mainMenu = nil;
slouken@1931
   264
slouken@1931
   265
    /* Create the application menu */
slouken@1931
   266
    appName = GetApplicationName();
slouken@1931
   267
    appleMenu = [[NSMenu alloc] initWithTitle:@""];
slouken@7191
   268
slouken@1931
   269
    /* Add menu items */
slouken@1931
   270
    title = [@"About " stringByAppendingString:appName];
slouken@1931
   271
    [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
slouken@1931
   272
slouken@1931
   273
    [appleMenu addItem:[NSMenuItem separatorItem]];
slouken@1931
   274
slouken@6515
   275
    [appleMenu addItemWithTitle:@"Preferences…" action:nil keyEquivalent:@","];
slouken@6515
   276
slouken@6515
   277
    [appleMenu addItem:[NSMenuItem separatorItem]];
slouken@6515
   278
slouken@6515
   279
    serviceMenu = [[NSMenu alloc] initWithTitle:@""];
slouken@6515
   280
    menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
slouken@6515
   281
    [menuItem setSubmenu:serviceMenu];
slouken@6515
   282
slouken@6515
   283
    [NSApp setServicesMenu:serviceMenu];
slouken@6836
   284
    [serviceMenu release];
slouken@5377
   285
slouken@5377
   286
    [appleMenu addItem:[NSMenuItem separatorItem]];
slouken@5377
   287
slouken@1931
   288
    title = [@"Hide " stringByAppendingString:appName];
slouken@6515
   289
    [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
slouken@1931
   290
slouken@6515
   291
    menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
slouken@1931
   292
    [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
slouken@1931
   293
slouken@1931
   294
    [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
slouken@1931
   295
slouken@1931
   296
    [appleMenu addItem:[NSMenuItem separatorItem]];
slouken@1931
   297
slouken@1931
   298
    title = [@"Quit " stringByAppendingString:appName];
slouken@6515
   299
    [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
slouken@7191
   300
slouken@1931
   301
    /* Put menu into the menubar */
slouken@1931
   302
    menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
slouken@1931
   303
    [menuItem setSubmenu:appleMenu];
slouken@1931
   304
    [[NSApp mainMenu] addItem:menuItem];
slouken@1931
   305
    [menuItem release];
slouken@1931
   306
slouken@1931
   307
    /* Tell the application object that this is now the application menu */
slouken@1931
   308
    [NSApp setAppleMenu:appleMenu];
slouken@1931
   309
    [appleMenu release];
slouken@1931
   310
slouken@1931
   311
slouken@1931
   312
    /* Create the window menu */
slouken@1931
   313
    windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
slouken@7191
   314
slouken@6515
   315
    /* Add menu items */
slouken@6515
   316
    [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
slouken@7191
   317
slouken@6515
   318
    [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
slouken@6515
   319
slouken@1931
   320
    /* Put menu into the menubar */
slouken@1931
   321
    menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
slouken@1931
   322
    [menuItem setSubmenu:windowMenu];
slouken@1931
   323
    [[NSApp mainMenu] addItem:menuItem];
slouken@1931
   324
    [menuItem release];
slouken@7191
   325
slouken@1931
   326
    /* Tell the application object that this is now the window menu */
slouken@1931
   327
    [NSApp setWindowsMenu:windowMenu];
slouken@1931
   328
    [windowMenu release];
slouken@7952
   329
slouken@7952
   330
slouken@7952
   331
    /* Add the fullscreen view toggle menu option, if supported */
slime73@10176
   332
    if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
slouken@7952
   333
        /* Create the view menu */
slouken@7952
   334
        viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
slouken@7952
   335
slouken@7952
   336
        /* Add menu items */
slouken@7952
   337
        menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
slouken@7952
   338
        [menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
slouken@7952
   339
slouken@7952
   340
        /* Put menu into the menubar */
slouken@7952
   341
        menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
slouken@7952
   342
        [menuItem setSubmenu:viewMenu];
slouken@7952
   343
        [[NSApp mainMenu] addItem:menuItem];
slouken@7952
   344
        [menuItem release];
slouken@7952
   345
slouken@7952
   346
        [viewMenu release];
slouken@7952
   347
    }
slouken@1931
   348
}
slouken@1931
   349
slouken@1931
   350
void
slouken@1931
   351
Cocoa_RegisterApp(void)
slouken@9087
   352
{ @autoreleasepool
slouken@1931
   353
{
icculus@6639
   354
    /* This can get called more than once! Be careful what you initialize! */
slouken@1931
   355
slouken@6848
   356
    if (NSApp == nil) {
slouken@8239
   357
        [SDLApplication sharedApplication];
icculus@8648
   358
        SDL_assert(NSApp != nil);
slouken@1931
   359
slouken@10535
   360
        s_bShouldHandleEventsInSDLApplication = SDL_TRUE;
slouken@10535
   361
slouken@10499
   362
        if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
slime73@10176
   363
            [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
alfred@9820
   364
            [NSApp activateIgnoringOtherApps:YES];
alfred@9820
   365
		}
alfred@9820
   366
		
slouken@6848
   367
        if ([NSApp mainMenu] == nil) {
slouken@6848
   368
            CreateApplicationMenus();
slouken@1931
   369
        }
slouken@6848
   370
        [NSApp finishLaunching];
slouken@8289
   371
        NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
slouken@8290
   372
            [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
slouken@8290
   373
            [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
jorgen@8718
   374
            [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
slouken@8290
   375
            nil];
slouken@7739
   376
        [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
icculus@8648
   377
        [appDefaults release];
slouken@1931
   378
    }
jorgen@7801
   379
    if (NSApp && !appDelegate) {
jorgen@7801
   380
        appDelegate = [[SDLAppDelegate alloc] init];
jorgen@7801
   381
jorgen@7801
   382
        /* If someone else has an app delegate, it means we can't turn a
jorgen@7801
   383
         * termination into SDL_Quit, and we can't handle application:openFile:
jorgen@7801
   384
         */
jorgen@7801
   385
        if (![NSApp delegate]) {
slouken@8986
   386
            [(NSApplication *)NSApp setDelegate:appDelegate];
jorgen@7801
   387
        } else {
jorgen@7801
   388
            appDelegate->seenFirstActivate = YES;
jorgen@7801
   389
        }
slouken@6848
   390
    }
slouken@9087
   391
}}
slouken@1931
   392
slouken@1931
   393
void
slouken@1931
   394
Cocoa_PumpEvents(_THIS)
slouken@9087
   395
{ @autoreleasepool
slouken@1931
   396
{
slouken@10669
   397
    /* Update activity every 30 seconds to prevent screensaver */
slouken@10669
   398
    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
slouken@10669
   399
    if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
slouken@10669
   400
        Uint32 now = SDL_GetTicks();
slouken@10669
   401
        if (!data->screensaver_activity ||
slouken@10669
   402
            SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
slouken@10669
   403
            UpdateSystemActivity(UsrActivity);
slouken@10669
   404
            data->screensaver_activity = now;
slouken@10669
   405
        }
slouken@10669
   406
    }
slouken@10669
   407
slouken@6848
   408
    for ( ; ; ) {
slouken@6848
   409
        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
slouken@6848
   410
        if ( event == nil ) {
slouken@6848
   411
            break;
slouken@1931
   412
        }
slouken@7191
   413
slouken@10535
   414
        if (!s_bShouldHandleEventsInSDLApplication) {
slouken@10535
   415
            Cocoa_DispatchEvent(event);
slouken@10535
   416
        }
slouken@10535
   417
slouken@10441
   418
        // Pass events down to SDLApplication to be handled in sendEvent:
slouken@6848
   419
        [NSApp sendEvent:event];
slouken@1931
   420
    }
slouken@9087
   421
}}
slouken@1931
   422
icculus@9364
   423
void
icculus@9364
   424
Cocoa_SuspendScreenSaver(_THIS)
icculus@9364
   425
{ @autoreleasepool
icculus@9364
   426
{
icculus@9364
   427
    SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
icculus@9364
   428
slouken@10669
   429
    if (!data->screensaver_use_iopm) {
slouken@10669
   430
        return;
slouken@10669
   431
    }
slouken@10669
   432
icculus@9364
   433
    if (data->screensaver_assertion) {
icculus@9364
   434
        IOPMAssertionRelease(data->screensaver_assertion);
icculus@9364
   435
        data->screensaver_assertion = 0;
icculus@9364
   436
    }
icculus@9364
   437
icculus@9364
   438
    if (_this->suspend_screensaver) {
icculus@9364
   439
        /* FIXME: this should ideally describe the real reason why the game
icculus@9364
   440
         * called SDL_DisableScreenSaver. Note that the name is only meant to be
icculus@9364
   441
         * seen by OS X power users. there's an additional optional human-readable
icculus@9364
   442
         * (localized) reason parameter which we don't set.
icculus@9364
   443
         */
icculus@9364
   444
        NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
icculus@9364
   445
        IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
icculus@9364
   446
                                           (CFStringRef) name,
icculus@9364
   447
                                           NULL, NULL, NULL, 0, NULL,
icculus@9364
   448
                                           &data->screensaver_assertion);
icculus@9364
   449
    }
icculus@9364
   450
}}
icculus@9364
   451
slouken@6044
   452
#endif /* SDL_VIDEO_DRIVER_COCOA */
slouken@6044
   453
slouken@1931
   454
/* vi: set ts=4 sw=4 expandtab: */