src/events/SDL_events.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 01 Feb 2011 19:15:42 -0800
changeset 5146 3052772b59db
parent 5123 dc0dfdd58f27
child 5154 fb424691cfc7
permissions -rw-r--r--
Added functions to watch events as they go through the event queue.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@2984
    27
#include "SDL_events.h"
slouken@0
    28
#include "SDL_syswm.h"
slouken@2984
    29
#include "SDL_thread.h"
slouken@1361
    30
#include "SDL_events_c.h"
slouken@1361
    31
#include "../timer/SDL_timer_c.h"
slouken@1361
    32
#if !SDL_JOYSTICK_DISABLED
slouken@1361
    33
#include "../joystick/SDL_joystick_c.h"
slouken@1361
    34
#endif
slouken@5123
    35
#include "../video/SDL_sysvideo.h"
slouken@0
    36
slouken@0
    37
/* Public data -- the event filter */
slouken@0
    38
SDL_EventFilter SDL_EventOK = NULL;
slouken@1895
    39
void *SDL_EventOKParam;
slouken@4429
    40
slouken@5146
    41
typedef struct SDL_EventWatcher {
slouken@5146
    42
    SDL_EventFilter callback;
slouken@5146
    43
    void *userdata;
slouken@5146
    44
    struct SDL_EventWatcher *next;
slouken@5146
    45
} SDL_EventWatcher;
slouken@5146
    46
slouken@5146
    47
static SDL_EventWatcher *SDL_event_watchers = NULL;
slouken@5146
    48
slouken@4429
    49
typedef struct {
slouken@4429
    50
    Uint32 bits[8];
slouken@4429
    51
} SDL_DisabledEventBlock;
slouken@4429
    52
slouken@4429
    53
static SDL_DisabledEventBlock *SDL_disabled_events[256];
slouken@4429
    54
static Uint32 SDL_userevents = SDL_USEREVENT;
slouken@0
    55
slouken@0
    56
/* Private data -- event queue */
slouken@0
    57
#define MAXEVENTS	128
slouken@1895
    58
static struct
slouken@1895
    59
{
slouken@1895
    60
    SDL_mutex *lock;
slouken@1895
    61
    int active;
slouken@1895
    62
    int head;
slouken@1895
    63
    int tail;
slouken@1895
    64
    SDL_Event event[MAXEVENTS];
slouken@1895
    65
    int wmmsg_next;
slouken@1895
    66
    struct SDL_SysWMmsg wmmsg[MAXEVENTS];
slouken@0
    67
} SDL_EventQ;
slouken@0
    68
slouken@0
    69
slouken@4429
    70
static __inline__ SDL_bool
slouken@4429
    71
SDL_ShouldPollJoystick()
slouken@4429
    72
{
paul@4698
    73
#if !SDL_JOYSTICK_DISABLED
slouken@4429
    74
    if (SDL_numjoysticks &&
slouken@4429
    75
        (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
slouken@4429
    76
         SDL_JoystickEventState(SDL_QUERY))) {
slouken@4429
    77
        return SDL_TRUE;
slouken@4429
    78
    }
paul@4698
    79
#endif
slouken@4429
    80
    return SDL_FALSE;
slouken@4429
    81
}
slouken@4429
    82
slouken@0
    83
/* Public functions */
slouken@0
    84
slouken@1895
    85
void
slouken@1895
    86
SDL_StopEventLoop(void)
slouken@0
    87
{
slouken@4429
    88
    int i;
slouken@4429
    89
slouken@5123
    90
    if (SDL_EventQ.lock) {
slouken@5123
    91
        SDL_DestroyMutex(SDL_EventQ.lock);
slouken@5123
    92
        SDL_EventQ.lock = NULL;
slouken@5123
    93
    }
slouken@1123
    94
slouken@1895
    95
    /* Clean out EventQ */
slouken@1895
    96
    SDL_EventQ.head = 0;
slouken@1895
    97
    SDL_EventQ.tail = 0;
slouken@1895
    98
    SDL_EventQ.wmmsg_next = 0;
slouken@4429
    99
slouken@4429
   100
    /* Clear disabled event state */
slouken@4429
   101
    for (i = 0; i < SDL_arraysize(SDL_disabled_events); ++i) {
slouken@4429
   102
        if (SDL_disabled_events[i]) {
slouken@4429
   103
            SDL_free(SDL_disabled_events[i]);
slouken@4429
   104
            SDL_disabled_events[i] = NULL;
slouken@4429
   105
        }
slouken@4429
   106
    }
slouken@5146
   107
slouken@5146
   108
    while (SDL_event_watchers) {
slouken@5146
   109
        SDL_EventWatcher *tmp = SDL_event_watchers;
slouken@5146
   110
        SDL_event_watchers = tmp->next;
slouken@5146
   111
        SDL_free(tmp);
slouken@5146
   112
    }
slouken@0
   113
}
slouken@0
   114
