Allow events at startup so we don't lose important events like SDL_DROPFILE

This commit is contained in:
Sam Lantinga 2012-10-14 01:30:42 -07:00
parent 40117e88dc
commit 211e6c359c

View file

@ -63,7 +63,7 @@ static struct
SDL_Event event[MAXEVENTS];
int wmmsg_next;
struct SDL_SysWMmsg wmmsg[MAXEVENTS];
} SDL_EventQ;
} SDL_EventQ = { NULL, 1 };
static __inline__ SDL_bool
@ -117,18 +117,21 @@ SDL_StopEventLoop(void)
int
SDL_StartEventLoop(void)
{
/* Clean out the event queue */
SDL_EventQ.lock = NULL;
SDL_StopEventLoop();
/* We'll leave the event queue alone, since we might have gotten
some important events at launch (like SDL_DROPFILE)
FIXME: Does this introduce any other bugs with events at startup?
*/
/* No filter to start with, process most event types */
SDL_EventOK = NULL;
SDL_EventState(SDL_DROPFILE, SDL_DISABLE);
SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
/* Create the lock and set ourselves active */
#if !SDL_THREADS_DISABLED
SDL_EventQ.lock = SDL_CreateMutex();
if (!SDL_EventQ.lock) {
SDL_EventQ.lock = SDL_CreateMutex();
}
if (SDL_EventQ.lock == NULL) {
return (-1);
}
@ -207,7 +210,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
}
/* Lock the event queue */
used = 0;
if (SDL_mutexP(SDL_EventQ.lock) == 0) {
if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) {
if (action == SDL_ADDEVENT) {
for (i = 0; i < numevents; ++i) {
used += SDL_AddEvent(&events[i]);
@ -374,7 +377,6 @@ SDL_PushEvent(SDL_Event * event)
}
SDL_GestureProcessEvent(event);
return 1;
}