src/video/cocoa/SDL_cocoaevents.m
author Ryan C. Gordon
Sun, 22 Mar 2015 01:25:12 -0400
changeset 9419 9763f689bced
parent 9364 ad9d35983de5
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Cocoa: Handle more cases of lost focus when Key window closes (thanks, Alex!).

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