Make it possible to use SDL events separately from the video subsystem.
authorSam Lantinga <slouken@libsdl.org>
Sat, 06 Jul 2013 12:28:57 -0700
changeset 7360b86947ea2749
parent 7359 96ac247b672e
child 7361 9b4430c49235
Make it possible to use SDL events separately from the video subsystem.
include/SDL.h
src/SDL.c
src/joystick/SDL_joystick.c
src/video/SDL_video.c
     1.1 --- a/include/SDL.h	Sat Jul 06 11:56:04 2013 -0700
     1.2 +++ b/include/SDL.h	Sat Jul 06 12:28:57 2013 -0700
     1.3 @@ -106,13 +106,14 @@
     1.4  /*@{*/
     1.5  #define SDL_INIT_TIMER          0x00000001
     1.6  #define SDL_INIT_AUDIO          0x00000010
     1.7 -#define SDL_INIT_VIDEO          0x00000020
     1.8 -#define SDL_INIT_JOYSTICK       0x00000200
     1.9 +#define SDL_INIT_VIDEO          0x00000020  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    1.10 +#define SDL_INIT_JOYSTICK       0x00000200  /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
    1.11  #define SDL_INIT_HAPTIC         0x00001000
    1.12 -#define SDL_INIT_GAMECONTROLLER 0x00002000      /**< turn on game controller also implicitly does JOYSTICK */
    1.13 -#define SDL_INIT_NOPARACHUTE    0x00100000      /**< Don't catch fatal signals */
    1.14 +#define SDL_INIT_GAMECONTROLLER 0x00002000  /**< SDL_INIT_GAMECONTROLLE implies SDL_INIT_JOYSTICK */
    1.15 +#define SDL_INIT_EVENTS         0x00004000
    1.16 +#define SDL_INIT_NOPARACHUTE    0x00100000  /**< Don't catch fatal signals */
    1.17  #define SDL_INIT_EVERYTHING ( \
    1.18 -                SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | \
    1.19 +                SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
    1.20                  SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
    1.21              )
    1.22  /*@}*/
     2.1 --- a/src/SDL.c	Sat Jul 06 11:56:04 2013 -0700
     2.2 +++ b/src/SDL.c	Sat Jul 06 12:28:57 2013 -0700
     2.3 @@ -27,6 +27,7 @@
     2.4  #include "SDL_revision.h"
     2.5  #include "SDL_fatal.h"
     2.6  #include "SDL_assert_c.h"
     2.7 +#include "events/SDL_events_c.h"
     2.8  #include "haptic/SDL_haptic_c.h"
     2.9  #include "joystick/SDL_joystick_c.h"
    2.10  
    2.11 @@ -111,8 +112,33 @@
    2.12      SDL_InitTicks();
    2.13  #endif
    2.14  
    2.15 +    if ((flags & SDL_INIT_GAMECONTROLLER)) {
    2.16 +        /* game controller implies joystick */
    2.17 +        flags |= SDL_INIT_JOYSTICK;
    2.18 +    }
    2.19 +
    2.20 +    if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
    2.21 +        /* video or joystick implies events */
    2.22 +        flags |= SDL_INIT_EVENTS;
    2.23 +    }
    2.24 +
    2.25 +    /* Initialize the event subsystem */
    2.26 +    if ((flags & SDL_INIT_EVENTS)) {
    2.27 +#if !SDL_EVENTS_DISABLED
    2.28 +        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
    2.29 +            if (SDL_StartEventLoop() < 0) {
    2.30 +                return (-1);
    2.31 +            }
    2.32 +            SDL_QuitInit();
    2.33 +        }
    2.34 +        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
    2.35 +#else
    2.36 +        return SDL_SetError("SDL not built with events support");
    2.37 +#endif
    2.38 +    }
    2.39 +
    2.40      /* Initialize the timer subsystem */
    2.41 -    if ((flags & SDL_INIT_TIMER) ){
    2.42 +    if ((flags & SDL_INIT_TIMER)){
    2.43  #if !SDL_TIMERS_DISABLED
    2.44          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
    2.45              if (SDL_TimerInit() < 0) {
    2.46 @@ -125,8 +151,8 @@
    2.47  #endif
    2.48      }
    2.49  
    2.50 -    /* Initialize the video/event subsystem */
    2.51 -    if ((flags & SDL_INIT_VIDEO) ){
    2.52 +    /* Initialize the video subsystem */
    2.53 +    if ((flags & SDL_INIT_VIDEO)){
    2.54  #if !SDL_VIDEO_DISABLED
    2.55          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
    2.56              if (SDL_VideoInit(NULL) < 0) {
    2.57 @@ -140,7 +166,7 @@
    2.58      }
    2.59  
    2.60      /* Initialize the audio subsystem */
    2.61 -    if ((flags & SDL_INIT_AUDIO) ){
    2.62 +    if ((flags & SDL_INIT_AUDIO)){
    2.63  #if !SDL_AUDIO_DISABLED
    2.64          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
    2.65              if (SDL_AudioInit(NULL) < 0) {
    2.66 @@ -153,13 +179,8 @@
    2.67  #endif
    2.68      }
    2.69  
    2.70 -    if ((flags & SDL_INIT_GAMECONTROLLER)) {
    2.71 -        /* Game controller implies Joystick. */
    2.72 -        flags |= SDL_INIT_JOYSTICK;
    2.73 -    }
    2.74 -
    2.75      /* Initialize the joystick subsystem */
    2.76 -    if ((flags & SDL_INIT_JOYSTICK) ){
    2.77 +    if ((flags & SDL_INIT_JOYSTICK)){
    2.78  #if !SDL_JOYSTICK_DISABLED
    2.79          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
    2.80             if (SDL_JoystickInit() < 0) {
    2.81 @@ -172,7 +193,7 @@
    2.82  #endif
    2.83      }
    2.84  
    2.85 -    if ((flags & SDL_INIT_GAMECONTROLLER) ){
    2.86 +    if ((flags & SDL_INIT_GAMECONTROLLER)){
    2.87  #if !SDL_JOYSTICK_DISABLED
    2.88          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
    2.89              if (SDL_GameControllerInit() < 0) {
    2.90 @@ -186,7 +207,7 @@
    2.91      }
    2.92  
    2.93      /* Initialize the haptic subsystem */
    2.94 -    if ((flags & SDL_INIT_HAPTIC) ){
    2.95 +    if ((flags & SDL_INIT_HAPTIC)){
    2.96  #if !SDL_HAPTIC_DISABLED
    2.97          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
    2.98              if (SDL_HapticInit() < 0) {
    2.99 @@ -237,7 +258,7 @@
   2.100      /* Shut down requested initialized subsystems */
   2.101  #if !SDL_JOYSTICK_DISABLED
   2.102      if ((flags & SDL_INIT_GAMECONTROLLER)) {
   2.103 -        /* Game controller implies Joystick. */
   2.104 +        /* game controller implies joystick */
   2.105          flags |= SDL_INIT_JOYSTICK;
   2.106  
   2.107          if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
   2.108 @@ -247,6 +268,9 @@
   2.109      }
   2.110  
   2.111      if ((flags & SDL_INIT_JOYSTICK)) {
   2.112 +        /* joystick implies events */
   2.113 +        flags |= SDL_INIT_EVENTS;
   2.114 +
   2.115          if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
   2.116              SDL_JoystickQuit();
   2.117          }
   2.118 @@ -274,6 +298,9 @@
   2.119  
   2.120  #if !SDL_VIDEO_DISABLED
   2.121      if ((flags & SDL_INIT_VIDEO)) {
   2.122 +        /* video implies events */
   2.123 +        flags |= SDL_INIT_EVENTS;
   2.124 +
   2.125          if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
   2.126              SDL_VideoQuit();
   2.127          }
   2.128 @@ -289,6 +316,16 @@
   2.129          SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
   2.130      }
   2.131  #endif
   2.132 +
   2.133 +#if !SDL_EVENTS_DISABLED
   2.134 +    if ((flags & SDL_INIT_EVENTS)) {
   2.135 +        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
   2.136 +            SDL_QuitQuit();
   2.137 +            SDL_StopEventLoop();
   2.138 +        }
   2.139 +        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
   2.140 +    }
   2.141 +#endif
   2.142  }
   2.143  
   2.144  Uint32
     3.1 --- a/src/joystick/SDL_joystick.c	Sat Jul 06 11:56:04 2013 -0700
     3.2 +++ b/src/joystick/SDL_joystick.c	Sat Jul 06 12:28:57 2013 -0700
     3.3 @@ -48,6 +48,12 @@
     3.4          SDL_joystick_allows_background_events = SDL_TRUE;
     3.5      }
     3.6  
     3.7 +#if !SDL_EVENTS_DISABLED
     3.8 +    if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
     3.9 +        return -1;
    3.10 +    }
    3.11 +#endif /* !SDL_EVENTS_DISABLED */
    3.12 +
    3.13      status = SDL_SYS_JoystickInit();
    3.14      if (status >= 0) {
    3.15          status = 0;
    3.16 @@ -458,6 +464,10 @@
    3.17  
    3.18      /* Quit the joystick setup */
    3.19      SDL_SYS_JoystickQuit();
    3.20 +
    3.21 +#if !SDL_EVENTS_DISABLED
    3.22 +    SDL_QuitSubSystem(SDL_INIT_EVENTS);
    3.23 +#endif
    3.24  }
    3.25  
    3.26  
     4.1 --- a/src/video/SDL_video.c	Sat Jul 06 11:56:04 2013 -0700
     4.2 +++ b/src/video/SDL_video.c	Sat Jul 06 12:28:57 2013 -0700
     4.3 @@ -422,11 +422,10 @@
     4.4  #endif
     4.5  
     4.6      /* Start the event loop */
     4.7 -    if (SDL_StartEventLoop() < 0 ||
     4.8 +    if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
     4.9          SDL_KeyboardInit() < 0 ||
    4.10          SDL_MouseInit() < 0 ||
    4.11 -        SDL_TouchInit() < 0 ||
    4.12 -        SDL_QuitInit() < 0) {
    4.13 +        SDL_TouchInit() < 0) {
    4.14          return -1;
    4.15      }
    4.16  
    4.17 @@ -2233,10 +2232,10 @@
    4.18      }
    4.19  
    4.20      /* Halt event processing before doing anything else */
    4.21 -    SDL_QuitQuit();
    4.22 +    SDL_TouchQuit();
    4.23      SDL_MouseQuit();
    4.24      SDL_KeyboardQuit();
    4.25 -    SDL_StopEventLoop();
    4.26 +    SDL_QuitSubSystem(SDL_INIT_EVENTS);
    4.27  
    4.28      SDL_EnableScreenSaver();
    4.29