slouken@0
   115
/* This function (and associated calls) may be called more than once */
slouken@1895
   116
int
slouken@5123
   117
SDL_StartEventLoop(void)
slouken@0
   118
{
slouken@1895
   119
    int retcode;
slouken@0
   120
slouken@1895
   121
    /* Clean out the event queue */
slouken@1895
   122
    SDL_EventQ.lock = NULL;
slouken@1895
   123
    SDL_StopEventLoop();
slouken@0
   124
slouken@1895
   125
    /* No filter to start with, process most event types */
slouken@1895
   126
    SDL_EventOK = NULL;
slouken@4429
   127
    SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
slouken@0
   128
slouken@5123
   129
    /* Create the lock and set ourselves active */
slouken@5123
   130
#if !SDL_THREADS_DISABLED
slouken@5123
   131
    SDL_EventQ.lock = SDL_CreateMutex();
slouken@5123
   132
    if (SDL_EventQ.lock == NULL) {
slouken@1895
   133
        return (-1);
slouken@1895
   134
    }
slouken@5123
   135
#endif /* !SDL_THREADS_DISABLED */
slouken@5123
   136
    SDL_EventQ.active = 1;
slouken@0
   137
slouken@1895
   138
    return (0);
slouken@0
   139
}
slouken@0
   140
slouken@0
   141
slouken@0
   142
/* Add an event to the event queue -- called with the queue locked */
slouken@1895
   143
static int
slouken@1895
   144
SDL_AddEvent(SDL_Event * event)
slouken@0
   145
{
slouken@1895
   146
    int tail, added;
slouken@0
   147
slouken@1895
   148
    tail = (SDL_EventQ.tail + 1) % MAXEVENTS;
slouken@1895
   149
    if (tail == SDL_EventQ.head) {
slouken@1895
   150
        /* Overflow, drop event */
slouken@1895
   151
        added = 0;
slouken@1895
   152
    } else {
slouken@1895
   153
        SDL_EventQ.event[SDL_EventQ.tail] = *event;
slouken@1895
   154
        if (event->type == SDL_SYSWMEVENT) {
slouken@1895
   155
            /* Note that it's possible to lose an event */
slouken@1895
   156
            int next = SDL_EventQ.wmmsg_next;
slouken@1895
   157
            SDL_EventQ.wmmsg[next] = *event->syswm.msg;
slouken@1895
   158
            SDL_EventQ.event[SDL_EventQ.tail].syswm.msg =
slouken@1895
   159
                &SDL_EventQ.wmmsg[next];
slouken@1895
   160
            SDL_EventQ.wmmsg_next = (next + 1) % MAXEVENTS;
slouken@1895
   161
        }
slouken@1895
   162
        SDL_EventQ.tail = tail;
slouken@1895
   163
        added = 1;
slouken@1895
   164
    }
slouken@1895
   165
    return (added);
slouken@0
   166
}
slouken@0
   167
slouken@0
   168
/* Cut an event, and return the next valid spot, or the tail */
slouken@0
   169
/*                           -- called with the queue locked */
slouken@1895
   170
static int
slouken@1895
   171
