# iOS System Callback (attn: Piotr Drapich) (fwd)

**URL:** <https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854>\
**Category:** SDL Development\
**Created:** [March 27, 2012, 6:48am UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854 "2012-03-27T06:48:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Drapich](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@Piotr\_Drapich](https://discourse.libsdl.org/u/Piotr_Drapich)\
**Post date:** [March 27, 2012, 6:48am UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/1 "2012-03-27T06:48:19Z")

</div>

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:
> 
> [SDL :: View topic - Can I do a patch for iOS system callbacks? (fwd)](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 \*/

+/\*\* + \* \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 (C) 1997-2012 Sam Lantinga + Copyright  
(C) 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 \*/

---

<div class="post-metadata">

**Author:** ![Piotr\_Drapich](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@Piotr\_Drapich](https://discourse.libsdl.org/u/Piotr_Drapich)\
**Post date:** [March 27, 2012, 7:19am UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/2 "2012-03-27T07:19:38Z")

</div>

It seems that it got mangled somehow so I’m sending it again.  
P.On Tue, 27 Mar 2012 @Piotr_Drapich wrote:

> 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,  
> Piotr
> 
> On 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:
> > 
> > [SDL :: View topic - Can I do a patch for iOS system callbacks? (fwd)](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 \*/

+/\*\*

- 
  - \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 (C) 1997-2012 Sam Lantinga

- Copyright (C) 1997-2011 Sam Lantinga 

+/\* 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 \*/

---

<div class="post-metadata">

**Author:** ![Tim\_Angus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/tim_angus/32/74_2.png) [@Tim\_Angus](https://discourse.libsdl.org/u/Tim_Angus)\
**Post date:** [March 27, 2012, 8:59am UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/3 "2012-03-27T08:59:42Z")

</div>

I sort of wonder if it’s a good idea expose the functionality by events  
as well as it implies it is expected to work OK where in many situations  
it won’t. It also means the same functionality is exposed in two  
different ways; this may be confusing.

Good work though :). I think your patch may be mixing spaces and tabs.On 27/03/2012 08:19, sdl at union.pl wrote:

> > 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

---

<div class="post-metadata">

**Author:** ![Vittorio\_Giovara](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@Vittorio\_Giovara](https://discourse.libsdl.org/u/Vittorio_Giovara)\
**Post date:** [March 27, 2012, 1:43pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/4 "2012-03-27T13:43:24Z")

</div>

Kudos for the patch!  
However if you want to quickly respond to events on ios isn’t it  
faster to just subclass the appdelegate and override the appropriate  
methods (applicationWillTerminate and friends)?

VittorioOn Tue, Mar 27, 2012 at 10:59 AM, Tim Angus wrote:

> On 27/03/2012 08:19, sdl at union.pl wrote:
> 
> > > 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
> 
> I sort of wonder if it’s a good idea expose the functionality by events as  
> well as it implies it is expected to work OK where in many situations it  
> won’t. It also means the same functionality is exposed in two different  
> ways; this may be confusing.
> 
> Good work though :). I think your patch may be mixing spaces and tabs.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Brian\_Barnes](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@Brian\_Barnes](https://discourse.libsdl.org/u/Brian_Barnes)\
**Post date:** [March 27, 2012, 2:09pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/5 "2012-03-27T14:09:50Z")

</div>

Tim Angus wrote:

> I sort of wonder if it’s a good idea expose the functionality by events  
> as well as it implies it is expected to work OK where in many situations  
> it won’t. It also means the same functionality is exposed in two  
> different ways; this may be confusing.
> 
> Good work though :). I think your patch may be mixing spaces and tabs.

I second the good job, I’ll be checking this out tonight.

Tim: Yeah, that would be part 2 if the powers that be eventually accept  
this patch. We will also need to remove all internal calls to pump  
events (not counting any poll event functions, obviously.) The most  
notable is in the GL swap.

All of that together should make SDL work well with iOS (as far as I know.)

[\>] Brian

---

<div class="post-metadata">

**Author:** ![Forest\_Hale](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Forest\_Hale](https://discourse.libsdl.org/u/Forest_Hale)\
**Post date:** [March 27, 2012, 8:16pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/6 "2012-03-27T20:16:13Z")

</div>

An observation: all iOS apps must respond to these events - they can be dummy handlers in some cases but they must respond, and any developer who isn’t providing these callbacks deserves to be slapped  
with a compile error.

Therefore, why not require that any SDL2 app compiled on iOS provide these functions? In other words, like SDL\_main, there would be a requirement for the app to have functions named  
SDL\_iOS\_App\_Terminate() and so on.

I leave the naming of these functions wide open to discussion, I’m just noting that an SDL2 app should not successfully compile on iOS unless it addresses these issues.On 03/27/2012 06:43 AM, Vittorio Giovara wrote:

> Kudos for the patch!  
> However if you want to quickly respond to events on ios isn’t it  
> faster to just subclass the appdelegate and override the appropriate  
> methods (applicationWillTerminate and friends)?
> 
> Vittorio
> 
> On Tue, Mar 27, 2012 at 10:59 AM, Tim Angus wrote:
> 
> > On 27/03/2012 08:19, sdl at union.pl wrote:
> > 
> > > > 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
> > 
> > I sort of wonder if it’s a good idea expose the functionality by events as  
> > well as it implies it is expected to work OK where in many situations it  
> > won’t. It also means the same functionality is exposed in two different  
> > ways; this may be confusing.
> > 
> > Good work though :). I think your patch may be mixing spaces and tabs.
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
LordHavoc  
Author of DarkPlaces Quake1 engine - [LadyHavoc's DarkPlaces Quake Modification](http://icculus.org/twilight/darkplaces)  
Co-designer of Nexuiz - [Nexuiz Classic – Alientrap](http://alientrap.org/nexuiz)  
“War does not prove who is right, it proves who is left.” - Unknown  
“Any sufficiently advanced technology is indistinguishable from a rigged demo.” - James Klass  
“A game is a series of interesting choices.” - Sid Meier

---

<div class="post-metadata">

**Author:** ![Brian\_Barnes](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@Brian\_Barnes](https://discourse.libsdl.org/u/Brian_Barnes)\
**Post date:** [March 27, 2012, 8:39pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/7 "2012-03-27T20:39:26Z")

</div>

Forest Hale wrote:

> An observation: all iOS apps must respond to these events - they can be dummy handlers in some cases but they must respond, and any developer who isn’t providing these callbacks deserves to be slapped  
> with a compile error.
> 
> Therefore, why not require that any SDL2 app compiled on iOS provide these functions? In other words, like SDL\_main, there would be a requirement for the app to have functions named  
> SDL\_iOS\_App\_Terminate() and so on.
> 
> I leave the naming of these functions wide open to discussion, I’m just noting that an SDL2 app should not successfully compile on iOS unless it addresses these issues.

I’ve got nothing against that but it means Piotr’s patch solution won’t  
be workable, as it’s more open ended, and, frankly, nothing stops you  
from creating SDL\_iOS\_App\_Terminate() with no function body.

Piotr’s patch solution, on the other, will work for further systems down  
the line (with different patch points.)

Is it really SDL2’s responsibility to police programmers?

(If I do have one requested change in Piotr’s stuff, it’s to add _IOS_  
to all the system event constants. They should probably be very  
specific to iOS and the android ones have _ANDROID_ and be specific to  
that.)

[\>] Brian

---

<div class="post-metadata">

**Author:** ![Forest\_Hale](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/439d5e/32.png) [@Forest\_Hale](https://discourse.libsdl.org/u/Forest_Hale)\
**Post date:** [March 27, 2012, 10:18pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/8 "2012-03-27T22:18:33Z")

</div>

In my experience anything important to basic functionality has every right to produce a compile error.

In this case, if someone forgets to handle all these callbacks, they run the risk of being rejected from the iOS appstore, a compile error is much more pleasant.On 03/27/2012 01:39 PM, Brian Barnes wrote:

> Is it really SDL2’s responsibility to police programmers?

–  
LordHavoc  
Author of DarkPlaces Quake1 engine - [LadyHavoc's DarkPlaces Quake Modification](http://icculus.org/twilight/darkplaces)  
Co-designer of Nexuiz - [Nexuiz Classic – Alientrap](http://alientrap.org/nexuiz)  
“War does not prove who is right, it proves who is left.” - Unknown  
“Any sufficiently advanced technology is indistinguishable from a rigged demo.” - James Klass  
“A game is a series of interesting choices.” - Sid Meier

---

<div class="post-metadata">

**Author:** ![Brian\_Barnes](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@Brian\_Barnes](https://discourse.libsdl.org/u/Brian_Barnes)\
**Post date:** [March 27, 2012, 10:44pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/9 "2012-03-27T22:44:21Z")

</div>

Piotr, could you put up that patch as a file somewhere? I’m not the expert on mercurial but it refuses to patch and I suspect it’s a copy-and-paste gremlin or a line-ending error.

[\>] Brian

---

<div class="post-metadata">

**Author:** ![Vittorio\_Giovara](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@Vittorio\_Giovara](https://discourse.libsdl.org/u/Vittorio_Giovara)\
**Post date:** [March 28, 2012, 9:25am UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/10 "2012-03-28T09:25:45Z")

</div>

Let’s not rush things, shall we? The hypothetical “maybe i will be  
rejected” is a threat that might be good to scare managers off, but  
for people who managed to get their code on ios, know that, unless  
you’re producing a very similar application the default ones or using  
private apis or trying to access network without checking if there is  
connectivity, it is quite unlikely to get a rejection these days.

Non responding to events will at worst cause crashes while entering or  
exiting background, and this will just lead to bad customer reviews…  
I don’t want to get a compile error for that… moreover SDL is being  
used also on Cydia, were there is no such restriction, why adding  
burden to those developers as well?

Finally, there other ways, like the one I mentioned, to respond to any  
event you like, just by subclassing the SDL\_UikitAppDelegate and  
override the methods you are interested in.

jm2c  
VittorioOn Wed, Mar 28, 2012 at 12:18 AM, Forest Hale wrote:

> On 03/27/2012 01:39 PM, Brian Barnes wrote:
> 
> > Is it really SDL2’s responsibility to police programmers?
> 
> In my experience anything important to basic functionality has every right to produce a compile error.
> 
> In this case, if someone forgets to handle all these callbacks, they run the risk of being rejected from the iOS appstore, a compile error is much more pleasant.
> 
> –  
> LordHavoc  
> Author of DarkPlaces Quake1 engine - [LadyHavoc's DarkPlaces Quake Modification](http://icculus.org/twilight/darkplaces)  
> Co-designer of Nexuiz - [Nexuiz Classic – Alientrap](http://alientrap.org/nexuiz)  
> “War does not prove who is right, it proves who is left.” - Unknown  
> “Any sufficiently advanced technology is indistinguishable from a rigged demo.” - James Klass  
> “A game is a series of interesting choices.” - Sid Meier
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Gabriel\_Jacobo](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gabriel_jacobo/32/1968_2.png) [@Gabriel\_Jacobo](https://discourse.libsdl.org/u/Gabriel_Jacobo)\
**Post date:** [March 28, 2012, 12:29pm UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/11 "2012-03-28T12:29:31Z")

</div>

> Finally, there other ways, like the one I mentioned, to respond to any  
> event you like, just by subclassing the SDL\_UikitAppDelegate and  
> override the methods you are interested in.
> 
> jm2c  
> Vittorio

I really appreciate the work being done by everyone to solve these  
issues and to make the patch work as best as possible, but I’d like to  
know…if what Vittorio says is true, that you can subclass  
SDL\_UikitAppDelegate and implements the callbacks there, it seems to  
me that would be the perfect solution as it would remain in the  
developer domain how to do so, and SDL will remain pristine in its  
throne of cross platformness (?). Worst case we can add some forced  
errors to warn developer that they must subclass…right?–  
Gabriel.

---

<div class="post-metadata">

**Author:** ![Piotr\_Drapich](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@Piotr\_Drapich](https://discourse.libsdl.org/u/Piotr_Drapich)\
**Post date:** [March 30, 2012, 12:03am UTC](https://discourse.libsdl.org/t/ios-system-callback-attn-piotr-drapich-fwd/18854/12 "2012-03-30T00:03:05Z")

</div>

Hi Vittorio,  
I think that you missed the whole point of this callback system:  
it is meant to be a “generic” implementation of system events on mobile  
platforms, not tied to a specific platform or operating system. It  
should provide a common set of system events and an unified way of  
handling them.

Here’s a table how these events map to various existing platforms:  
SDL iOS  
Android PlayBook Bada  
SDL\_SYSEVENT\_TERMINATE applicationWillTerminate  
OnDestroy NAVIGATOR\_EXIT  
Osp::App::Application::OnAppTerminating  
SDL\_SYSEVENT\_WILL\_SUSPEND applicationWillResignActive  
OnPause   
SDL\_SYSEVENT\_SUSPEND applicationDidEnterBackground  
onStop NAVIGATOR\_WINDOW\_INACTIVE  
Osp::App::Application::OnBackground  
SDL\_SYSEVENT\_WILL\_RESUME applicationWillEnterForeground   
SDL\_SYSEVENT\_RESUME applicationDidBecomeActive  
OnResume NAVIGATOR\_WINDOW\_ACTIVE  
Osp::App::Application::OnForeground  
SDL\_SYSEVENT\_LOWMEMORY applicationDidReceiveMemoryWarning  
NAVIGATOR\_LOW\_MEMORY Osp::App::Application::OnLowMemory  
SDL\_SYSEVENT\_ORIENTATION\_CHANGED didRotateFromInterfaceOrientation  
OnOrientationChanged NAVIGATOR\_ORIENTATION\_CHECK  
OnOrientationChanged

regards,  
Piotr

btw: Of course, you can subclass appdelegate which may be faster, but it  
will make your code platform dependent.On Wed, 28 Mar 2012, Vittorio Giovara wrote:

> Let’s not rush things, shall we? The hypothetical “maybe i will be  
> rejected” is a threat that might be good to scare managers off, but  
> for people who managed to get their code on ios, know that, unless  
> you’re producing a very similar application the default ones or using  
> private apis or trying to access network without checking if there is  
> connectivity, it is quite unlikely to get a rejection these days.
> 
> Non responding to events will at worst cause crashes while entering or  
> exiting background, and this will just lead to bad customer reviews…  
> I don’t want to get a compile error for that… moreover SDL is being  
> used also on Cydia, were there is no such restriction, why adding  
> burden to those developers as well?
> 
> Finally, there other ways, like the one I mentioned, to respond to any  
> event you like, just by subclassing the SDL\_UikitAppDelegate and  
> override the methods you are interested in.
> 
> jm2c  
> Vittorio
> 
> On Wed, Mar 28, 2012 at 12:18 AM, Forest Hale wrote:
> 
> > On 03/27/2012 01:39 PM, Brian Barnes wrote:
> > 
> > > Is it really SDL2’s responsibility to police programmers?
> > 
> > In my experience anything important to basic functionality has every right to produce a compile error.
> > 
> > In this case, if someone forgets to handle all these callbacks, they run the risk of being rejected from the iOS appstore, a compile error is much more pleasant.
> > 
> > –  
> > LordHavoc  
> > Author of DarkPlaces Quake1 engine - [LadyHavoc's DarkPlaces Quake Modification](http://icculus.org/twilight/darkplaces)  
> > Co-designer of Nexuiz - [Nexuiz Classic – Alientrap](http://alientrap.org/nexuiz)  
> > “War does not prove who is right, it proves who is left.” - Unknown  
> > “Any sufficiently advanced technology is indistinguishable from a rigged demo.” - James Klass  
> > “A game is a series of interesting choices.” - Sid Meier
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
