src/events/SDL_events.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1666 6e7ec5cb83c3
     1.1 --- a/src/events/SDL_events.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/events/SDL_events.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -39,41 +39,45 @@
     1.4  
     1.5  /* Private data -- event queue */
     1.6  #define MAXEVENTS	128
     1.7 -static struct {
     1.8 -	SDL_mutex *lock;
     1.9 -	int active;
    1.10 -	int head;
    1.11 -	int tail;
    1.12 -	SDL_Event event[MAXEVENTS];
    1.13 -	int wmmsg_next;
    1.14 -	struct SDL_SysWMmsg wmmsg[MAXEVENTS];
    1.15 +static struct
    1.16 +{
    1.17 +    SDL_mutex *lock;
    1.18 +    int active;
    1.19 +    int head;
    1.20 +    int tail;
    1.21 +    SDL_Event event[MAXEVENTS];
    1.22 +    int wmmsg_next;
    1.23 +    struct SDL_SysWMmsg wmmsg[MAXEVENTS];
    1.24  } SDL_EventQ;
    1.25  
    1.26  /* Private data -- event locking structure */
    1.27 -static struct {
    1.28 -	SDL_mutex *lock;
    1.29 -	int safe;
    1.30 +static struct
    1.31 +{
    1.32 +    SDL_mutex *lock;
    1.33 +    int safe;
    1.34  } SDL_EventLock;
    1.35  
    1.36  /* Thread functions */
    1.37 -static SDL_Thread *SDL_EventThread = NULL;	/* Thread handle */
    1.38 -static Uint32 event_thread;			/* The event thread id */
    1.39 +static SDL_Thread *SDL_EventThread = NULL;      /* Thread handle */
    1.40 +static Uint32 event_thread;     /* The event thread id */
    1.41  
    1.42 -void SDL_Lock_EventThread(void)
    1.43 +void
    1.44 +SDL_Lock_EventThread (void)
    1.45  {
    1.46 -	if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) {
    1.47 -		/* Grab lock and spin until we're sure event thread stopped */
    1.48 -		SDL_mutexP(SDL_EventLock.lock);
    1.49 -		while ( ! SDL_EventLock.safe ) {
    1.50 -			SDL_Delay(1);
    1.51 -		}
    1.52 -	}
    1.53 +    if (SDL_EventThread && (SDL_ThreadID () != event_thread)) {
    1.54 +        /* Grab lock and spin until we're sure event thread stopped */
    1.55 +        SDL_mutexP (SDL_EventLock.lock);
    1.56 +        while (!SDL_EventLock.safe) {
    1.57 +            SDL_Delay (1);
    1.58 +        }
    1.59 +    }
    1.60  }
    1.61 -void SDL_Unlock_EventThread(void)
    1.62 +void
    1.63 +SDL_Unlock_EventThread (void)
    1.64  {
    1.65 -	if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) {
    1.66 -		SDL_mutexV(SDL_EventLock.lock);
    1.67 -	}
    1.68 +    if (SDL_EventThread && (SDL_ThreadID () != event_thread)) {
    1.69 +        SDL_mutexV (SDL_EventLock.lock);
    1.70 +    }
    1.71  }
    1.72  
    1.73  #ifdef __OS2__
    1.74 @@ -87,414 +91,431 @@
    1.75  #include <time.h>
    1.76  #endif
    1.77  
    1.78 -static int SDLCALL SDL_GobbleEvents(void *unused)
    1.79 +static int SDLCALL
    1.80 +SDL_GobbleEvents (void *unused)
    1.81  {
    1.82 -	event_thread = SDL_ThreadID();
    1.83 +    event_thread = SDL_ThreadID ();
    1.84  
    1.85  #ifdef __OS2__
    1.86  #ifdef USE_DOSSETPRIORITY
    1.87 -	/* Increase thread priority, so it will process events in time for sure! */
    1.88 -	DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
    1.89 +    /* Increase thread priority, so it will process events in time for sure! */
    1.90 +    DosSetPriority (PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
    1.91  #endif
    1.92  #endif
    1.93  
    1.94 -	while ( SDL_EventQ.active ) {
    1.95 -		SDL_VideoDevice *video = current_video;
    1.96 -		SDL_VideoDevice *this  = current_video;
    1.97 +    while (SDL_EventQ.active) {
    1.98 +        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
    1.99  
   1.100 -		/* Get events from the video subsystem */
   1.101 -		if ( video ) {
   1.102 -			video->PumpEvents(this);
   1.103 -		}
   1.104 +        /* Get events from the video subsystem */
   1.105 +        if (_this) {
   1.106 +            _this->PumpEvents (_this);
   1.107 +        }
   1.108  
   1.109 -		/* Queue pending key-repeat events */
   1.110 -		SDL_CheckKeyRepeat();
   1.111 +        /* Queue pending key-repeat events */
   1.112 +        SDL_CheckKeyRepeat ();
   1.113  
   1.114  #if !SDL_JOYSTICK_DISABLED
   1.115 -		/* Check for joystick state change */
   1.116 -		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
   1.117 -			SDL_JoystickUpdate();
   1.118 -		}
   1.119 +        /* Check for joystick state change */
   1.120 +        if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
   1.121 +            SDL_JoystickUpdate ();
   1.122 +        }
   1.123  #endif
   1.124  
   1.125 -		/* Give up the CPU for the rest of our timeslice */
   1.126 -		SDL_EventLock.safe = 1;
   1.127 -		if ( SDL_timer_running ) {
   1.128 -			SDL_ThreadedTimerCheck();
   1.129 -		}
   1.130 -		SDL_Delay(1);
   1.131 +        /* Give up the CPU for the rest of our timeslice */
   1.132 +        SDL_EventLock.safe = 1;
   1.133 +        if (SDL_timer_running) {
   1.134 +            SDL_ThreadedTimerCheck ();
   1.135 +        }
   1.136 +        SDL_Delay (1);
   1.137  
   1.138 -		/* Check for event locking.
   1.139 -		   On the P of the lock mutex, if the lock is held, this thread
   1.140 -		   will wait until the lock is released before continuing.  The
   1.141 -		   safe flag will be set, meaning that the other thread can go
   1.142 -		   about it's business.  The safe flag is reset before the V,
   1.143 -		   so as soon as the mutex is free, other threads can see that
   1.144 -		   it's not safe to interfere with the event thread.
   1.145 -		 */
   1.146 -		SDL_mutexP(SDL_EventLock.lock);
   1.147 -		SDL_EventLock.safe = 0;
   1.148 -		SDL_mutexV(SDL_EventLock.lock);
   1.149 -	}
   1.150 -	SDL_SetTimerThreaded(0);
   1.151 -	event_thread = 0;
   1.152 -	return(0);
   1.153 +        /* Check for event locking.
   1.154 +           On the P of the lock mutex, if the lock is held, this thread
   1.155 +           will wait until the lock is released before continuing.  The
   1.156 +           safe flag will be set, meaning that the other thread can go
   1.157 +           about it's business.  The safe flag is reset before the V,
   1.158 +           so as soon as the mutex is free, other threads can see that
   1.159 +           it's not safe to interfere with the event thread.
   1.160 +         */
   1.161 +        SDL_mutexP (SDL_EventLock.lock);
   1.162 +        SDL_EventLock.safe = 0;
   1.163 +        SDL_mutexV (SDL_EventLock.lock);
   1.164 +    }
   1.165 +    SDL_SetTimerThreaded (0);
   1.166 +    event_thread = 0;
   1.167 +    return (0);
   1.168  }
   1.169  
   1.170 -static int SDL_StartEventThread(Uint32 flags)
   1.171 +static int
   1.172 +SDL_StartEventThread (Uint32 flags)
   1.173  {
   1.174 -	/* Reset everything to zero */
   1.175 -	SDL_EventThread = NULL;
   1.176 -	SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
   1.177 +    /* Reset everything to zero */
   1.178 +    SDL_EventThread = NULL;
   1.179 +    SDL_memset (&SDL_EventLock, 0, sizeof (SDL_EventLock));
   1.180  
   1.181 -	/* Create the lock and set ourselves active */
   1.182 +    /* Create the lock and set ourselves active */
   1.183  #if !SDL_THREADS_DISABLED
   1.184 -	SDL_EventQ.lock = SDL_CreateMutex();
   1.185 -	if ( SDL_EventQ.lock == NULL ) {
   1.186 -#ifdef __MACOS__ /* MacOS classic you can't multithread, so no lock needed */
   1.187 -		;
   1.188 +    SDL_EventQ.lock = SDL_CreateMutex ();
   1.189 +    if (SDL_EventQ.lock == NULL) {
   1.190 +#ifdef __MACOS__                /* MacOS classic you can't multithread, so no lock needed */
   1.191 +        ;
   1.192  #else
   1.193 -		return(-1);
   1.194 +        return (-1);
   1.195  #endif
   1.196 -	}
   1.197 +    }
   1.198  #endif /* !SDL_THREADS_DISABLED */
   1.199 -	SDL_EventQ.active = 1;
   1.200 +    SDL_EventQ.active = 1;
   1.201  
   1.202 -	if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
   1.203 -		SDL_EventLock.lock = SDL_CreateMutex();
   1.204 -		if ( SDL_EventLock.lock == NULL ) {
   1.205 -			return(-1);
   1.206 -		}
   1.207 -		SDL_EventLock.safe = 0;
   1.208 +    if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) {
   1.209 +        SDL_EventLock.lock = SDL_CreateMutex ();
   1.210 +        if (SDL_EventLock.lock == NULL) {
   1.211 +            return (-1);
   1.212 +        }
   1.213 +        SDL_EventLock.safe = 0;
   1.214  
   1.215 -		/* The event thread will handle timers too */
   1.216 -		SDL_SetTimerThreaded(2);
   1.217 +        /* The event thread will handle timers too */
   1.218 +        SDL_SetTimerThreaded (2);
   1.219  #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
   1.220  #undef SDL_CreateThread
   1.221 -		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
   1.222 +        SDL_EventThread =
   1.223 +            SDL_CreateThread (SDL_GobbleEvents, NULL, NULL, NULL);
   1.224  #else
   1.225 -		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
   1.226 +        SDL_EventThread = SDL_CreateThread (SDL_GobbleEvents, NULL);
   1.227  #endif
   1.228 -		if ( SDL_EventThread == NULL ) {
   1.229 -			return(-1);
   1.230 -		}
   1.231 -	} else {
   1.232 -		event_thread = 0;
   1.233 -	}
   1.234 -	return(0);
   1.235 +        if (SDL_EventThread == NULL) {
   1.236 +            return (-1);
   1.237 +        }
   1.238 +    } else {
   1.239 +        event_thread = 0;
   1.240 +    }
   1.241 +    return (0);
   1.242  }
   1.243  
   1.244 -static void SDL_StopEventThread(void)
   1.245 +static void
   1.246 +SDL_StopEventThread (void)
   1.247  {
   1.248 -	SDL_EventQ.active = 0;
   1.249 -	if ( SDL_EventThread ) {
   1.250 -		SDL_WaitThread(SDL_EventThread, NULL);
   1.251 -		SDL_EventThread = NULL;
   1.252 -		SDL_DestroyMutex(SDL_EventLock.lock);
   1.253 -	}
   1.254 +    SDL_EventQ.active = 0;
   1.255 +    if (SDL_EventThread) {
   1.256 +        SDL_WaitThread (SDL_EventThread, NULL);
   1.257 +        SDL_EventThread = NULL;
   1.258 +        SDL_DestroyMutex (SDL_EventLock.lock);
   1.259 +    }
   1.260  #ifndef IPOD
   1.261 -	SDL_DestroyMutex(SDL_EventQ.lock);
   1.262 +    SDL_DestroyMutex (SDL_EventQ.lock);
   1.263  #endif
   1.264  }
   1.265  
   1.266 -Uint32 SDL_EventThreadID(void)
   1.267 +Uint32
   1.268 +SDL_EventThreadID (void)
   1.269  {
   1.270 -	return(event_thread);
   1.271 +    return (event_thread);
   1.272  }
   1.273  
   1.274  /* Public functions */
   1.275  
   1.276 -void SDL_StopEventLoop(void)
   1.277 +void
   1.278 +SDL_StopEventLoop (void)
   1.279  {
   1.280 -	/* Halt the event thread, if running */
   1.281 -	SDL_StopEventThread();
   1.282 +    /* Halt the event thread, if running */
   1.283 +    SDL_StopEventThread ();
   1.284  
   1.285 -	/* Shutdown event handlers */
   1.286 -	SDL_AppActiveQuit();
   1.287 -	SDL_KeyboardQuit();
   1.288 -	SDL_MouseQuit();
   1.289 -	SDL_QuitQuit();
   1.290 +    /* Shutdown event handlers */
   1.291 +    SDL_AppActiveQuit ();
   1.292 +    SDL_KeyboardQuit ();
   1.293 +    SDL_MouseQuit ();
   1.294 +    SDL_QuitQuit ();
   1.295  
   1.296 -	/* Clean out EventQ */
   1.297 -	SDL_EventQ.head = 0;
   1.298 -	SDL_EventQ.tail = 0;
   1.299 -	SDL_EventQ.wmmsg_next = 0;
   1.300 +    /* Clean out EventQ */
   1.301 +    SDL_EventQ.head = 0;
   1.302 +    SDL_EventQ.tail = 0;
   1.303 +    SDL_EventQ.wmmsg_next = 0;
   1.304  }
   1.305  
   1.306  /* This function (and associated calls) may be called more than once */
   1.307 -int SDL_StartEventLoop(Uint32 flags)
   1.308 +int
   1.309 +SDL_StartEventLoop (Uint32 flags)
   1.310  {
   1.311 -	int retcode;
   1.312 +    int retcode;
   1.313  
   1.314 -	/* Clean out the event queue */
   1.315 -	SDL_EventThread = NULL;
   1.316 -	SDL_EventQ.lock = NULL;
   1.317 -	SDL_StopEventLoop();
   1.318 +    /* Clean out the event queue */
   1.319 +    SDL_EventThread = NULL;
   1.320 +    SDL_EventQ.lock = NULL;
   1.321 +    SDL_StopEventLoop ();
   1.322  
   1.323 -	/* No filter to start with, process most event types */
   1.324 -	SDL_EventOK = NULL;
   1.325 -	SDL_memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents));
   1.326 -	SDL_eventstate = ~0;
   1.327 -	/* It's not save to call SDL_EventState() yet */
   1.328 -	SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT);
   1.329 -	SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE;
   1.330 +    /* No filter to start with, process most event types */
   1.331 +    SDL_EventOK = NULL;
   1.332 +    SDL_memset (SDL_ProcessEvents, SDL_ENABLE, sizeof (SDL_ProcessEvents));
   1.333 +    SDL_eventstate = ~0;
   1.334 +    /* It's not save to call SDL_EventState() yet */
   1.335 +    SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT);
   1.336 +    SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE;
   1.337  
   1.338 -	/* Initialize event handlers */
   1.339 -	retcode = 0;
   1.340 -	retcode += SDL_AppActiveInit();
   1.341 -	retcode += SDL_KeyboardInit();
   1.342 -	retcode += SDL_MouseInit();
   1.343 -	retcode += SDL_QuitInit();
   1.344 -	if ( retcode < 0 ) {
   1.345 -		/* We don't expect them to fail, but... */
   1.346 -		return(-1);
   1.347 -	}
   1.348 +    /* Initialize event handlers */
   1.349 +    retcode = 0;
   1.350 +    retcode += SDL_AppActiveInit ();
   1.351 +    retcode += SDL_KeyboardInit ();
   1.352 +    retcode += SDL_MouseInit ();
   1.353 +    retcode += SDL_QuitInit ();
   1.354 +    if (retcode < 0) {
   1.355 +        /* We don't expect them to fail, but... */
   1.356 +        return (-1);
   1.357 +    }
   1.358  
   1.359 -	/* Create the lock and event thread */
   1.360 -	if ( SDL_StartEventThread(flags) < 0 ) {
   1.361 -		SDL_StopEventLoop();
   1.362 -		return(-1);
   1.363 -	}
   1.364 -	return(0);
   1.365 +    /* Create the lock and event thread */
   1.366 +    if (SDL_StartEventThread (flags) < 0) {
   1.367 +        SDL_StopEventLoop ();
   1.368 +        return (-1);
   1.369 +    }
   1.370 +    return (0);
   1.371  }
   1.372  
   1.373  
   1.374  /* Add an event to the event queue -- called with the queue locked */
   1.375 -static int SDL_AddEvent(SDL_Event *event)
   1.376 +static int
   1.377 +SDL_AddEvent (SDL_Event * event)
   1.378  {
   1.379 -	int tail, added;
   1.380 +    int tail, added;
   1.381  
   1.382 -	tail = (SDL_EventQ.tail+1)%MAXEVENTS;
   1.383 -	if ( tail == SDL_EventQ.head ) {
   1.384 -		/* Overflow, drop event */
   1.385 -		added = 0;
   1.386 -	} else {
   1.387 -		SDL_EventQ.event[SDL_EventQ.tail] = *event;
   1.388 -		if (event->type == SDL_SYSWMEVENT) {
   1.389 -			/* Note that it's possible to lose an event */
   1.390 -			int next = SDL_EventQ.wmmsg_next;
   1.391 -			SDL_EventQ.wmmsg[next] = *event->syswm.msg;
   1.392 -		        SDL_EventQ.event[SDL_EventQ.tail].syswm.msg =
   1.393 -						&SDL_EventQ.wmmsg[next];
   1.394 -			SDL_EventQ.wmmsg_next = (next+1)%MAXEVENTS;
   1.395 -		}
   1.396 -		SDL_EventQ.tail = tail;
   1.397 -		added = 1;
   1.398 -	}
   1.399 -	return(added);
   1.400 +    tail = (SDL_EventQ.tail + 1) % MAXEVENTS;
   1.401 +    if (tail == SDL_EventQ.head) {
   1.402 +        /* Overflow, drop event */
   1.403 +        added = 0;
   1.404 +    } else {
   1.405 +        SDL_EventQ.event[SDL_EventQ.tail] = *event;
   1.406 +        if (event->type == SDL_SYSWMEVENT) {
   1.407 +            /* Note that it's possible to lose an event */
   1.408 +            int next = SDL_EventQ.wmmsg_next;
   1.409 +            SDL_EventQ.wmmsg[next] = *event->syswm.msg;
   1.410 +            SDL_EventQ.event[SDL_EventQ.tail].syswm.msg =
   1.411 +                &SDL_EventQ.wmmsg[next];
   1.412 +            SDL_EventQ.wmmsg_next = (next + 1) % MAXEVENTS;
   1.413 +        }
   1.414 +        SDL_EventQ.tail = tail;
   1.415 +        added = 1;
   1.416 +    }
   1.417 +    return (added);
   1.418  }
   1.419  
   1.420  /* Cut an event, and return the next valid spot, or the tail */
   1.421  /*                           -- called with the queue locked */
   1.422 -static int SDL_CutEvent(int spot)
   1.423 +static int
   1.424 +SDL_CutEvent (int spot)
   1.425  {
   1.426 -	if ( spot == SDL_EventQ.head ) {
   1.427 -		SDL_EventQ.head = (SDL_EventQ.head+1)%MAXEVENTS;
   1.428 -		return(SDL_EventQ.head);
   1.429 -	} else
   1.430 -	if ( (spot+1)%MAXEVENTS == SDL_EventQ.tail ) {
   1.431 -		SDL_EventQ.tail = spot;
   1.432 -		return(SDL_EventQ.tail);
   1.433 -	} else
   1.434 -	/* We cut the middle -- shift everything over */
   1.435 -	{
   1.436 -		int here, next;
   1.437 +    if (spot == SDL_EventQ.head) {
   1.438 +        SDL_EventQ.head = (SDL_EventQ.head + 1) % MAXEVENTS;
   1.439 +        return (SDL_EventQ.head);
   1.440 +    } else if ((spot + 1) % MAXEVENTS == SDL_EventQ.tail) {
   1.441 +        SDL_EventQ.tail = spot;
   1.442 +        return (SDL_EventQ.tail);
   1.443 +    } else
   1.444 +        /* We cut the middle -- shift everything over */
   1.445 +    {
   1.446 +        int here, next;
   1.447  
   1.448 -		/* This can probably be optimized with SDL_memcpy() -- careful! */
   1.449 -		if ( --SDL_EventQ.tail < 0 ) {
   1.450 -			SDL_EventQ.tail = MAXEVENTS-1;
   1.451 -		}
   1.452 -		for ( here=spot; here != SDL_EventQ.tail; here = next ) {
   1.453 -			next = (here+1)%MAXEVENTS;
   1.454 -			SDL_EventQ.event[here] = SDL_EventQ.event[next];
   1.455 -		}
   1.456 -		return(spot);
   1.457 -	}
   1.458 -	/* NOTREACHED */
   1.459 +        /* This can probably be optimized with SDL_memcpy() -- careful! */
   1.460 +        if (--SDL_EventQ.tail < 0) {
   1.461 +            SDL_EventQ.tail = MAXEVENTS - 1;
   1.462 +        }
   1.463 +        for (here = spot; here != SDL_EventQ.tail; here = next) {
   1.464 +            next = (here + 1) % MAXEVENTS;
   1.465 +            SDL_EventQ.event[here] = SDL_EventQ.event[next];
   1.466 +        }
   1.467 +        return (spot);
   1.468 +    }
   1.469 +    /* NOTREACHED */
   1.470  }
   1.471  
   1.472  /* Lock the event queue, take a peep at it, and unlock it */
   1.473 -int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action,
   1.474 -								Uint32 mask)
   1.475 +int
   1.476 +SDL_PeepEvents (SDL_Event * events, int numevents, SDL_eventaction action,
   1.477 +                Uint32 mask)
   1.478  {
   1.479 -	int i, used;
   1.480 +    int i, used;
   1.481  
   1.482 -	/* Don't look after we've quit */
   1.483 -	if ( ! SDL_EventQ.active ) {
   1.484 -		return(-1);
   1.485 -	}
   1.486 -	/* Lock the event queue */
   1.487 -	used = 0;
   1.488 -	if ( SDL_mutexP(SDL_EventQ.lock) == 0 ) {
   1.489 -		if ( action == SDL_ADDEVENT ) {
   1.490 -			for ( i=0; i<numevents; ++i ) {
   1.491 -				used += SDL_AddEvent(&events[i]);
   1.492 -			}
   1.493 -		} else {
   1.494 -			SDL_Event tmpevent;
   1.495 -			int spot;
   1.496 +    /* Don't look after we've quit */
   1.497 +    if (!SDL_EventQ.active) {
   1.498 +        return (-1);
   1.499 +    }
   1.500 +    /* Lock the event queue */
   1.501 +    used = 0;
   1.502 +    if (SDL_mutexP (SDL_EventQ.lock) == 0) {
   1.503 +        if (action == SDL_ADDEVENT) {
   1.504 +            for (i = 0; i < numevents; ++i) {
   1.505 +                used += SDL_AddEvent (&events[i]);
   1.506 +            }
   1.507 +        } else {
   1.508 +            SDL_Event tmpevent;
   1.509 +            int spot;
   1.510  
   1.511 -			/* If 'events' is NULL, just see if they exist */
   1.512 -			if ( events == NULL ) {
   1.513 -				action = SDL_PEEKEVENT;
   1.514 -				numevents = 1;
   1.515 -				events = &tmpevent;
   1.516 -			}
   1.517 -			spot = SDL_EventQ.head;
   1.518 -			while ((used < numevents)&&(spot != SDL_EventQ.tail)) {
   1.519 -				if ( mask & SDL_EVENTMASK(SDL_EventQ.event[spot].type) ) {
   1.520 -					events[used++] = SDL_EventQ.event[spot];
   1.521 -					if ( action == SDL_GETEVENT ) {
   1.522 -						spot = SDL_CutEvent(spot);
   1.523 -					} else {
   1.524 -						spot = (spot+1)%MAXEVENTS;
   1.525 -					}
   1.526 -				} else {
   1.527 -					spot = (spot+1)%MAXEVENTS;
   1.528 -				}
   1.529 -			}
   1.530 -		}
   1.531 -		SDL_mutexV(SDL_EventQ.lock);
   1.532 -	} else {
   1.533 -		SDL_SetError("Couldn't lock event queue");
   1.534 -		used = -1;
   1.535 -	}
   1.536 -	return(used);
   1.537 +            /* If 'events' is NULL, just see if they exist */
   1.538 +            if (events == NULL) {
   1.539 +                action = SDL_PEEKEVENT;
   1.540 +                numevents = 1;
   1.541 +                events = &tmpevent;
   1.542 +            }
   1.543 +            spot = SDL_EventQ.head;
   1.544 +            while ((used < numevents) && (spot != SDL_EventQ.tail)) {
   1.545 +                if (mask & SDL_EVENTMASK (SDL_EventQ.event[spot].type)) {
   1.546 +                    events[used++] = SDL_EventQ.event[spot];
   1.547 +                    if (action == SDL_GETEVENT) {
   1.548 +                        spot = SDL_CutEvent (spot);
   1.549 +                    } else {
   1.550 +                        spot = (spot + 1) % MAXEVENTS;
   1.551 +                    }
   1.552 +                } else {
   1.553 +                    spot = (spot + 1) % MAXEVENTS;
   1.554 +                }
   1.555 +            }
   1.556 +        }
   1.557 +        SDL_mutexV (SDL_EventQ.lock);
   1.558 +    } else {
   1.559 +        SDL_SetError ("Couldn't lock event queue");
   1.560 +        used = -1;
   1.561 +    }
   1.562 +    return (used);
   1.563  }
   1.564  
   1.565  /* Run the system dependent event loops */
   1.566 -void SDL_PumpEvents(void)
   1.567 +void
   1.568 +SDL_PumpEvents (void)
   1.569  {
   1.570 -	if ( !SDL_EventThread ) {
   1.571 -		SDL_VideoDevice *video = current_video;
   1.572 -		SDL_VideoDevice *this  = current_video;
   1.573 +    if (!SDL_EventThread) {
   1.574 +        SDL_VideoDevice *_this = SDL_GetVideoDevice ();
   1.575  
   1.576 -		/* Get events from the video subsystem */
   1.577 -		if ( video ) {
   1.578 -			video->PumpEvents(this);
   1.579 -		}
   1.580 +        /* Get events from the video subsystem */
   1.581 +        if (_this) {
   1.582 +            _this->PumpEvents (_this);
   1.583 +        }
   1.584  
   1.585 -		/* Queue pending key-repeat events */
   1.586 -		SDL_CheckKeyRepeat();
   1.587 +        /* Queue pending key-repeat events */
   1.588 +        SDL_CheckKeyRepeat ();
   1.589  
   1.590  #if !SDL_JOYSTICK_DISABLED
   1.591 -		/* Check for joystick state change */
   1.592 -		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
   1.593 -			SDL_JoystickUpdate();
   1.594 -		}
   1.595 +        /* Check for joystick state change */
   1.596 +        if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
   1.597 +            SDL_JoystickUpdate ();
   1.598 +        }
   1.599  #endif
   1.600 -	}
   1.601 +    }
   1.602  }
   1.603  
   1.604  /* Public functions */
   1.605  
   1.606 -int SDL_PollEvent (SDL_Event *event)
   1.607 +int
   1.608 +SDL_PollEvent (SDL_Event * event)
   1.609  {
   1.610 -	SDL_PumpEvents();
   1.611 +    SDL_PumpEvents ();
   1.612  
   1.613 -	/* We can't return -1, just return 0 (no event) on error */
   1.614 -	if ( SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0 )
   1.615 -		return 0;
   1.616 -	return 1;
   1.617 +    /* We can't return -1, just return 0 (no event) on error */
   1.618 +    if (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0)
   1.619 +        return 0;
   1.620 +    return 1;
   1.621  }
   1.622  
   1.623 -int SDL_WaitEvent (SDL_Event *event)
   1.624 +int
   1.625 +SDL_WaitEvent (SDL_Event * event)
   1.626  {
   1.627 -	while ( 1 ) {
   1.628 -		SDL_PumpEvents();
   1.629 -		switch(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
   1.630 -		    case -1: return 0;
   1.631 -		    case 1: return 1;
   1.632 -		    case 0: SDL_Delay(10);
   1.633 -		}
   1.634 -	}
   1.635 +    while (1) {
   1.636 +        SDL_PumpEvents ();
   1.637 +        switch (SDL_PeepEvents (event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
   1.638 +        case -1:
   1.639 +            return 0;
   1.640 +        case 1:
   1.641 +            return 1;
   1.642 +        case 0:
   1.643 +            SDL_Delay (10);
   1.644 +        }
   1.645 +    }
   1.646  }
   1.647  
   1.648 -int SDL_PushEvent(SDL_Event *event)
   1.649 +int
   1.650 +SDL_PushEvent (SDL_Event * event)
   1.651  {
   1.652 -	if ( SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0) <= 0 )
   1.653 -		return -1;
   1.654 -	return 0;
   1.655 +    if (SDL_PeepEvents (event, 1, SDL_ADDEVENT, 0) <= 0)
   1.656 +        return -1;
   1.657 +    return 0;
   1.658  }
   1.659  
   1.660 -void SDL_SetEventFilter (SDL_EventFilter filter)
   1.661 +void
   1.662 +SDL_SetEventFilter (SDL_EventFilter filter)
   1.663  {
   1.664 -	SDL_Event bitbucket;
   1.665 +    SDL_Event bitbucket;
   1.666  
   1.667 -	/* Set filter and discard pending events */
   1.668 -	SDL_EventOK = filter;
   1.669 -	while ( SDL_PollEvent(&bitbucket) > 0 )
   1.670 -		;
   1.671 -}
   1.672 -
   1.673 -SDL_EventFilter SDL_GetEventFilter(void)
   1.674 -{
   1.675 -	return(SDL_EventOK);
   1.676 +    /* Set filter and discard pending events */
   1.677 +    SDL_EventOK = filter;
   1.678 +    while (SDL_PollEvent (&bitbucket) > 0);
   1.679  }
   1.680  
   1.681 -Uint8 SDL_EventState (Uint8 type, int state)
   1.682 +SDL_EventFilter
   1.683 +SDL_GetEventFilter (void)
   1.684  {
   1.685 -	SDL_Event bitbucket;
   1.686 -	Uint8 current_state;
   1.687 +    return (SDL_EventOK);
   1.688 +}
   1.689 +
   1.690 +Uint8
   1.691 +SDL_EventState (Uint8 type, int state)
   1.692 +{
   1.693 +    SDL_Event bitbucket;
   1.694 +    Uint8 current_state;
   1.695  
   1.696 -	/* If SDL_ALLEVENTS was specified... */
   1.697 -	if ( type == 0xFF ) {
   1.698 -		current_state = SDL_IGNORE;
   1.699 -		for ( type=0; type<SDL_NUMEVENTS; ++type ) {
   1.700 -			if ( SDL_ProcessEvents[type] != SDL_IGNORE ) {
   1.701 -				current_state = SDL_ENABLE;
   1.702 -			}
   1.703 -			SDL_ProcessEvents[type] = state;
   1.704 -			if ( state == SDL_ENABLE ) {
   1.705 -				SDL_eventstate |= (0x00000001 << (type));
   1.706 -			} else {
   1.707 -				SDL_eventstate &= ~(0x00000001 << (type));
   1.708 -			}
   1.709 -		}
   1.710 -		while ( SDL_PollEvent(&bitbucket) > 0 )
   1.711 -			;
   1.712 -		return(current_state);
   1.713 -	}
   1.714 +    /* If SDL_ALLEVENTS was specified... */
   1.715 +    if (type == 0xFF) {
   1.716 +        current_state = SDL_IGNORE;
   1.717 +        for (type = 0; type < SDL_NUMEVENTS; ++type) {
   1.718 +            if (SDL_ProcessEvents[type] != SDL_IGNORE) {
   1.719 +                current_state = SDL_ENABLE;
   1.720 +            }
   1.721 +            SDL_ProcessEvents[type] = state;
   1.722 +            if (state == SDL_ENABLE) {
   1.723 +                SDL_eventstate |= (0x00000001 << (type));
   1.724 +            } else {
   1.725 +                SDL_eventstate &= ~(0x00000001 << (type));
   1.726 +            }
   1.727 +        }
   1.728 +        while (SDL_PollEvent (&bitbucket) > 0);
   1.729 +        return (current_state);
   1.730 +    }
   1.731  
   1.732 -	/* Just set the state for one event type */
   1.733 -	current_state = SDL_ProcessEvents[type];
   1.734 -	switch (state) {
   1.735 -		case SDL_IGNORE:
   1.736 -		case SDL_ENABLE:
   1.737 -			/* Set state and discard pending events */
   1.738 -			SDL_ProcessEvents[type] = state;
   1.739 -			if ( state == SDL_ENABLE ) {
   1.740 -				SDL_eventstate |= (0x00000001 << (type));
   1.741 -			} else {
   1.742 -				SDL_eventstate &= ~(0x00000001 << (type));
   1.743 -			}
   1.744 -			while ( SDL_PollEvent(&bitbucket) > 0 )
   1.745 -				;
   1.746 -			break;
   1.747 -		default:
   1.748 -			/* Querying state? */
   1.749 -			break;
   1.750 -	}
   1.751 -	return(current_state);
   1.752 +    /* Just set the state for one event type */
   1.753 +    current_state = SDL_ProcessEvents[type];
   1.754 +    switch (state) {
   1.755 +    case SDL_IGNORE:
   1.756 +    case SDL_ENABLE:
   1.757 +        /* Set state and discard pending events */
   1.758 +        SDL_ProcessEvents[type] = state;
   1.759 +        if (state == SDL_ENABLE) {
   1.760 +            SDL_eventstate |= (0x00000001 << (type));
   1.761 +        } else {
   1.762 +            SDL_eventstate &= ~(0x00000001 << (type));
   1.763 +        }
   1.764 +        while (SDL_PollEvent (&bitbucket) > 0);
   1.765 +        break;
   1.766 +    default:
   1.767 +        /* Querying state? */
   1.768 +        break;
   1.769 +    }
   1.770 +    return (current_state);
   1.771  }
   1.772  
   1.773  /* This is a generic event handler.
   1.774   */
   1.775 -int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message)
   1.776 +int
   1.777 +SDL_PrivateSysWMEvent (SDL_SysWMmsg * message)
   1.778  {
   1.779 -	int posted;
   1.780 +    int posted;
   1.781  
   1.782 -	posted = 0;
   1.783 -	if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
   1.784 -		SDL_Event event;
   1.785 -		SDL_memset(&event, 0, sizeof(event));
   1.786 -		event.type = SDL_SYSWMEVENT;
   1.787 -		event.syswm.msg = message;
   1.788 -		if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
   1.789 -			posted = 1;
   1.790 -			SDL_PushEvent(&event);
   1.791 -		}
   1.792 -	}
   1.793 -	/* Update internal event state */
   1.794 -	return(posted);
   1.795 +    posted = 0;
   1.796 +    if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
   1.797 +        SDL_Event event;
   1.798 +        SDL_memset (&event, 0, sizeof (event));
   1.799 +        event.type = SDL_SYSWMEVENT;
   1.800 +        event.syswm.msg = message;
   1.801 +        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   1.802 +            posted = 1;
   1.803 +            SDL_PushEvent (&event);
   1.804 +        }
   1.805 +    }
   1.806 +    /* Update internal event state */
   1.807 +    return (posted);
   1.808  }
   1.809 +
   1.810 +/* vi: set ts=4 sw=4 expandtab: */