src/video/uikit/SDL_uikitevents.m
author Alex Szpakowski <slime73@gmail.com>
Fri, 01 Apr 2016 19:18:50 -0300
changeset 10139 bb54e1e47110
parent 9998 f67cf37e9cd4
child 10141 fe9cf7c678f4
permissions -rw-r--r--
iOS: Workaround for a crash after Dictation is used.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7285
diff changeset
    21
#include "../../SDL_internal.h"
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    23
#if SDL_VIDEO_DRIVER_UIKIT
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    24
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "../../events/SDL_events_c.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "SDL_uikitvideo.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_uikitevents.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#import <Foundation/Foundation.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    32
static BOOL UIKit_EventPumpEnabled = YES;
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    33
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    34
void
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    35
SDL_iPhoneSetEventPump(SDL_bool enabled)
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    36
{
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    37
    UIKit_EventPumpEnabled = enabled;
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    38
}
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    39
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
UIKit_PumpEvents(_THIS)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
{
9487
f9fbc2d1edb0 Misc. iOS code improvements.
Alex Szpakowski <slime73@gmail.com>
parents: 8149
diff changeset
    43
    if (!UIKit_EventPumpEnabled) {
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    44
        return;
9487
f9fbc2d1edb0 Misc. iOS code improvements.
Alex Szpakowski <slime73@gmail.com>
parents: 8149
diff changeset
    45
    }
6346
56871d364efc Disable the SDL event pump after the SDL main routine returns, since events will be dispatched by the Cocoa event loop.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    46
7284
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    47
    /* Let the run loop run for a short amount of time: long enough for
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    48
       touch events to get processed (which is important to get certain
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    49
       elements of Game Center's GKLeaderboardViewController to respond
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    50
       to touch input), but not long enough to introduce a significant
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    51
       delay in the rest of the app.
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    52
    */
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    53
    const CFTimeInterval seconds = 0.000002;
6857
dd4c12f0358b converted tabs to spaces in iOS/UIKit PumpEvents code
DavidLudwig <dludwig@pobox.com>
parents: 6685
diff changeset
    54
7284
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    55
    /* Pump most event types. */
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    56
    SInt32 result;
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    57
    do {
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    58
        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, seconds, TRUE);
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    59
    } while (result == kCFRunLoopRunHandledSource);
6857
dd4c12f0358b converted tabs to spaces in iOS/UIKit PumpEvents code
DavidLudwig <dludwig@pobox.com>
parents: 6685
diff changeset
    60
7284
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    61
    /* Make sure UIScrollView objects scroll properly. */
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    62
    do {
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    63
        result = CFRunLoopRunInMode((CFStringRef)UITrackingRunLoopMode, seconds, TRUE);
ac3f4830ae25 The jump hack is no longer used.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    64
    } while(result == kCFRunLoopRunHandledSource);
10139
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    65
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    66
    @autoreleasepool {
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    67
        /* Some iOS system functionality (such as Dictation on the on-screen
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    68
           keyboard) uses its own OpenGL ES context but doesn't restore the
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    69
           previous one when it's done. This is a workaround to make sure the
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    70
           expected SDL-created OpenGL ES context is active after the OS is
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    71
           finished running its own code for the frame. If this isn't done, the
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    72
           app may crash or have other nasty symptoms when Dictation is used.
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    73
         */
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    74
        EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    75
        if (context != NULL && [EAGLContext currentContext] != context) {
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    76
            [EAGLContext setCurrentContext:context];
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    77
        }
bb54e1e47110 iOS: Workaround for a crash after Dictation is used.
Alex Szpakowski <slime73@gmail.com>
parents: 9998
diff changeset
    78
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    81
#endif /* SDL_VIDEO_DRIVER_UIKIT */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6003
diff changeset
    82
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
/* vi: set ts=4 sw=4 expandtab: */