src/events/SDL_events.c
author Sam Lantinga
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1666 6e7ec5cb83c3
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

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