SDL_CutEvent(int spot)
slouken@0
   172
{
slouken@1895
   173
    if (spot == SDL_EventQ.head) {
slouken@1895
   174
        SDL_EventQ.head = (SDL_EventQ.head + 1) % MAXEVENTS;
slouken@1895
   175
        return (SDL_EventQ.head);
slouken@1895
   176
    } else if ((spot + 1) % MAXEVENTS == SDL_EventQ.tail) {
slouken@1895
   177
        SDL_EventQ.tail = spot;
slouken@1895
   178
        return (SDL_EventQ.tail);
slouken@1895
   179
    } else
slouken@1895
   180
        /* We cut the middle -- shift everything over */
slouken@1895
   181
    {
slouken@1895
   182
        int here, next;
slouken@0
   183
slouken@1895
   184
        /* This can probably be optimized with SDL_memcpy() -- careful! */
slouken@1895
   185
        if (--SDL_EventQ.tail < 0) {
slouken@1895
   186
            SDL_EventQ.tail = MAXEVENTS - 1;
slouken@1895
   187
        }
slouken@1895
   188
        for (here = spot; here != SDL_EventQ.tail; here = next) {
slouken@1895
   189
            next = (here + 1) % MAXEVENTS;
slouken@1895
   190
            SDL_EventQ.event[here] = SDL_EventQ.event[next];
slouken@1895
   191
        }
slouken@1895
   192
        return (spot);
slouken@1895
   193
    }
slouken@1895
   194
    /* NOTREACHED */
slouken@0
   195
}
slouken@0
   196
slouken@0
   197
/* Lock the event queue, take a peep at it, and unlock it */
slouken@1895
   198
int
slouken@1895
   199
SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
slouken@4429
   200
               Uint32 minType, Uint32 maxType)
slouken@0
   201
{
slouken@1895
   202
    int i, used;
slouken@0
   203
slouken@1895
   204
    /* Don't look after we've quit */
slouken@1895
   205
    if (!SDL_EventQ.active) {
slouken@1895
   206
        return (-1);
slouken@1895
   207
    }
slouken@1895
   208
    /* Lock the event queue */
slouken@1895
   209
    used = 0;
slouken@1895
   210
    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
slouken@1895
   211
        if (action == SDL_ADDEVENT) {
slouken@1895
   212
            for (i = 0; i < numevents; ++i) {
slouken@1895
   213
                used += SDL_AddEvent(&events[i]);
slouken@1895
   214
            }
slouken@1895
   215
        } else {
slouken@1895
   216
            SDL_Event tmpevent;
slouken@1895
   217
            int spot;
slouken@0
   218
slouken@1895
   219
            /* If 'events' is NULL, just see if they exist */
slouken@1895
   220
            if (events == NULL) {
slouken@1895
   221
                action = SDL_PEEKEVENT;
slouken@1895
   222
                numevents = 1;
slouken@1895
   223
                events = &tmpevent;
slouken@1895
   224
            }
slouken@1895
   225
            spot = SDL_EventQ.head;
slouken@1895
   226
            while ((used < numevents) && (spot != SDL_EventQ.tail)) {
slouken@4429
   227
                Uint32 type = SDL_EventQ.event[spot].type;
slouken@4429
   228
                if (minType <= type && type <= maxType) {
slouken@1895
   229
                    events[used++] = SDL_EventQ.event[spot];
slouken@1895
   230
                    if (action == SDL_GETEVENT) {
slouken@1895
   231
                        spot = SDL_CutEvent(spot);
slouken@1895
   232
                    } else {
slouken@1895
   233
                        spot = (spot + 1) % MAXEVENTS;
slouken@1895
   234
                    }
slouken@1895
   235
                } else {
slouken@1895
   236
                    spot = (spot + 1) % MAXEVENTS;
slouken@1895
   237
                }
slouken@1895
   238
            }
slouken@1895
   239
        }
slouken@1895
   240
        SDL_mutexV(SDL_EventQ.lock);
slouken@1895
   241
    } else {
slouken@1895
   242
        SDL_SetError("Couldn't lock event queue");
slouken@1895
   243
        used = -1;
slouken@1895
   244
    }
slouken@1895
   245
    return (used);
slouken@1895
   246
}
slouken@1895
   247
slouken@1895
   248
SDL_bool
slouken@4429
   249
SDL_HasEvent(Uint32 type)
slouken@1895
   250
{
slouken@4429
   251
    return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0);
slouken@4429
   252
}
slouken@4429
   253
slouken@4429
   254
SDL_bool
slouken@4429
   255
SDL_HasEvents(Uint32 minType, Uint32 maxType)
slouken@4429
   256
{
slouken@4429
   257
    return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0);
