Hi Brian,
Here’s a diff for my callback implementation based on the latest
SDL source from hg. It also implements all important iOS events as SDL
events:
SDL_SYSEVENT_TERMINATE
SDL_SYSEVENT_WILL_SUSPEND
SDL_SYSEVENT_SUSPEND
SDL_SYSEVENT_WILL_RESUME
SDL_SYSEVENT_RESUME
SDL_SYSEVENT_LOWMEMORY
regards,
PiotrOn Sun, 18 Mar 2012, Brian Barnes wrote:
I’m finally getting back to this. Has there been any movement or additional thought on Poitr’s patch? The original message:
http://forums.libsdl.org/viewtopic.php?t=7733&sid=21dffacbd29855581fe66d8a1126a1df
Piotr, do you have a new version of this patch that conforms with the current trunk of SDL2? I’ll retest it for you.
diff -r 6bb657898f55 include/SDL_events.h — a/include/SDL_events.h Tue
Feb 28 21:58:36 2012 -0500 +++ b/include/SDL_events.h Thu Mar 22 04:10:18
2012 +0100 @@ -104,11 +104,27 @@
SDL_MULTIGESTURE,
/* Clipboard events */ +
SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
-
/* System events */ + + SDL_SYSEVENT_TERMINATE = 0xa00, +
SDL_SYSEVENT_WILL_SUSPEND, + SDL_SYSEVENT_SUSPEND, +
SDL_SYSEVENT_WILL_RESUME, + SDL_SYSEVENT_RESUME, + SDL_SYSEVENT_LOWMEMORY, -
/* Drag and drop events */
SDL_DROPFILE = 0x1000, /**< The system requests a file open *//** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
* and should be allocated with SDL_RegisterEvents()
*/ @@ -382,6 +398,16 @@
Uint32 timestamp;
} SDL_QuitEvent;
+/** + * \brief System event + */ + +typedef struct SDL_SystemEvent +{ +
Uint32 type; + Uint32 timestamp; + void *data; +} SDL_SystemEvent;
/**
- \brief A user-defined event type (event.user.*) @@ -413,6 +439,36 @@
SDL_SysWMmsg *msg; /**< driver dependent data, defined in
SDL_syswm.h */
} SDL_SysWMEvent;
/**
- \brief General event structure
*/ @@ -438,6 +494,14 @@
SDL_MultiGestureEvent mgesture; /< Multi Finger Gesture data */
SDL_DollarGestureEvent dgesture; /< Multi Finger Gesture data */
SDL_DropEvent drop; /< Drag and drop event data */ +
SDL_SystemEvent sysevent; /< System event data */
} SDL_Event;
@@ -619,6 +683,16 @@
*/
extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
+/** + * Set system event hook + * + / +typedef int (SDLCALL *
SDL_SystemEventHandler) (SDL_Event event); + +extern DECLSPEC void
SDLCALL SDL_SetSystemEventHook(SDL_SystemEventHandler handler); + + +
/* Ends C function definitions when using C++ /
#ifdef __cplusplus
/ INDENT-OFF / diff -r 6bb657898f55 src/events/SDL_events.c —
a/src/events/SDL_events.c Tue Feb 28 21:58:36 2012 -0500 +++
b/src/events/SDL_events.c Thu Mar 22 04:10:18 2012 +0100 @@ -36,6 +36,7 @@
/ Public data – the event filter */
SDL_EventFilter SDL_EventOK = NULL;
void *SDL_EventOKParam; +SDL_SystemEventHandler SDL_SysEventHandler =
NULL;
typedef struct SDL_EventWatcher {
SDL_EventFilter callback; @@ -359,6 +360,7 @@
{
SDL_EventWatcher *curr;
event->window.timestamp = SDL_GetTicks(); +
if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
return 0;
} @@ -529,4 +531,13 @@
return (posted);
}
+void +SDL_SetSystemEventHook(SDL_SystemEventHandler handler) +{ + if
(handler) + { + SDL_SysEventHandler=handler; + } +} +
/* vi: set ts=4 sw=4 expandtab: / diff -r 6bb657898f55
src/events/SDL_events_c.h — a/src/events/SDL_events_c.h Tue Feb 28
21:58:36 2012 -0500 +++ b/src/events/SDL_events_c.h Thu Mar 22 04:10:18
2012 +0100 @@ -1,6 +1,7 @@
/
Simple DirectMedia Layer
Copyright © 1997-2012 Sam Lantinga + Copyright
© 1997-2011 Sam Lantinga
This software is provided ‘as-is’, without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -46,4 +47,7 @@
extern SDL_EventFilter SDL_EventOK;
extern void *SDL_EventOKParam;
+/* The system event hook function / +extern SDL_SystemEventHandler
SDL_SysEventHandler; +
/ vi: set ts=4 sw=4 expandtab: */ diff -r 6bb657898f55
src/video/uikit/SDL_uikitappdelegate.m —
a/src/video/uikit/SDL_uikitappdelegate.m Tue Feb 28 21:58:36 2012 -0500
+++ b/src/video/uikit/SDL_uikitappdelegate.m Thu Mar 22 04:10:18 2012
+0100 @@ -123,7 +123,12 @@
-
(void)applicationWillTerminate:(UIApplication )application
{ - SDL_SendQuit(); + SDL_Event event; +
event.type=SDL_SYSEVENT_TERMINATE; + event.sysevent.data=NULL; + if
(SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else
SDL_SendQuit();
/ hack to prevent automatic termination. See SDL_uikitevents.m for
details /
longjmp((jump_env()), 1);
} @@ -131,37 +136,81 @@ -
(void) applicationWillResignActive:(UIApplication*)application
{
//NSLog(@"%@", NSStringFromSelector(_cmd)); + SDL_Event event; +
event.type=SDL_SYSEVENT_WILL_SUSPEND; + event.sysevent.data=NULL; + if
(SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else { + // Send
every window on every screen a MINIMIZED event. + SDL_VideoDevice *_this =
SDL_GetVideoDevice(); + if (!_this) { + return; + } -
// Send every window on every screen a MINIMIZED event. -
SDL_VideoDevice *_this = SDL_GetVideoDevice(); - if (!_this) { - return; -
} + SDL_Window *window; + for (window = _this->windows; window != nil;
window = window->next) { + SDL_SendWindowEvent(window,
SDL_WINDOWEVENT_MINIMIZED, 0, 0); + } + } +} -
SDL_Window window; - for (window = _this->windows; window != nil;
window = window->next) { - SDL_SendWindowEvent(window,
SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); - SDL_SendWindowEvent(window,
SDL_WINDOWEVENT_MINIMIZED, 0, 0); - } ±
(void)applicationDidEnterBackground:(UIApplication)application +{ +
//NSLog(@"%@", NSStringFromSelector(_cmd)); + + SDL_Event event; +
event.type=SDL_SYSEVENT_SUSPEND; + event.sysevent.data=NULL; + if
(SDL_SysEventHandler) + SDL_SysEventHandler(&event); +} + ±
(void)applicationWillEnterForeground:(UIApplication*)application +{ +
//NSLog(@"%@", NSStringFromSelector(_cmd)); + + SDL_Event event; +
event.type=SDL_SYSEVENT_WILL_RESUME; + event.sysevent.data=NULL; + if
(SDL_SysEventHandler) + SDL_SysEventHandler(&event);
} -
(void) applicationDidBecomeActive:(UIApplication*)application
{
//NSLog(@"%@", NSStringFromSelector(_cmd)); -
// Send every window on every screen a RESTORED event. - SDL_VideoDevice
*_this = SDL_GetVideoDevice(); - if (!_this) { - return; - } + SDL_Event
event; + event.type=SDL_SYSEVENT_RESUME; + event.sysevent.data=NULL; + if
(SDL_SysEventHandler) + SDL_SysEventHandler(&event); + else { + // Send
every window on every screen a RESTORED event. + SDL_VideoDevice *_this =
SDL_GetVideoDevice(); + if (!_this) { + return; + } -
SDL_Window *window; - for (window = _this->windows; window != nil;
window = window->next) { - SDL_SendWindowEvent(window,
SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); - SDL_SendWindowEvent(window,
SDL_WINDOWEVENT_RESTORED, 0, 0); - } + SDL_Window *window; + for (window =
_this->windows; window != nil; window = window->next) { +
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); +
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); + } + }
}
± (void)applicationDidReceiveMemoryWarning:(UIApplication*)application +{
- //NSLog(@"%@", NSStringFromSelector(_cmd)); + + SDL_Event event; +
event.type=SDL_SYSEVENT_LOWMEMORY; + event.sysevent.data=NULL; + if
(SDL_SysEventHandler) + SDL_SysEventHandler(&event); +}
@end
#endif /* SDL_VIDEO_DRIVER_UIKIT */