src/events/SDL_events.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 21 Aug 2005 06:18:54 +0000
changeset 1123 28ac87a38c17
parent 1028 5ba65305c954
child 1140 af8b0f9ac2f4
permissions -rw-r--r--
Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
From: Jiri Svoboda
Subject: [SDL] signal handling bug

I encountered the following bug:
SDL doesn't reset signal handlers for SIGTERM and SIGINT, after calling SDL_Quit these remain hooked to the handler in SDL_quit.c, being translated into SDL_QUIT events.

Consequently an application that issues a SDL_Quit and remains running will ignore any SIGTERM or SIGINT., and specifically CTRL-C presses.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* General event handling code for SDL */
slouken@0
    29
slouken@0
    30
#include <stdio.h>
slouken@0
    31
#include <string.h>
slouken@0
    32
slouken@0
    33
#include "SDL.h"
slouken@0
    34
#include "SDL_thread.h"
slouken@0
    35
#include "SDL_mutex.h"
slouken@0
    36
#include "SDL_events.h"
slouken@0
    37
#include "SDL_events_c.h"
slouken@0
    38
#include "SDL_timer_c.h"
slouken@0
    39
#ifndef DISABLE_JOYSTICK
slouken@0
    40
#include "SDL_joystick_c.h"
slouken@0
    41
#endif
slouken@0
    42
#ifndef ENABLE_X11
slouken@0
    43
#define DISABLE_X11
slouken@0
    44
#endif
slouken@0
    45
#include "SDL_syswm.h"
slouken@0
    46
#include "SDL_sysevents.h"
slouken@0
    47
slouken@0
    48
/* Public data -- the event filter */
slouken@0
    49
SDL_EventFilter SDL_EventOK = NULL;
slouken@0
    50
Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
slouken@0
    51
static Uint32 SDL_eventstate = 0;
slouken@0
    52
slouken@0
    53
/* Private data -- event queue */
slouken@0
    54
#define MAXEVENTS	128
slouken@0
    55
static struct {
slouken@0
    56
	SDL_mutex *lock;
slouken@0
    57
	int active;
slouken@0
    58
	int head;
slouken@0
    59
	int tail;
slouken@0
    60
	SDL_Event event[MAXEVENTS];
slouken@0
    61
	int wmmsg_next;
slouken@0
    62
	struct SDL_SysWMmsg wmmsg[MAXEVENTS];
slouken@0
    63
} SDL_EventQ;
slouken@0
    64
slouken@0
    65
/* Private data -- event locking structure */
slouken@0
    66
static struct {
slouken@0
    67
	SDL_mutex *lock;
slouken@0
    68
	int safe;
slouken@0
    69
} SDL_EventLock;
slouken@0
    70
slouken@0
    71
/* Thread functions */
slouken@0
    72
static SDL_Thread *SDL_EventThread = NULL;	/* Thread handle */
slouken@0
    73
static Uint32 event_thread;			/* The event thread id */
slouken@0
    74
slouken@0
    75
void SDL_Lock_EventThread(void)
slouken@0
    76
{
slouken@0
    77
	if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) {
slouken@0
    78
		/* Grab lock and spin until we're sure event thread stopped */
slouken@0
    79
		SDL_mutexP(SDL_EventLock.lock);
slouken@0
    80
		while ( ! SDL_EventLock.safe ) {
slouken@0
    81
			SDL_Delay(1);
slouken@0
    82
		}
slouken@0
    83
	}
slouken@0
    84
}
slouken@0
    85
void SDL_Unlock_EventThread(void)
slouken@0
    86
{
slouken@0
    87
	if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) {
slouken@0
    88
		SDL_mutexV(SDL_EventLock.lock);
slouken@0
    89
	}
slouken@0
    90
}
slouken@0
    91
slouken@0
    92
