src/video/uikit/SDL_uikitevents.m
author Sam Lantinga
Mon, 25 Jun 2012 11:10:34 -0400
changeset 6346 56871d364efc
parent 6138 4c64952a58fb
child 6684 992268e65626
permissions -rwxr-xr-x
Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
slouken@2765
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@2765
     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@2765
     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@2765
    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@2765
    20
*/
slouken@2765
    21
#include "SDL_config.h"
slouken@2765
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_UIKIT
slouken@6044
    24
slouken@2765
    25
#include "../../events/SDL_events_c.h"
slouken@2765
    26
slouken@2765
    27
#include "SDL_uikitvideo.h"
slouken@2765
    28
#include "SDL_uikitevents.h"
slouken@2765
    29
slouken@2765
    30
#import <Foundation/Foundation.h>
slouken@2765
    31
#include "jumphack.h"
slouken@2765
    32
slouken@6346
    33
static BOOL UIKit_EventPumpEnabled = YES;
slouken@6346
    34
slouken@6346
    35
void
slouken@6346
    36
SDL_iPhoneSetEventPump(SDL_bool enabled)
slouken@6346
    37
{
slouken@6346
    38
    UIKit_EventPumpEnabled = enabled;
slouken@6346
    39
}
slouken@6346
    40
slouken@2765
    41
void
slouken@2765
    42
UIKit_PumpEvents(_THIS)
slouken@2765
    43
{
slouken@6346
    44
    if (!UIKit_EventPumpEnabled)
slouken@6346
    45
        return;
slouken@6346
    46
kees@6001
    47
    /*
slouken@5131
    48
        When the user presses the 'home' button on the iPod
slouken@5131
    49
        the application exits -- immediatly.
kees@6001
    50
slouken@5131
    51
        Unlike in Mac OS X, it appears there is no way to cancel the termination.
kees@6001
    52
slouken@5131
    53
        This doesn't give the SDL user's application time to respond to an SDL_Quit event.
slouken@5131
    54
        So what we do is that in the UIApplicationDelegate class (SDLUIApplicationDelegate),
slouken@5131
    55
        when the delegate receives the ApplicationWillTerminate message, we execute
slouken@5131
    56
        a longjmp statement to get back here, preventing an immediate exit.
kees@6001
    57
     */
slouken@5131
    58
    if (setjmp(*jump_env()) == 0) {
slouken@5131
    59
        /* if we're setting the jump, rather than jumping back */
slouken@5131
    60
        SInt32 result;
slouken@5131
    61
        do {
slouken@5131
    62
            result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
kees@6003
    63
        } while (result == kCFRunLoopRunHandledSource);
slouken@5131
    64
    }
slouken@2765
    65
}
slouken@2765
    66
slouken@6044
    67
#endif /* SDL_VIDEO_DRIVER_UIKIT */
slouken@6044
    68
slouken@2765
    69
/* vi: set ts=4 sw=4 expandtab: */