slouken@4429
   258
}
slouken@4429
   259
slouken@4429
   260
void
slouken@4429
   261
SDL_FlushEvent(Uint32 type)
slouken@4429
   262
{
slouken@4429
   263
    SDL_FlushEvents(type, type);
slouken@4429
   264
}
slouken@4429
   265
slouken@4429
   266
void
slouken@4429
   267
SDL_FlushEvents(Uint32 minType, Uint32 maxType)
slouken@4429
   268
{
slouken@4429
   269
    /* Don't look after we've quit */
slouken@4429
   270
    if (!SDL_EventQ.active) {
slouken@4429
   271
        return;
slouken@4429
   272
    }
slouken@4429
   273
slouken@4460
   274
    /* Make sure the events are current */
slouken@4460
   275
    SDL_PumpEvents();
slouken@4460
   276
slouken@4429
   277
    /* Lock the event queue */
slouken@4429
   278
    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
slouken@4429
   279
        int spot = SDL_EventQ.head;
slouken@4429
   280
        while (spot != SDL_EventQ.tail) {
slouken@4429
   281
            Uint32 type = SDL_EventQ.event[spot].type;
slouken@4429
   282
            if (minType <= type && type <= maxType) {
slouken@4429
   283
                spot = SDL_CutEvent(spot);
slouken@4429
   284
            } else {
slouken@4429
   285
                spot = (spot + 1) % MAXEVENTS;
slouken@4429
   286
            }
slouken@4429
   287
        }
slouken@4429
   288
        SDL_mutexV(SDL_EventQ.lock);
slouken@4429
   289
    }
slouken@0
   290
}
slouken@0
   291
slouken@0
   292
/* Run the system dependent event loops */
slouken@1895
   293
void
slouken@1895
   294
SDL_PumpEvents(void)
slouken@0
   295
{
slouken@5123
   296
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@0
   297
slouken@5123
   298
    /* Get events from the video subsystem */
slouken@5123
   299
    if (_this) {
slouken@5123
   300
        _this->PumpEvents(_this);
slouken@5123
   301
    }
slouken@1361
   302
#if !SDL_JOYSTICK_DISABLED
slouken@5123
   303
    /* Check for joystick state change */
slouken@5123
   304
    if (SDL_ShouldPollJoystick()) {
slouken@5123
   305
        SDL_JoystickUpdate();
slouken@5123
   306
    }
slouken@0
   307
#endif
slouken@0
   308
}
slouken@0
   309
slouken@0
   310
/* Public functions */
slouken@0
   311
slouken@1895
   312
int
slouken@1895
   313
SDL_PollEvent(SDL_Event * event)
slouken@0
   314
{
slouken@3072
   315
    return SDL_WaitEventTimeout(event, 0);
slouken@0
   316
}
slouken@0
   317
slouken@1895
   318
int
slouken@1895
   319
SDL_WaitEvent(SDL_Event * event)
slouken@0
   320
{
slouken@3072
   321
    return SDL_WaitEventTimeout(event, -1);
slouken@3072
   322
}
slouken@3072
   323
slouken@3072
   324
int
slouken@3072
   325
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
slouken@3072
   326
{
slouken@3072
   327
    Uint32 expiration = 0;
slouken@3072
   328
slouken@3072
   329
    if (timeout > 0)
slouken@3072
   330
        expiration = SDL_GetTicks() + timeout;
slouken@3072
   331
slouken@3072
   332
    for (;;) {
slouken@1895
   333
        SDL_PumpEvents();
slouken@4429
   334
        switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
slouken@1895
   335
        case -1:
slouken@1895
   336
            return 0;
slouken@1895
   337
        case 1:
slouken@1895
   338
            return 1;
slouken@1895
   339
        case 0:
slouken@3072
   340
            if (timeout == 0) {
slouken@3072
   341
                /* Polling and no events, just return */
slouken@3072
   342
                return 0;
slouken@3072
   343
            }
slouken@3072
   344
            if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) {
slouken@3072
   345
                /* Timeout expired and no events */
slouken@3072
   346
                return 0;
slouken@3072
   347
            }
slouken@1895
   348
            SDL_Delay(10);
slouken@3072
   349
            break;
slouken@1895
   350
        }
slouken@1895
   351
    }
