summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/events/SDL_events.c2
-rw-r--r--src/events/SDL_events_c.h2
-rw-r--r--src/events/SDL_quit.c135
3 files changed, 92 insertions, 47 deletions
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 1177d6c41d..74db470bed 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -689,7 +689,7 @@ SDL_PumpEvents(void)
}
#endif
- SDL_SendPendingQuit(); /* in case we had a signal handler fire, etc. */
+ SDL_SendPendingSignalEvents(); /* in case we had a signal handler fire, etc. */
}
/* Public functions */
diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h
index 6d6809633f..d8c92fee70 100644
--- a/src/events/SDL_events_c.h
+++ b/src/events/SDL_events_c.h
@@ -52,7 +52,7 @@ extern int SDL_SendQuit(void);
extern int SDL_EventsInit(void);
extern void SDL_EventsQuit(void);
-extern void SDL_SendPendingQuit(void);
+extern void SDL_SendPendingSignalEvents(void);
#endif /* SDL_events_c_h_ */
diff --git a/src/events/SDL_quit.c b/src/events/SDL_quit.c
index 6daed40414..78864f236f 100644
--- a/src/events/SDL_quit.c
+++ b/src/events/SDL_quit.c
@@ -34,6 +34,14 @@
static SDL_bool disable_signals = SDL_FALSE;
static SDL_bool send_quit_pending = SDL_FALSE;
+#ifdef SDL_BACKGROUNDING_SIGNAL
+static SDL_bool send_backgrounding_pending = SDL_FALSE;
+#endif
+
+#ifdef SDL_FOREGROUNDING_SIGNAL
+static SDL_bool send_foregrounding_pending = SDL_FALSE;
+#endif
+
#ifdef HAVE_SIGNAL_H
static void
SDL_HandleSIG(int sig)
@@ -43,46 +51,81 @@ SDL_HandleSIG(int sig)
/* Send a quit event next time the event loop pumps. */
/* We can't send it in signal handler; malloc() might be interrupted! */
- send_quit_pending = SDL_TRUE;
+ if ((sig == SIGINT) || (sig == SIGTERM)) {
+ send_quit_pending = SDL_TRUE;
+ }
+
+ #ifdef SDL_BACKGROUNDING_SIGNAL
+ else if (sig == SDL_BACKGROUNDING_SIGNAL) {
+ send_backgrounding_pending = SDL_TRUE;
+ }
+ #endif
+
+ #ifdef SDL_FOREGROUNDING_SIGNAL
+ else if (sig == SDL_FOREGROUNDING_SIGNAL) {
+ send_foregrounding_pending = SDL_TRUE;
+ }
+ #endif
}
#endif /* HAVE_SIGNAL_H */
-/* Public functions */
-static int
-SDL_QuitInit_Internal(void)
+static void
+SDL_EventSignal_Init(const int sig)
{
#ifdef HAVE_SIGACTION
struct sigaction action;
- sigaction(SIGINT, NULL, &action);
+
+ sigaction(sig, NULL, &action);
#ifdef HAVE_SA_SIGACTION
if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
#else
if ( action.sa_handler == SIG_DFL ) {
#endif
action.sa_handler = SDL_HandleSIG;
- sigaction(SIGINT, &action, NULL);
+ sigaction(sig, &action, NULL);
+ }
+#elif HAVE_SIGNAL_H
+ void (*ohandler) (int) = signal(sig, SDL_HandleSIG);
+ if (ohandler != SIG_DFL) {
+ signal(sig, ohandler);
}
- sigaction(SIGTERM, NULL, &action);
-
-#ifdef HAVE_SA_SIGACTION
- if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
-#else
- if ( action.sa_handler == SIG_DFL ) {
#endif
- action.sa_handler = SDL_HandleSIG;
- sigaction(SIGTERM, &action, NULL);
+}
+
+static void
+SDL_EventSignal_Quit(const int sig)
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction action;
+ sigaction(sig, NULL, &action);
+ if ( action.sa_handler == SDL_HandleSIG ) {
+ action.sa_handler = SIG_DFL;
+ sigaction(sig, &action, NULL);
}
#elif HAVE_SIGNAL_H
- void (*ohandler) (int);
+ void (*ohandler) (int) = signal(sig, SIG_DFL);
+ if (ohandler != SDL_HandleSIG) {
+ signal(sig, ohandler);
+ }
+#endif /* HAVE_SIGNAL_H */
+}
+/* Public functions */
+static int
+SDL_QuitInit_Internal(void)
+{
/* Both SIGINT and SIGTERM are translated into quit interrupts */
- ohandler = signal(SIGINT, SDL_HandleSIG);
- if (ohandler != SIG_DFL)
- signal(SIGINT, ohandler);
- ohandler = signal(SIGTERM, SDL_HandleSIG);
- if (ohandler != SIG_DFL)
- signal(SIGTERM, ohandler);
-#endif /* HAVE_SIGNAL_H */
+ /* and SDL can be built to simulate iOS/Android semantics with arbitrary signals. */
+ SDL_EventSignal_Init(SIGINT);
+ SDL_EventSignal_Init(SIGTERM);
+
+ #ifdef SDL_BACKGROUNDING_SIGNAL
+ SDL_EventSignal_Init(SDL_BACKGROUNDING_SIGNAL);
+ #endif
+
+ #ifdef SDL_FOREGROUNDING_SIGNAL
+ SDL_EventSignal_Init(SDL_FOREGROUNDING_SIGNAL);
+ #endif
/* That's it! */
return 0;
@@ -100,28 +143,16 @@ SDL_QuitInit(void)
static void
SDL_QuitQuit_Internal(void)
{
-#ifdef HAVE_SIGACTION
- struct sigaction action;
- sigaction(SIGINT, NULL, &action);
- if ( action.sa_handler == SDL_HandleSIG ) {
- action.sa_handler = SIG_DFL;
- sigaction(SIGINT, &action, NULL);
- }
- sigaction(SIGTERM, NULL, &action);
- if ( action.sa_handler == SDL_HandleSIG ) {
- action.sa_handler = SIG_DFL;
- sigaction(SIGTERM, &action, NULL);
- }
-#elif HAVE_SIGNAL_H
- void (*ohandler) (int);
-
- ohandler = signal(SIGINT, SIG_DFL);
- if (ohandler != SDL_HandleSIG)
- signal(SIGINT, ohandler);
- ohandler = signal(SIGTERM, SIG_DFL);
- if (ohandler != SDL_HandleSIG)
- signal(SIGTERM, ohandler);
-#endif /* HAVE_SIGNAL_H */
+ SDL_EventSignal_Quit(SIGINT);
+ SDL_EventSignal_Quit(SIGTERM);
+
+ #ifdef SDL_BACKGROUNDING_SIGNAL
+ SDL_EventSignal_Quit(SDL_BACKGROUNDING_SIGNAL);
+ #endif
+
+ #ifdef SDL_FOREGROUNDING_SIGNAL
+ SDL_EventSignal_Quit(SDL_FOREGROUNDING_SIGNAL);
+ #endif
}
void
@@ -141,12 +172,26 @@ SDL_SendQuit(void)
}
void
-SDL_SendPendingQuit(void)
+SDL_SendPendingSignalEvents(void)
{
if (send_quit_pending) {
SDL_SendQuit();
SDL_assert(!send_quit_pending);
}
+
+ #ifdef SDL_BACKGROUNDING_SIGNAL
+ if (send_backgrounding_pending) {
+ send_backgrounding_pending = SDL_FALSE;
+ SDL_OnApplicationWillResignActive();
+ }
+ #endif
+
+ #ifdef SDL_FOREGROUNDING_SIGNAL
+ if (send_foregrounding_pending) {
+ send_foregrounding_pending = SDL_FALSE;
+ SDL_OnApplicationDidBecomeActive();
+ }
+ #endif
}
/* vi: set ts=4 sw=4 expandtab: */