HI Brian,
Unfortunately I dont have such space available now, I’m posting below the
latest version of my callback implementation - let me know if you can use
to patch SDL source successfully.
Btw: this is the latest version, with new SDL_SYSEVENT_ORIENTATION_CHANGED
event and Android support.
regards,
PiotrOn Fri, 30 Mar 2012, Brian Barnes wrote:
Piotr, can you put the patch up somewhere I can grab it as a file? My
cut-n-paste job from the mail doesn’t give me a file I can patch with –
whatever it is, line endings, etc, I don’t know. I’d like to get to
testing this ASAP.
[>] Brian
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 Sun Apr 01 03:37:26 2012 +0200
@@ -106,6 +106,16 @@
/* 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,
- SDL_SYSEVENT_ORIENTATION_CHANGED,
- /* Drag and drop events */
SDL_DROPFILE = 0x1000, /**< The system requests a file open */
@@ -382,6 +392,22 @@
Uint32 timestamp;
} SDL_QuitEvent;
+/**
+typedef struct SDL_SystemEvent
+{
- Uint32 type;
- Uint32 timestamp;
- void *data;
+} SDL_SystemEvent;
-
+typedef enum
+{
- SDL_ORIENTATION_PORTRAIT,
- SDL_ORIENTATION_LANDSCAPE
+} SDL_DeviceOrientation;
/**
- \brief A user-defined event type (event.user.*)
@@ -438,6 +464,7 @@
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 +646,16 @@
*/
extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
+/**
-
-
-
/
+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/core/android/SDL_android.cpp
— a/src/core/android/SDL_android.cpp Tue Feb 28 21:58:36 2012 -0500
+++ b/src/core/android/SDL_android.cpp Sun Apr 01 03:37:26 2012 +0200
@@ -168,14 +168,28 @@
JNIEnv env, jclass cls)
{
// Inject a SDL_QUIT event
// Pause
extern “C” void Java_org_libsdl_app_SDLActivity_nativePause(
JNIEnv* env, jclass cls)
{
typedef struct SDL_EventWatcher {
SDL_EventFilter callback;
@@ -529,4 +530,13 @@
return (posted);
}
+void
+SDL_SetSystemEventHook(SDL_SystemEventHandler 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 Sun Apr 01 03:37:26 2012 +0200
@@ -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 Sun Apr 01 03:37:26 2012 +0200
@@ -123,7 +123,12 @@
- (void)applicationWillTerminate:(UIApplication *)application
{
- SDL_SendQuit();
- (void) applicationWillResignActive:(UIApplication*)application
{
//NSLog(@"%@", NSStringFromSelector(_cmd));
- // 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_FOCUS_LOST, 0, 0);
-
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
+{
+}
+
± (void)applicationWillEnterForeground:(UIApplication*)application
+{
}
-
(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
+{
+}
@end
#endif /* SDL_VIDEO_DRIVER_UIKIT */
diff -r 6bb657898f55 src/video/uikit/SDL_uikitviewcontroller.m
— a/src/video/uikit/SDL_uikitviewcontroller.m Tue Feb 28 21:58:36 2012 -0500
+++ b/src/video/uikit/SDL_uikitviewcontroller.m Sun Apr 01 03:37:26 2012 +0200
@@ -121,18 +121,23 @@
CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
const CGSize size = frame.size;
int w, h;
-
SDL_Event event;
-
event.type=SDL_SYSEVENT_ORIENTATION_CHANGED;
-
event.sysevent.data=NULL;
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
w = (size.width < size.height) ? size.width : size.height;
h = (size.width > size.height) ? size.width : size.height;
-
event.sysevent.data=(void*)SDL_ORIENTATION_PORTRAIT;
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
w = (size.width > size.height) ? size.width : size.height;
h = (size.width < size.height) ? size.width : size.height;
-
event.sysevent.data=(void*)SDL_ORIENTATION_LANDSCAPE;
break;
default:
@@ -140,13 +145,18 @@
return;
}
-
if (SDL_SysEventHandler)
-
SDL_SysEventHandler(&event);
-
w = (int)(w * displaymodedata->scale);
h = (int)(h * displaymodedata->scale);
[uiwindow setFrame:frame];
[data->view setFrame:frame];
[data->view updateFrame];
- SDL_SendWindowEvent(self->window, SDL_WINDOWEVENT_RESIZED, w, h);
#endif /* SDL_VIDEO_DRIVER_UIKIT */