static int SDL_GobbleEvents(void *unused)
slouken@0
    93
{
slouken@0
    94
	event_thread = SDL_ThreadID();
slouken@0
    95
	while ( SDL_EventQ.active ) {
slouken@0
    96
		SDL_VideoDevice *video = current_video;
slouken@0
    97
		SDL_VideoDevice *this  = current_video;
slouken@0
    98
slouken@0
    99
		/* Get events from the video subsystem */
slouken@0
   100
		if ( video ) {
slouken@0
   101
			video->PumpEvents(this);
slouken@0
   102
		}
slouken@0
   103
slouken@0
   104
		/* Queue pending key-repeat events */
slouken@0
   105
		SDL_CheckKeyRepeat();
slouken@0
   106
slouken@0
   107
#ifndef DISABLE_JOYSTICK
slouken@0
   108
		/* Check for joystick state change */
slouken@0
   109
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
slouken@0
   110
			SDL_JoystickUpdate();
slouken@0
   111
		}
slouken@0
   112
#endif
slouken@0
   113
slouken@0
   114
		/* Give up the CPU for the rest of our timeslice */
slouken@0
   115
		SDL_EventLock.safe = 1;
slouken@1028
   116
		if ( SDL_timer_running ) {
slouken@0
   117
			SDL_ThreadedTimerCheck();
slouken@0
   118
		}
slouken@0
   119
		SDL_Delay(1);
slouken@0
   120
slouken@0
   121
		/* Check for event locking.
slouken@0
   122
		   On the P of the lock mutex, if the lock is held, this thread
slouken@0
   123
		   will wait until the lock is released before continuing.  The
slouken@0
   124
		   safe flag will be set, meaning that the other thread can go
slouken@0
   125
		   about it's business.  The safe flag is reset before the V,
slouken@0
   126
		   so as soon as the mutex is free, other threads can see that
slouken@0
   127
		   it's not safe to interfere with the event thread.
slouken@0
   128
		 */
slouken@0
   129
		SDL_mutexP(SDL_EventLock.lock);
slouken@0
   130
		SDL_EventLock.safe = 0;
slouken@0
   131
		SDL_mutexV(SDL_EventLock.lock);
slouken@0
   132
	}
slouken@0
   133
	SDL_SetTimerThreaded(0);
slouken@0
   134
	event_thread = 0;
slouken@0
   135
	return(0);
slouken@0
   136
}
slouken@0
   137
slouken@0
   138
static int SDL_StartEventThread(Uint32 flags)
slouken@0
   139
{
slouken@0
   140
	/* Reset everything to zero */
slouken@0
   141
	SDL_EventThread = NULL;
slouken@0
   142
	memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
slouken@0
   143
slouken@0
   144
	/* Create the lock and set ourselves active */
slouken@0
   145
#ifndef DISABLE_THREADS
slouken@0
   146
	SDL_EventQ.lock = SDL_CreateMutex();
slouken@0
   147
	if ( SDL_EventQ.lock == NULL ) {
slouken@0
   148
#ifdef macintosh /* On MacOS 7/8, you can't multithread, so no lock needed */
slouken@0
   149
		;
slouken@0
   150
#else
slouken@0
   151
		return(-1);
slouken@0
   152
#endif
slouken@0
   153
	}
slouken@0
   154
#endif /* !DISABLE_THREADS */
slouken@0
   155
	SDL_EventQ.active = 1;
slouken@0
   156
slouken@0
   157
	if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
slouken@0
   158
		SDL_EventLock.lock = SDL_CreateMutex();
slouken@0
   159
		if ( SDL_EventLock.lock == NULL ) {
slouken@0
   160
			return(-1);
slouken@0
   161
		}
slouken@0
   162
		SDL_EventLock.safe = 0;
slouken@0
   163
slouken@1028
   164
		/* The event thread will handle timers too */
slouken@1028
   165
		SDL_SetTimerThreaded(2);
slouken@0
   166
		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
slouken@0
   167
		if ( SDL_EventThread == NULL ) {
slouken@0
   168
			return(-1);
slouken@0
   169
		}
slouken@0
   170
	} else {
slouken@0
   171
		event_thread = 0;
slouken@0
   172
	}