slouken@0
   352
}
slouken@0
   353
slouken@1895
   354
int
slouken@1895
   355
SDL_PushEvent(SDL_Event * event)
slouken@0
   356
{
slouken@5146
   357
    SDL_EventWatcher *curr;
slouken@5146
   358
slouken@1895
   359
    if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
slouken@1895
   360
        return 0;
slouken@1895
   361
    }
slouken@5146
   362
slouken@5146
   363
    for (curr = SDL_event_watchers; curr; curr = curr->next) {
slouken@5146
   364
        curr->callback(curr->userdata, event);
slouken@5146
   365
    }
slouken@5146
   366
slouken@4429
   367
    if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0) <= 0) {
slouken@1895
   368
        return -1;
slouken@1895
   369
    }
jim@4657
   370
jim@4657
   371
    SDL_GestureProcessEvent(event);
jim@4657
   372
    
jim@4657
   373
slouken@1895
   374
    return 1;
slouken@0
   375
}
slouken@0
   376
slouken@1895
   377
void
slouken@1895
   378
SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
slouken@0
   379
{
slouken@1895
   380
    SDL_Event bitbucket;
slouken@0
   381
slouken@1895
   382
    /* Set filter and discard pending events */
slouken@1895
   383
    SDL_EventOK = filter;
slouken@1895
   384
    SDL_EventOKParam = userdata;
slouken@1895
   385
    while (SDL_PollEvent(&bitbucket) > 0);
slouken@0
   386
}
slouken@0
   387
slouken@1895
   388
SDL_bool
slouken@1895
   389
SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
slouken@0
   390
{
slouken@1895
   391
    if (filter) {
slouken@1895
   392
        *filter = SDL_EventOK;
slouken@1895
   393
    }
slouken@1895
   394
    if (userdata) {
slouken@1895
   395
        *userdata = SDL_EventOKParam;
slouken@1895
   396
    }
slouken@1895
   397
    return SDL_EventOK ? SDL_TRUE : SDL_FALSE;
slouken@0
   398
}
slouken@0
   399
slouken@5146
   400
/* FIXME: This is not thread-safe yet */
slouken@5146
   401
void
slouken@5146
   402
SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
slouken@5146
   403
{
slouken@5146
   404
    SDL_EventWatcher *watcher;
slouken@5146
   405
slouken@5146
   406
    watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
slouken@5146
   407
    if (!watcher) {
slouken@5146
   408
        /* Uh oh... */
slouken@5146
   409
        return;
slouken@5146
   410
    }
slouken@5146
   411
    watcher->callback = filter;
slouken@5146
   412
    watcher->userdata = userdata;
slouken@5146
   413
    watcher->next = SDL_event_watchers;
slouken@5146
   414
    SDL_event_watchers = watcher;
slouken@5146
   415
}
slouken@5146
   416
slouken@5146
   417
/* FIXME: This is not thread-safe yet */
slouken@5146
   418
void
slouken@5146
   419
SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
slouken@5146
   420
{
slouken@5146
   421
    SDL_EventWatcher *prev = NULL;
slouken@5146
   422
    SDL_EventWatcher *curr;
slouken@5146
   423
slouken@5146
   424
    for (curr = SDL_event_watchers; curr; prev = curr, curr = curr->next) {
slouken@5146
   425
        if (curr->callback == filter && curr->userdata == userdata) {
slouken@5146
   426
            if (prev) {
slouken@5146
   427
                prev->next = curr->next;
slouken@5146
   428
            } else {
slouken@5146
   429
                SDL_event_watchers = curr->next;
slouken@5146
   430
            }
slouken@5146
   431
            SDL_free(curr);
slouken@5146
   432
            break;
slouken@5146
   433
        }
slouken@5146
   434
    }
slouken@5146
   435
}
slouken@5146
   436
slouken@1895
   437
void
slouken@1895
   438
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
slouken@0
   439
{
slouken@1895
   440
    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
slouken@1895
   441
        int spot;
slouken@0
   442
slouken@1895
   443
        spot = SDL_EventQ.head;
slouken@1895
   444
        while (spot != SDL_EventQ.tail) {
slouken@1895
   445
            if (filter(userdata, &SDL_EventQ.event[spot])) {
slouken@1895
   446
                spot = (spot + 1) % MAXEVENTS;
slouken@1895
   447
            } else {
slouken@1895
   448
                spot = SDL_CutEvent(spot);
slouken@1895
   449
            }
slouken@1895
   450
        }
slouken@1895
   451
    }
