src/events/SDL_events.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1666 6e7ec5cb83c3
child 1722 5daa04d862f1
     1.1 --- a/src/events/SDL_events.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/events/SDL_events.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -62,21 +62,21 @@
     1.4  static Uint32 event_thread;     /* The event thread id */
     1.5  
     1.6  void
     1.7 -SDL_Lock_EventThread (void)
     1.8 +SDL_Lock_EventThread(void)
     1.9  {
    1.10 -    if (SDL_EventThread && (SDL_ThreadID () != event_thread)) {
    1.11 +    if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
    1.12          /* Grab lock and spin until we're sure event thread stopped */
    1.13 -        SDL_mutexP (SDL_EventLock.lock);
    1.14 +        SDL_mutexP(SDL_EventLock.lock);
    1.15          while (!SDL_EventLock.safe) {
    1.16 -            SDL_Delay (1);
    1.17 +            SDL_Delay(1);
    1.18          }
    1.19      }
    1.20  }
    1.21  void
    1.22 -SDL_Unlock_EventThread (void)
    1.23 +SDL_Unlock_EventThread(void)
    1.24  {
    1.25 -    if (SDL_EventThread && (SDL_ThreadID () != event_thread)) {
    1.26 -        SDL_mutexV (SDL_EventLock.lock);
    1.27 +    if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
    1.28 +        SDL_mutexV(SDL_EventLock.lock);
    1.29      }
    1.30  }
    1.31  
    1.32 @@ -92,41 +92,41 @@
    1.33  #endif
    1.34  
    1.35  static int SDLCALL
    1.36 -SDL_GobbleEvents (void *unused)
    1.37 +SDL_GobbleEvents(void *unused)
    1.38  {
    1.39 -    event_thread = SDL_ThreadID ();
    1.40 +    event_thread = SDL_ThreadID();
    1.41  
    1.42  #ifdef __OS2__
    1.43  #ifdef USE_DOSSETPRIORITY
    1.44      /* Increase thread priority, so it will process events in time for sure! */
    1.45 -    DosSetPriority (PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
    1.46 +    DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
    1.47  #endif
    1.48  #endif
    1.49  
    1.50      while (SDL_EventQ.active) {
    1.51 -        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
    1.52 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.53  
    1.54          /* Get events from the video subsystem */
    1.55          if (_this) {
    1.56 -            _this->PumpEvents (_this);
    1.57 +            _this->PumpEvents(_this);
    1.58          }
    1.59  
    1.60          /* Queue pending key-repeat events */
    1.61 -        SDL_CheckKeyRepeat ();
    1.62 +        SDL_CheckKeyRepeat();
    1.63  
    1.64  #if !SDL_JOYSTICK_DISABLED
    1.65          /* Check for joystick state change */
    1.66          if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
    1.67 -            SDL_JoystickUpdate ();
    1.68 +            SDL_JoystickUpdate();
    1.69          }
    1.70  #endif
    1.71  
    1.72          /* Give up the CPU for the rest of our timeslice */
    1.73          SDL_EventLock.safe = 1;
    1.74          if (SDL_timer_running) {
    1.75 -            SDL_ThreadedTimerCheck ();
    1.76 +            SDL_ThreadedTimerCheck();
    1.77          }
    1.78 -        SDL_Delay (1);
    1.79 +        SDL_Delay(1);
    1.80  
    1.81          /* Check for event locking.
    1.82             On the P of the lock mutex, if the lock is held, this thread
    1.83 @@ -136,25 +136,25 @@
    1.84             so as soon as the mutex is free, other threads can see that
    1.85             it's not safe to interfere with the event thread.
    1.86           */
    1.87 -        SDL_mutexP (SDL_EventLock.lock);
    1.88 +        SDL_mutexP(SDL_EventLock.lock);
    1.89          SDL_EventLock.safe = 0;
    1.90 -        SDL_mutexV (SDL_EventLock.lock);
    1.91 +        SDL_mutexV(SDL_EventLock.lock);
    1.92      }
    1.93 -    SDL_SetTimerThreaded (0);
    1.94 +    SDL_SetTimerThreaded(0);
    1.95      event_thread = 0;
    1.96      return (0);
    1.97  }
    1.98  
    1.99  static int
   1.100 -SDL_StartEventThread (Uint32 flags)
   1.101 +SDL_StartEventThread(Uint32 flags)
   1.102  {
   1.103      /* Reset everything to zero */
   1.104      SDL_EventThread = NULL;
   1.105 -    SDL_memset (&SDL_EventLock, 0, sizeof (SDL_EventLock));
   1.106 +    SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
   1.107  
   1.108      /* Create the lock and set ourselves active */
   1.109  #if !SDL_THREADS_DISABLED
   1.110 -    SDL_EventQ.lock = SDL_CreateMutex ();
   1.111 +    SDL_EventQ.lock = SDL_CreateMutex();
   1.112      if (SDL_EventQ.lock == NULL) {
   1.113  #ifdef __MACOS__                /* MacOS classic you can't multithread, so no lock needed */
   1.114          ;
   1.115 @@ -166,20 +166,20 @@
   1.116      SDL_EventQ.active = 1;
   1.117  
   1.118      if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
   1.119 -        SDL_EventLock.lock = SDL_CreateMutex ();
   1.120 +        SDL_EventLock.lock = SDL_CreateMutex();
   1.121          if (SDL_EventLock.lock == NULL) {
   1.122              return (-1);
   1.123          }
   1.124          SDL_EventLock.safe = 0;
   1.125  
   1.126          /* The event thread will handle timers too */
   1.127 -        SDL_SetTimerThreaded (2);
   1.128 +        SDL_SetTimerThreaded(2);
   1.129  #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
   1.130  #undef SDL_CreateThread
   1.131          SDL_EventThread =
   1.132 -            SDL_CreateThread (SDL_GobbleEvents, NULL, NULL, NULL);
   1.133 +            SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
   1.134  #else
   1.135 -        SDL_EventThread = SDL_CreateThread (SDL_GobbleEvents, NULL);
   1.136 +        SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
   1.137  #endif
   1.138          if (SDL_EventThread == NULL) {
   1.139              return (-1);
   1.140 @@ -191,21 +191,21 @@
   1.141  }
   1.142  
   1.143  static void
   1.144 -SDL_StopEventThread (void)
   1.145 +SDL_StopEventThread(void)
   1.146  {
   1.147      SDL_EventQ.active = 0;
   1.148      if (SDL_EventThread) {
   1.149 -        SDL_WaitThread (SDL_EventThread, NULL);
   1.150 +        SDL_WaitThread(SDL_EventThread, NULL);
   1.151          SDL_EventThread = NULL;
   1.152 -        SDL_DestroyMutex (SDL_EventLock.lock);
   1.153 +        SDL_DestroyMutex(SDL_EventLock.lock);
   1.154      }
   1.155  #ifndef IPOD
   1.156 -    SDL_DestroyMutex (SDL_EventQ.lock);
   1.157 +    SDL_DestroyMutex(SDL_EventQ.lock);
   1.158  #endif
   1.159  }
   1.160  
   1.161  Uint32
   1.162 -SDL_EventThreadID (void)
   1.163 +SDL_EventThreadID(void)
   1.164  {
   1.165      return (event_thread);
   1.166  }
   1.167 @@ -213,15 +213,15 @@
   1.168  /* Public functions */
   1.169  
   1.170  void
   1.171 -SDL_StopEventLoop (void)
   1.172 +SDL_StopEventLoop(void)
   1.173  {
   1.174      /* Halt the event thread, if running */
   1.175 -    SDL_StopEventThread ();
   1.176 +    SDL_StopEventThread();
   1.177  
   1.178      /* Shutdown event handlers */
   1.179 -    SDL_KeyboardQuit ();
   1.180 -    SDL_MouseQuit ();
   1.181 -    SDL_QuitQuit ();
   1.182 +    SDL_KeyboardQuit();
   1.183 +    SDL_MouseQuit();
   1.184 +    SDL_QuitQuit();
   1.185  
   1.186      /* Clean out EventQ */
   1.187      SDL_EventQ.head = 0;
   1.188 @@ -231,18 +231,18 @@
   1.189  
   1.190  /* This function (and associated calls) may be called more than once */
   1.191  int
   1.192 -SDL_StartEventLoop (Uint32 flags)
   1.193 +SDL_StartEventLoop(Uint32 flags)
   1.194  {
   1.195      int retcode;
   1.196  
   1.197      /* Clean out the event queue */
   1.198      SDL_EventThread = NULL;
   1.199      SDL_EventQ.lock = NULL;
   1.200 -    SDL_StopEventLoop ();
   1.201 +    SDL_StopEventLoop();
   1.202  
   1.203      /* No filter to start with, process most event types */
   1.204      SDL_EventOK = NULL;
   1.205 -    SDL_memset (SDL_ProcessEvents, SDL_ENABLE, sizeof (SDL_ProcessEvents));
   1.206 +    SDL_memset(SDL_ProcessEvents, SDL_ENABLE, sizeof(SDL_ProcessEvents));
   1.207      SDL_eventstate = ~0;
   1.208      /* It's not save to call SDL_EventState() yet */
   1.209      SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT);
   1.210 @@ -250,17 +250,17 @@
   1.211  
   1.212      /* Initialize event handlers */
   1.213      retcode = 0;
   1.214 -    retcode += SDL_KeyboardInit ();
   1.215 -    retcode += SDL_MouseInit ();
   1.216 -    retcode += SDL_QuitInit ();
   1.217 +    retcode += SDL_KeyboardInit();
   1.218 +    retcode += SDL_MouseInit();
   1.219 +    retcode += SDL_QuitInit();
   1.220      if (retcode < 0) {
   1.221          /* We don't expect them to fail, but... */
   1.222          return (-1);
   1.223      }
   1.224  
   1.225      /* Create the lock and event thread */
   1.226 -    if (SDL_StartEventThread (flags) < 0) {
   1.227 -        SDL_StopEventLoop ();
   1.228 +    if (SDL_StartEventThread(flags) < 0) {
   1.229 +        SDL_StopEventLoop();
   1.230          return (-1);
   1.231      }
   1.232      return (0);
   1.233 @@ -269,7 +269,7 @@
   1.234  
   1.235  /* Add an event to the event queue -- called with the queue locked */
   1.236  static int
   1.237 -SDL_AddEvent (SDL_Event * event)
   1.238 +SDL_AddEvent(SDL_Event * event)
   1.239  {
   1.240      int tail, added;
   1.241  
   1.242 @@ -296,7 +296,7 @@
   1.243  /* Cut an event, and return the next valid spot, or the tail */
   1.244  /*                           -- called with the queue locked */
   1.245  static int
   1.246 -SDL_CutEvent (int spot)
   1.247 +SDL_CutEvent(int spot)
   1.248  {
   1.249      if (spot == SDL_EventQ.head) {
   1.250          SDL_EventQ.head = (SDL_EventQ.head + 1) % MAXEVENTS;
   1.251 @@ -324,8 +324,8 @@
   1.252  
   1.253  /* Lock the event queue, take a peep at it, and unlock it */
   1.254  int
   1.255 -SDL_PeepEvents (SDL_Event * events, int numevents, SDL_eventaction action,
   1.256 -                Uint32 mask)
   1.257 +SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
   1.258 +               Uint32 mask)
   1.259  {
   1.260      int i, used;
   1.261  
   1.262 @@ -335,10 +335,10 @@
   1.263      }
   1.264      /* Lock the event queue */
   1.265      used = 0;
   1.266 -    if (SDL_mutexP (SDL_EventQ.lock) == 0) {
   1.267 +    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
   1.268          if (action == SDL_ADDEVENT) {
   1.269              for (i = 0; i < numevents; ++i) {
   1.270 -                used += SDL_AddEvent (&events[i]);
   1.271 +                used += SDL_AddEvent(&events[i]);
   1.272              }
   1.273          } else {
   1.274              SDL_Event tmpevent;
   1.275 @@ -352,10 +352,10 @@
   1.276              }
   1.277              spot = SDL_EventQ.head;
   1.278              while ((used < numevents) && (spot != SDL_EventQ.tail)) {
   1.279 -                if (mask & SDL_EVENTMASK (SDL_EventQ.event[spot].type)) {
   1.280 +                if (mask & SDL_EVENTMASK(SDL_EventQ.event[spot].type)) {
   1.281                      events[used++] = SDL_EventQ.event[spot];
   1.282                      if (action == SDL_GETEVENT) {
   1.283 -                        spot = SDL_CutEvent (spot);
   1.284 +                        spot = SDL_CutEvent(spot);
   1.285                      } else {
   1.286                          spot = (spot + 1) % MAXEVENTS;
   1.287                      }
   1.288 @@ -364,9 +364,9 @@
   1.289                  }
   1.290              }
   1.291          }
   1.292 -        SDL_mutexV (SDL_EventQ.lock);
   1.293 +        SDL_mutexV(SDL_EventQ.lock);
   1.294      } else {
   1.295 -        SDL_SetError ("Couldn't lock event queue");
   1.296 +        SDL_SetError("Couldn't lock event queue");
   1.297          used = -1;
   1.298      }
   1.299      return (used);
   1.300 @@ -374,23 +374,23 @@
   1.301  
   1.302  /* Run the system dependent event loops */
   1.303  void
   1.304 -SDL_PumpEvents (void)
   1.305 +SDL_PumpEvents(void)
   1.306  {
   1.307      if (!SDL_EventThread) {
   1.308 -        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
   1.309 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.310  
   1.311          /* Get events from the video subsystem */
   1.312          if (_this) {
   1.313 -            _this->PumpEvents (_this);
   1.314 +            _this->PumpEvents(_this);
   1.315          }
   1.316  
   1.317          /* Queue pending key-repeat events */
   1.318 -        SDL_CheckKeyRepeat ();
   1.319 +        SDL_CheckKeyRepeat();
   1.320  
   1.321  #if !SDL_JOYSTICK_DISABLED
   1.322          /* Check for joystick state change */
   1.323          if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
   1.324 -            SDL_JoystickUpdate ();
   1.325 +            SDL_JoystickUpdate();
   1.326          }
   1.327  #endif
   1.328      }
   1.329 @@ -399,58 +399,58 @@
   1.330  /* Public functions */
   1.331  
   1.332  int
   1.333 -SDL_PollEvent (SDL_Event * event)
   1.334 +SDL_PollEvent(SDL_Event * event)
   1.335  {
   1.336 -    SDL_PumpEvents ();
   1.337 +    SDL_PumpEvents();
   1.338  
   1.339      /* We can't return -1, just return 0 (no event) on error */
   1.340 -    if (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0)
   1.341 +    if (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0)
   1.342          return 0;
   1.343      return 1;
   1.344  }
   1.345  
   1.346  int
   1.347 -SDL_WaitEvent (SDL_Event * event)
   1.348 +SDL_WaitEvent(SDL_Event * event)
   1.349  {
   1.350      while (1) {
   1.351 -        SDL_PumpEvents ();
   1.352 -        switch (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
   1.353 +        SDL_PumpEvents();
   1.354 +        switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
   1.355          case -1:
   1.356              return 0;
   1.357          case 1:
   1.358              return 1;
   1.359          case 0:
   1.360 -            SDL_Delay (10);
   1.361 +            SDL_Delay(10);
   1.362          }
   1.363      }
   1.364  }
   1.365  
   1.366  int
   1.367 -SDL_PushEvent (SDL_Event * event)
   1.368 +SDL_PushEvent(SDL_Event * event)
   1.369  {
   1.370 -    if (SDL_PeepEvents (event, 1, SDL_ADDEVENT, 0) <= 0)
   1.371 +    if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0) <= 0)
   1.372          return -1;
   1.373      return 0;
   1.374  }
   1.375  
   1.376  void
   1.377 -SDL_SetEventFilter (SDL_EventFilter filter)
   1.378 +SDL_SetEventFilter(SDL_EventFilter filter)
   1.379  {
   1.380      SDL_Event bitbucket;
   1.381  
   1.382      /* Set filter and discard pending events */
   1.383      SDL_EventOK = filter;
   1.384 -    while (SDL_PollEvent (&bitbucket) > 0);
   1.385 +    while (SDL_PollEvent(&bitbucket) > 0);
   1.386  }
   1.387  
   1.388  SDL_EventFilter
   1.389 -SDL_GetEventFilter (void)
   1.390 +SDL_GetEventFilter(void)
   1.391  {
   1.392      return (SDL_EventOK);
   1.393  }
   1.394  
   1.395  Uint8
   1.396 -SDL_EventState (Uint8 type, int state)
   1.397 +SDL_EventState(Uint8 type, int state)
   1.398  {
   1.399      SDL_Event bitbucket;
   1.400      Uint8 current_state;
   1.401 @@ -469,7 +469,7 @@
   1.402                  SDL_eventstate &= ~(0x00000001 << (type));
   1.403              }
   1.404          }
   1.405 -        while (SDL_PollEvent (&bitbucket) > 0);
   1.406 +        while (SDL_PollEvent(&bitbucket) > 0);
   1.407          return (current_state);
   1.408      }
   1.409  
   1.410 @@ -485,7 +485,7 @@
   1.411          } else {
   1.412              SDL_eventstate &= ~(0x00000001 << (type));
   1.413          }
   1.414 -        while (SDL_PollEvent (&bitbucket) > 0);
   1.415 +        while (SDL_PollEvent(&bitbucket) > 0);
   1.416          break;
   1.417      default:
   1.418          /* Querying state? */
   1.419 @@ -497,19 +497,19 @@
   1.420  /* This is a generic event handler.
   1.421   */
   1.422  int
   1.423 -SDL_PrivateSysWMEvent (SDL_SysWMmsg * message)
   1.424 +SDL_PrivateSysWMEvent(SDL_SysWMmsg * message)
   1.425  {
   1.426      int posted;
   1.427  
   1.428      posted = 0;
   1.429      if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
   1.430          SDL_Event event;
   1.431 -        SDL_memset (&event, 0, sizeof (event));
   1.432 +        SDL_memset(&event, 0, sizeof(event));
   1.433          event.type = SDL_SYSWMEVENT;
   1.434          event.syswm.msg = message;
   1.435          if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   1.436              posted = 1;
   1.437 -            SDL_PushEvent (&event);
   1.438 +            SDL_PushEvent(&event);
   1.439          }
   1.440      }
   1.441      /* Update internal event state */