slouken@0
   173
	return(0);
slouken@0
   174
}
slouken@0
   175
slouken@0
   176
static void SDL_StopEventThread(void)
slouken@0
   177
{
slouken@0
   178
	SDL_EventQ.active = 0;
slouken@0
   179
	if ( SDL_EventThread ) {
slouken@0
   180
		SDL_WaitThread(SDL_EventThread, NULL);
slouken@0
   181
		SDL_EventThread = NULL;
slouken@0
   182
		SDL_DestroyMutex(SDL_EventLock.lock);
slouken@0
   183
	}
slouken@0
   184
	SDL_DestroyMutex(SDL_EventQ.lock);
slouken@0
   185
}
slouken@0
   186
slouken@0
   187
Uint32 SDL_EventThreadID(void)
slouken@0
   188
{
slouken@0
   189
	return(event_thread);
slouken@0
   190
}
slouken@0
   191
slouken@0
   192
/* Public functions */
slouken@0
   193
slouken@0
   194
void SDL_StopEventLoop(void)
slouken@0
   195
{
slouken@0
   196
	/* Halt the event thread, if running */
slouken@0
   197
	SDL_StopEventThread();
slouken@0
   198
slouken@1123
   199
	/* Shutdown event handlers */
slouken@1123
   200
	SDL_AppActiveQuit();
slouken@1123
   201
	SDL_KeyboardQuit();
slouken@1123
   202
	SDL_MouseQuit();
slouken@1123
   203
	SDL_QuitQuit();
slouken@1123
   204
slouken@0
   205
	/* Clean out EventQ */
slouken@0
   206
	SDL_EventQ.head = 0;
slouken@0
   207
	SDL_EventQ.tail = 0;
slouken@0
   208
	SDL_EventQ.wmmsg_next = 0;
slouken@0
   209
}
slouken@0
   210
slouken@0
   211
/* This function (and associated calls) may be called more than once */
slouken@0
   212
int SDL_StartEventLoop(Uint32 flags)
slouken@0
   213
{
slouken@0
   214
	int retcode;
slouken@0
   215
slouken@0
   216
	/* Clean out the event queue */
slouken@0
   217
	SDL_EventThread = NULL;
slouken@0
   218
	SDL_EventQ.lock = NULL;
slouken@0
   219
	SDL_StopEventLoop();
slouken@0
   220
slouken@0
   221
	/* No filter to start with, process most event types */
slouken@0
   222
	SDL_EventOK = NULL;
slouken@0
   223
	memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents));
slouken@0
   224
	SDL_eventstate = ~0;
slouken@0
   225
	/* It's not save to call SDL_EventState() yet */
slouken@0
   226
	SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT);
slouken@0
   227
	SDL_ProcessEvents[SDL_SYSWMEVENT] = SDL_IGNORE;
slouken@0
   228
slouken@0
   229
	/* Initialize event handlers */
slouken@0
   230
	retcode = 0;
slouken@0
   231
	retcode += SDL_AppActiveInit();
slouken@0
   232
	retcode += SDL_KeyboardInit();
slouken@0
   233
	retcode += SDL_MouseInit();
slouken@0
   234
	retcode += SDL_QuitInit();
slouken@0
   235
	if ( retcode < 0 ) {
slouken@0
   236
		/* We don't expect them to fail, but... */
slouken@0
   237
		return(-1);
slouken@0
   238
	}
slouken@0
   239
slouken@0
   240
	/* Create the lock and event thread */
slouken@0
   241
	if ( SDL_StartEventThread(flags) < 0 ) {
slouken@0
   242
		SDL_StopEventLoop();
slouken@0
   243
		return(-1);
slouken@0
   244
	}
slouken@0
   245
	return(0);
slouken@0
   246
}
slouken@0
   247
slouken@0
   248
slouken@0
   249
/* Add an event to the event queue -- called with the queue locked */
slouken@0
   250