slouken@1895
   452
    SDL_mutexV(SDL_EventQ.lock);
slouken@1895
   453
}
slouken@0
   454
slouken@1895
   455
Uint8
slouken@4429
   456
SDL_EventState(Uint32 type, int state)
slouken@1895
   457
{
slouken@1895
   458
    Uint8 current_state;
slouken@4429
   459
    Uint8 hi = ((type >> 8) & 0xff);
slouken@4429
   460
    Uint8 lo = (type & 0xff);
slouken@1895
   461
slouken@4429
   462
    if (SDL_disabled_events[hi] &&
slouken@4429
   463
        (SDL_disabled_events[hi]->bits[lo/32] & (1 << (lo&31)))) {
slouken@4429
   464
        current_state = SDL_DISABLE;
slouken@4429
   465
    } else {
slouken@4429
   466
        current_state = SDL_ENABLE;
slouken@1895
   467
    }
slouken@1895
   468
slouken@4429
   469
    if (state != current_state)
slouken@4429
   470
    {
slouken@4429
   471
        switch (state) {
slouken@4429
   472
        case SDL_DISABLE:
slouken@4429
   473
            /* Disable this event type and discard pending events */
slouken@4429
   474
            if (!SDL_disabled_events[hi]) {
slouken@4429
   475
                SDL_disabled_events[hi] = (SDL_DisabledEventBlock*) SDL_calloc(1, sizeof(SDL_DisabledEventBlock));
slouken@4429
   476
                if (!SDL_disabled_events[hi]) {
slouken@4429
   477
                    /* Out of memory, nothing we can do... */
slouken@4429
   478
                    break;
slouken@4429
   479
                }
slouken@4429
   480
            }
slouken@4429
   481
            SDL_disabled_events[hi]->bits[lo/32] |= (1 << (lo&31));
slouken@4429
   482
            SDL_FlushEvent(type);
slouken@4429
   483
            break;
slouken@4429
   484
        case SDL_ENABLE:
slouken@4429
   485
            SDL_disabled_events[hi]->bits[lo/32] &= ~(1 << (lo&31));
slouken@4429
   486
            break;
slouken@4429
   487
        default:
slouken@4429
   488
            /* Querying state... */
slouken@4429
   489
            break;
slouken@1895
   490
        }
slouken@1895
   491
    }
slouken@4429
   492
slouken@4429
   493
    return current_state;
slouken@4429
   494
}
slouken@4429
   495
slouken@4429
   496
Uint32
slouken@4429
   497
SDL_RegisterEvents(int numevents)
slouken@4429
   498
{
slouken@4429
   499
    Uint32 event_base;
slouken@4429
   500
slouken@4429
   501
    if (SDL_userevents+numevents <= SDL_LASTEVENT) {
slouken@4429
   502
        event_base = SDL_userevents;
slouken@4429
   503
        SDL_userevents += numevents;
slouken@4429
   504
    } else {
slouken@4429
   505
        event_base = (Uint32)-1;
slouken@4429
   506
    }
slouken@4429
   507
    return event_base;
slouken@0
   508
}
slouken@0
   509
slouken@0
   510
/* This is a generic event handler.
slouken@0
   511
 */
slouken@1895
   512
int
slouken@1895
   513
SDL_SendSysWMEvent(SDL_SysWMmsg * message)
slouken@0
   514
{
slouken@1895
   515
    int posted;
slouken@0
   516
slouken@1895
   517
    posted = 0;
slouken@4429
   518
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@1895
   519
        SDL_Event event;
slouken@1895
   520
        SDL_memset(&event, 0, sizeof(event));
slouken@1895
   521
        event.type = SDL_SYSWMEVENT;
slouken@1895
   522
        event.syswm.msg = message;
slouken@1895
   523
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
   524
    }
slouken@1895
   525
    /* Update internal event state */
slouken@1895
   526
    return (posted);
slouken@0
   527
}
slouken@1895
   528
slouken@1895
   529
/* vi: set ts=4 sw=4 expandtab: */