iPhone interruption patch / SDL 1.3
authorSam Lantinga <slouken@libsdl.org>
Sat, 17 Oct 2009 07:36:45 +0000
changeset 34004ec48602f1db
parent 3399 f96615051c8c
child 3401 244ca085c026
iPhone interruption patch / SDL 1.3

Eric Wing to Sam

I've been sitting on this too long. I need to push.
It's untested because of the unrelated crashing bug I've been experiencing.
Also have a fix for SIZEOF_VOIDP in the config for both iPhone and Mac.
include/SDL_config_iphoneos.h
include/SDL_config_macosx.h
include/SDL_video.h
src/video/cocoa/SDL_cocoawindow.h
src/video/uikit/SDL_uikitappdelegate.h
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/include/SDL_config_iphoneos.h	Tue Oct 13 20:17:11 2009 +0000
     1.2 +++ b/include/SDL_config_iphoneos.h	Sat Oct 17 07:36:45 2009 +0000
     1.3 @@ -35,6 +35,12 @@
     1.4  typedef unsigned long uintptr_t;
     1.5  #endif /* !_STDINT_H_ && !HAVE_STDINT_H */
     1.6  
     1.7 +#ifdef __LP64__
     1.8 +#define SIZEOF_VOIDP 8
     1.9 +#else
    1.10 +#define SIZEOF_VOIDP 4
    1.11 +#endif
    1.12 +
    1.13  #define SDL_HAS_64BIT_TYPE	1
    1.14  
    1.15  #define HAVE_ALLOCA_H		1
     2.1 --- a/include/SDL_config_macosx.h	Tue Oct 13 20:17:11 2009 +0000
     2.2 +++ b/include/SDL_config_macosx.h	Sat Oct 17 07:36:45 2009 +0000
     2.3 @@ -30,7 +30,12 @@
     2.4  
     2.5  /* This is a set of defines to configure the SDL features */
     2.6  
     2.7 -#define SIZEOF_VOIDP 4
     2.8 +#ifdef __LP64__
     2.9 +	#define SIZEOF_VOIDP 8
    2.10 +#else
    2.11 +	#define SIZEOF_VOIDP 4
    2.12 +#endif
    2.13 +
    2.14  #define SDL_HAS_64BIT_TYPE	1
    2.15  
    2.16  /* Useful headers */
     3.1 --- a/include/SDL_video.h	Tue Oct 13 20:17:11 2009 +0000
     3.2 +++ b/include/SDL_video.h	Sat Oct 17 07:36:45 2009 +0000
     3.3 @@ -414,8 +414,9 @@
     3.4   */
     3.5  extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode);
     3.6  
     3.7 +
     3.8  /**
     3.9 - * \fn SDL_DisplayMode *SDL_GetClosestDisplayMode(const SDL_DisplayMode *mode, SDL_DisplayMode *closest)
    3.10 + * \fn SDL_DisplayMode SDL_GetClosestDisplayMode(const SDL_DisplayMode mode, SDL_DisplayMode closest)
    3.11   *
    3.12   * \brief Get the closest match to the requested display mode.
    3.13   *
     4.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Tue Oct 13 20:17:11 2009 +0000
     4.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Sat Oct 17 07:36:45 2009 +0000
     4.3 @@ -24,10 +24,16 @@
     4.4  #ifndef _SDL_cocoawindow_h
     4.5  #define _SDL_cocoawindow_h
     4.6  
     4.7 +#import <Cocoa/Cocoa.h>
     4.8 +
     4.9  typedef struct SDL_WindowData SDL_WindowData;
    4.10  
    4.11  /* *INDENT-OFF* */
    4.12 -@interface Cocoa_WindowListener:NSResponder {
    4.13 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
    4.14 +@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
    4.15 +#else
    4.16 +@interface Cocoa_WindowListener : NSResponder {
    4.17 +#endif		
    4.18      SDL_WindowData *_data;
    4.19  }
    4.20  
     5.1 --- a/src/video/uikit/SDL_uikitappdelegate.h	Tue Oct 13 20:17:11 2009 +0000
     5.2 +++ b/src/video/uikit/SDL_uikitappdelegate.h	Sat Oct 17 07:36:45 2009 +0000
     5.3 @@ -26,9 +26,11 @@
     5.4  /* *INDENT-OFF* */
     5.5  @interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
     5.6      UIWindow *window;
     5.7 +	SDL_WindowID windowID;
     5.8  }
     5.9  
    5.10  @property (readwrite, retain) UIWindow *window;
    5.11 +@property (readwrite, assign) SDL_WindowID windowID;
    5.12  
    5.13  +(SDLUIKitDelegate *)sharedAppDelegate;
    5.14  
     6.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Tue Oct 13 20:17:11 2009 +0000
     6.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Sat Oct 17 07:36:45 2009 +0000
     6.3 @@ -56,6 +56,7 @@
     6.4  @implementation SDLUIKitDelegate
     6.5  
     6.6  @synthesize window;
     6.7 +@synthesize windowID;
     6.8  
     6.9  /* convenience method */
    6.10  +(SDLUIKitDelegate *)sharedAppDelegate {
    6.11 @@ -66,6 +67,7 @@
    6.12  - (id)init {
    6.13  	self = [super init];
    6.14  	window = nil;
    6.15 +	windowID = 0;
    6.16  	return self;
    6.17  }
    6.18  
    6.19 @@ -97,6 +99,20 @@
    6.20  	
    6.21  }
    6.22  
    6.23 +- (void) applicationWillResignActive:(UIApplication*)application
    6.24 +{
    6.25 +//	NSLog(@"%@", NSStringFromSelector(_cmd));
    6.26 +	SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
    6.27 +}
    6.28 +
    6.29 +- (void) applicationDidBecomeActive:(UIApplication*)application
    6.30 +{
    6.31 +//	NSLog(@"%@", NSStringFromSelector(_cmd));
    6.32 +	SDL_SendWindowEvent(self.windowID, SDL_WINDOWEVENT_RESTORED, 0, 0);
    6.33 +}
    6.34 +
    6.35 +
    6.36 +
    6.37  -(void)dealloc {
    6.38  	[window release];
    6.39  	[super dealloc];
     7.1 --- a/src/video/uikit/SDL_uikitwindow.m	Tue Oct 13 20:17:11 2009 +0000
     7.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Sat Oct 17 07:36:45 2009 +0000
     7.3 @@ -82,7 +82,7 @@
     7.4  
     7.5  int UIKit_CreateWindow(_THIS, SDL_Window *window) {
     7.6  		
     7.7 -	/* iPhone applications are single window only */
     7.8 +	/* We currently only handle single window applications on iPhone */
     7.9  	if (nil != [SDLUIKitDelegate sharedAppDelegate].window) {
    7.10  		SDL_SetError("Window already exists, no multi-window support.");
    7.11  		return -1;
    7.12 @@ -96,7 +96,10 @@
    7.13          return -1;
    7.14      }	
    7.15  	
    7.16 +	// This saves the main window in the app delegate so event callbacks can do stuff on the window.
    7.17 +	// This assumes a single window application design and needs to be fixed for multiple windows.
    7.18  	[SDLUIKitDelegate sharedAppDelegate].window = uiwindow;
    7.19 +	[SDLUIKitDelegate sharedAppDelegate].windowID = window->id;
    7.20  	[uiwindow release]; /* release the window (the app delegate has retained it) */
    7.21  	
    7.22  	return 1;
    7.23 @@ -113,6 +116,7 @@
    7.24  
    7.25  	/* this will also destroy the window */
    7.26  	[SDLUIKitDelegate sharedAppDelegate].window = nil;
    7.27 +	[SDLUIKitDelegate sharedAppDelegate].windowID = 0;
    7.28  
    7.29  }
    7.30