static int SDL_AddEvent(SDL_Event *event)
slouken@0
   251
{
slouken@0
   252
	int tail, added;
slouken@0
   253
slouken@0
   254
	tail = (SDL_EventQ.tail+1)%MAXEVENTS;
slouken@0
   255
	if ( tail == SDL_EventQ.head ) {
slouken@0
   256
		/* Overflow, drop event */
slouken@0
   257
		added = 0;
slouken@0
   258
	} else {
slouken@0
   259
		SDL_EventQ.event[SDL_EventQ.tail] = *event;
slouken@0
   260
		if (event->type == SDL_SYSWMEVENT) {
slouken@0
   261
			/* Note that it's possible to lose an event */
slouken@0
   262
			int next = SDL_EventQ.wmmsg_next;
slouken@0
   263
			SDL_EventQ.wmmsg[next] = *event->syswm.msg;
slouken@0
   264
		        SDL_EventQ.event[SDL_EventQ.tail].syswm.msg =
slouken@0
   265
						&SDL_EventQ.wmmsg[next];
slouken@0
   266
			SDL_EventQ.wmmsg_next = (next+1)%MAXEVENTS;
slouken@0
   267
		}
slouken@0
   268
		SDL_EventQ.tail = tail;
slouken@0
   269
		added = 1;
slouken@0
   270
	}
slouken@0
   271
	return(added);
slouken@0
   272
}
slouken@0
   273
slouken@0
   274
/* Cut an event, and return the next valid spot, or the tail */
slouken@0
   275
/*                           -- called with the queue locked */
slouken@0
   276
static int SDL_CutEvent(int spot)
slouken@0
   277
{
slouken@0
   278
	if ( spot == SDL_EventQ.head ) {
slouken@0
   279
		SDL_EventQ.head = (SDL_EventQ.head+1)%MAXEVENTS;
slouken@0
   280
		return(SDL_EventQ.head);
slouken@0
   281
	} else
slouken@0
   282
	if ( (spot+1)%MAXEVENTS == SDL_EventQ.tail ) {
slouken@0
   283
		SDL_EventQ.tail = spot;
slouken@0
   284
		return(SDL_EventQ.tail);
slouken@0
   285
	} else
slouken@0
   286
	/* We cut the middle -- shift everything over */
slouken@0
   287
	{
slouken@0
   288
		int here, next;
slouken@0
   289
slouken@0
   290
		/* This can probably be optimized with memcpy() -- careful! */
slouken@0
   291
		if ( --SDL_EventQ.tail < 0 ) {
slouken@0
   292
			SDL_EventQ.tail = MAXEVENTS-1;
slouken@0
   293
		}
slouken@0
   294
		for ( here=spot; here != SDL_EventQ.tail; here = next ) {
slouken@0
   295
			next = (here+1)%MAXEVENTS;
slouken@0
   296
			SDL_EventQ.event[here] = SDL_EventQ.event[next];
slouken@0
   297
		}
slouken@0
   298
		return(spot);
slouken@0
   299
	}
slouken@0
   300
	/* NOTREACHED */
slouken@0
   301
}
slouken@0
   302
slouken@0
   303
/* Lock the event queue, take a peep at it, and unlock it */
slouken@0
   304
int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action,
slouken@0
   305
								Uint32 mask)
slouken@0
   306
{
slouken@0
   307
	int i, used;
slouken@0
   308
slouken@0
   309
	/* Don't look after we've quit */
slouken@0
   310
	if ( ! SDL_EventQ.active ) {
slouken@276
   311
		return(-1);
slouken@0
   312
	}
slouken@0
   313
	/* Lock the event queue */
slouken@0
   314
	used = 0;
slouken@0
   315
	if ( SDL_mutexP(SDL_EventQ.lock) == 0 ) {
slouken@0
   316
		if ( action == SDL_ADDEVENT ) {
slouken@0
   317
			for ( i=0; i<numevents; ++i ) {
slouken@0
   318
				used += SDL_AddEvent(&events[i]);
slouken@0
   319
			}
slouken@0
   320
		} else {
slouken@0
   321
			SDL_Event tmpevent;
slouken@0
   322
			int spot;
slouken@0
   323
slouken@0
   324
			/* If 'events' is NULL, just see if they exist */
slouken@0
   325
			if ( events == NULL ) {
slouken@0
   326
				action = SDL_PEEKEVENT;
slouken@0
   327
				numevents = 1;
slouken@0
   328
				events = &tmpevent;
slouken@0
   329
			}
slouken@0
   330
			spot = SDL_EventQ.head;
slouken@0
   331
			while ((used < numevents)&&(spot != SDL_EventQ.tail)) {
slouken@0
   332
				if ( mask & SDL_EVENTMASK(SDL_EventQ.event[spot].type) ) {
slouken@0
   333
					events[used++] = SDL_EventQ.event[spot];
slouken@0
   334
					if ( action == SDL_GETEVENT ) {
slouken@0
   335
						spot = SDL_CutEvent(spot);
slouken@0
   336
					} else {
slouken@0
   337
						spot = (spot+1)%MAXEVENTS;
slouken@0
   338
					}
slouken@0
   339
				} else {
slouken@0
   340
					spot = (spot+1)%MAXEVENTS;
slouken@0
   341
				}
slouken@0
   342
			}
slouken@0
   343
		}
slouken@0
   344
		SDL_mutexV(SDL_EventQ.lock);
slouken@0
   345
	} else {
slouken@0
   346
		SDL_SetError("Couldn't lock event queue");
slouken@0
   347
		used = -1;
slouken@0
   348
	}
slouken@0
   349
	return(used);
slouken@0
   350
}
slouken@0
   351
slouken@0
   352
/* Run the system dependent event loops */
slouken@0
   353
void SDL_PumpEvents(void)
slouken@0
   354
{
slouken@0
   355
	if ( !SDL_EventThread ) {
slouken@0
   356
		SDL_VideoDevice *video = current_video;
slouken@0
   357
		SDL_VideoDevice *this  = current_video;
slouken@0
   358
slouken@0
   359
		/* Get events from the video subsystem */
slouken@0
   360
		if ( video ) {
slouken@0
   361
			video->PumpEvents(this);
slouken@0
   362
		}
slouken@0
   363
slouken@0
   364
		/* Queue pending key-repeat events */
slouken@0
   365
		SDL_CheckKeyRepeat();
slouken@0
   366
slouken@0
   367
#ifndef DISABLE_JOYSTICK
slouken@0
   368
		/* Check for joystick state change */
slouken@0
   369
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
slouken@0
   370
			SDL_JoystickUpdate();
slouken@0
   371
		}
slouken@0
   372
#endif
slouken@0
   373
	}
slouken@0
   374
}
slouken@0
   375
slouken@0
   376
/* Public functions */
slouken@0
   377
slouken@0
   378
int SDL_PollEvent (SDL_Event *event)
slouken@0
   379
{
slouken@0
   380
	SDL_PumpEvents();
slouken@0
   381
slouken@352
   382
	/* We can't return -1, just return 0 (no event) on error */
slouken@352
   383
	if ( SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0 )
slouken@352
   384
		return 0;
slouken@352
   385
	return 1;
slouken@0
   386
}
slouken@0
   387
slouken@0
   388
int SDL_WaitEvent (SDL_Event *event)
slouken@0
   389
{
slouken@0
   390
	while ( 1 ) {
slouken@0
   391
		SDL_PumpEvents();
slouken@0
   392
		switch(SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
slouken@353
   393
		    case -1: return 0;
slouken@0
   394
		    case 1: return 1;
slouken@0
   395
		    case 0: SDL_Delay(10);
slouken@0
   396
		}
slouken@0
   397
	}
slouken@0
   398
}
slouken@0
   399
slouken@0
   400
int SDL_PushEvent(SDL_Event *event)
slouken@0
   401
{
slouken@384
   402
	if ( SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0) <= 0 )
slouken@384
   403
		return -1;
slouken@384
   404
	return 0;
slouken@0
   405
}
slouken@0
   406
slouken@0
   407
void SDL_SetEventFilter (SDL_EventFilter filter)
slouken@0
   408
{
slouken@0
   409
	SDL_Event bitbucket;
slouken@0
   410
slouken@0
   411
	/* Set filter and discard pending events */
slouken@0
   412
	SDL_EventOK = filter;
slouken@0
   413
	while ( SDL_PollEvent(&bitbucket) > 0 )
slouken@0
   414
		;
slouken@0
   415
}
slouken@0
   416
slouken@0
   417
SDL_EventFilter SDL_GetEventFilter(void)
slouken@0
   418
{
slouken@0
   419
	return(SDL_EventOK);
slouken@0
   420
}
slouken@0
   421
slouken@0
   422
Uint8 SDL_EventState (Uint8 type, int state)
slouken@0
   423
{
slouken@0
   424
	SDL_Event bitbucket;
slouken@0
   425
	Uint8 current_state;
slouken@0
   426
slouken@0
   427
	/* If SDL_ALLEVENTS was specified... */
slouken@0
   428
	if ( type == 0xFF ) {
slouken@0
   429
		current_state = SDL_IGNORE;
slouken@0
   430
		for ( type=0; type<SDL_NUMEVENTS; ++type ) {
slouken@0
   431
			if ( SDL_ProcessEvents[type] != SDL_IGNORE ) {
slouken@0
   432
				current_state = SDL_ENABLE;
slouken@0
   433
			}
slouken@0
   434
			SDL_ProcessEvents[type] = state;
slouken@0
   435
			if ( state == SDL_ENABLE ) {
slouken@0
   436
				SDL_eventstate |= (0x00000001 << (type));
slouken@0
   437
			} else {
slouken@0
   438
				SDL_eventstate &= ~(0x00000001 << (type));
slouken@0
   439
			}
slouken@0
   440
		}
slouken@0
   441
		while ( SDL_PollEvent(&bitbucket) > 0 )
slouken@0
   442
			;
slouken@0
   443
		return(current_state);
slouken@0
   444
	}
slouken@0
   445
slouken@0
   446
	/* Just set the state for one event type */
slouken@0
   447
	current_state = SDL_ProcessEvents[type];
slouken@0
   448
	switch (state) {
slouken@0
   449
		case SDL_IGNORE:
slouken@0
   450
		case SDL_ENABLE:
slouken@0
   451
			/* Set state and discard pending events */
slouken@0
   452
			SDL_ProcessEvents[type] = state;
slouken@0
   453
			if ( state == SDL_ENABLE ) {
slouken@0
   454
				SDL_eventstate |= (0x00000001 << (type));
slouken@0
   455
			} else {
slouken@0
   456
				SDL_eventstate &= ~(0x00000001 << (type));
slouken@0
   457
			}
slouken@0
   458
			while ( SDL_PollEvent(&bitbucket) > 0 )
slouken@0
   459
				;
slouken@0
   460
			break;
slouken@0
   461
		default:
slouken@0
   462
			/* Querying state? */
slouken@0
   463
			break;
slouken@0
   464
	}
slouken@0
   465
	return(current_state);
slouken@0
   466
}
slouken@0
   467
slouken@0
   468
/* This is a generic event handler.
slouken@0
   469
 */
slouken@0
   470
int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message)
slouken@0
   471
{
slouken@0
   472
	int posted;
slouken@0
   473
slouken@0
   474
	posted = 0;
slouken@0
   475
	if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
slouken@0
   476
		SDL_Event event;
slouken@0
   477
		memset(&event, 0, sizeof(event));
slouken@0
   478
		event.type = SDL_SYSWMEVENT;
slouken@0
   479
		event.syswm.msg = message;
slouken@0
   480
		if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
slouken@0
   481
			posted = 1;
slouken@0
   482
			SDL_PushEvent(&event);
slouken@0
   483
		}
slouken@0
   484
	}
slouken@0
   485
	/* Update internal event state */
slouken@0
   486
	return(posted);
slouken@0
   487
}