src/events/SDL_events.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 10106 d240baef8248
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9898
diff changeset
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5293
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7860
diff changeset
    21
#include "../SDL_internal.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/* General event handling code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
#include "SDL.h"
2984
0b160c970b7e Fixed some dependency issues with SDL_revision.h
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    26
#include "SDL_events.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include "SDL_syswm.h"
2984
0b160c970b7e Fixed some dependency issues with SDL_revision.h
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    28
#include "SDL_thread.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    29
#include "SDL_events_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    30
#include "../timer/SDL_timer_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    31
#if !SDL_JOYSTICK_DISABLED
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    32
#include "../joystick/SDL_joystick_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    33
#endif
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
    34
#include "../video/SDL_sysvideo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
7306
1516fe08e6ec Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
Sam Lantinga <slouken@libsdl.org>
parents: 7305
diff changeset
    36
/* An arbitrary limit so we don't have unbounded growth */
1516fe08e6ec Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
Sam Lantinga <slouken@libsdl.org>
parents: 7305
diff changeset
    37
#define SDL_MAX_QUEUED_EVENTS   65535
1516fe08e6ec Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
Sam Lantinga <slouken@libsdl.org>
parents: 7305
diff changeset
    38
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
/* Public data -- the event filter */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    40
SDL_EventFilter SDL_EventOK = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    41
void *SDL_EventOKParam;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    42
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    43
typedef struct SDL_EventWatcher {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    44
    SDL_EventFilter callback;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    45
    void *userdata;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    46
    struct SDL_EventWatcher *next;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    47
} SDL_EventWatcher;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    48
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    49
static SDL_EventWatcher *SDL_event_watchers = NULL;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
    50
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    51
typedef struct {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    52
    Uint32 bits[8];
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    53
} SDL_DisabledEventBlock;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    54
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    55
static SDL_DisabledEventBlock *SDL_disabled_events[256];
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    56
static Uint32 SDL_userevents = SDL_USEREVENT;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    58
/* Private data -- event queue */
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    59
typedef struct _SDL_EventEntry
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    60
{
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    61
    SDL_Event event;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    62
    SDL_SysWMmsg msg;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    63
    struct _SDL_EventEntry *prev;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    64
    struct _SDL_EventEntry *next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    65
} SDL_EventEntry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    66
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    67
typedef struct _SDL_SysWMEntry
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    68
{
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    69
    SDL_SysWMmsg msg;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    70
    struct _SDL_SysWMEntry *next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    71
} SDL_SysWMEntry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    72
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    73
static struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    74
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    75
    SDL_mutex *lock;
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    76
    SDL_atomic_t active;
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    77
    SDL_atomic_t count;
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    78
    int max_events_seen;
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    79
    SDL_EventEntry *head;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    80
    SDL_EventEntry *tail;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    81
    SDL_EventEntry *free;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    82
    SDL_SysWMEntry *wmmsg_used;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    83
    SDL_SysWMEntry *wmmsg_free;
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    84
} SDL_EventQ = { NULL, { 1 }, { 0 }, 0, NULL, NULL, NULL, NULL, NULL };
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    85
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    86
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
/* Public functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    88
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    89
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    90
SDL_StopEventLoop(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    91
{
9437
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
    92
    const char *report = SDL_GetHint("SDL_EVENT_QUEUE_STATISTICS");
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    93
    int i;
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    94
    SDL_EventEntry *entry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    95
    SDL_SysWMEntry *wmmsg;
6495
2bf42c5e897a Clear the queue active flag when we shutdown, so we don't have a mutex error trying to read the queue.
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    96
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
    97
    if (SDL_EventQ.lock) {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
    98
        SDL_LockMutex(SDL_EventQ.lock);
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
    99
    }
1123
28ac87a38c17 Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents: 1028
diff changeset
   100
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   101
    SDL_AtomicSet(&SDL_EventQ.active, 0);
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   102
9437
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   103
    if (report && SDL_atoi(report)) {
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   104
        SDL_Log("SDL EVENT QUEUE: Maximum events in-flight: %d\n",
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   105
                SDL_EventQ.max_events_seen);
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   106
    }
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   107
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   108
    /* Clean out EventQ */
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   109
    for (entry = SDL_EventQ.head; entry; ) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   110
        SDL_EventEntry *next = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   111
        SDL_free(entry);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   112
        entry = next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   113
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   114
    for (entry = SDL_EventQ.free; entry; ) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   115
        SDL_EventEntry *next = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   116
        SDL_free(entry);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   117
        entry = next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   118
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   119
    for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; ) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   120
        SDL_SysWMEntry *next = wmmsg->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   121
        SDL_free(wmmsg);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   122
        wmmsg = next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   123
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   124
    for (wmmsg = SDL_EventQ.wmmsg_free; wmmsg; ) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   125
        SDL_SysWMEntry *next = wmmsg->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   126
        SDL_free(wmmsg);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   127
        wmmsg = next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   128
    }
9437
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   129
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   130
    SDL_AtomicSet(&SDL_EventQ.count, 0);
9437
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   131
    SDL_EventQ.max_events_seen = 0;
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   132
    SDL_EventQ.head = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   133
    SDL_EventQ.tail = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   134
    SDL_EventQ.free = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   135
    SDL_EventQ.wmmsg_used = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   136
    SDL_EventQ.wmmsg_free = NULL;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   137
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   138
    /* Clear disabled event state */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   139
    for (i = 0; i < SDL_arraysize(SDL_disabled_events); ++i) {
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7611
diff changeset
   140
        SDL_free(SDL_disabled_events[i]);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7611
diff changeset
   141
        SDL_disabled_events[i] = NULL;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   142
    }
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   143
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   144
    while (SDL_event_watchers) {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   145
        SDL_EventWatcher *tmp = SDL_event_watchers;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   146
        SDL_event_watchers = tmp->next;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   147
        SDL_free(tmp);
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   148
    }
7190
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   149
    SDL_EventOK = NULL;
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   150
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   151
    if (SDL_EventQ.lock) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   152
        SDL_UnlockMutex(SDL_EventQ.lock);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   153
        SDL_DestroyMutex(SDL_EventQ.lock);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   154
        SDL_EventQ.lock = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   155
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
/* This function (and associated calls) may be called more than once */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   159
int
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   160
SDL_StartEventLoop(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   161
{
6588
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   162
    /* We'll leave the event queue alone, since we might have gotten
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   163
       some important events at launch (like SDL_DROPFILE)
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   164
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   165
       FIXME: Does this introduce any other bugs with events at startup?
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   166
     */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   168
    /* Create the lock and set ourselves active */
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   169
#if !SDL_THREADS_DISABLED
6588
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   170
    if (!SDL_EventQ.lock) {
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   171
        SDL_EventQ.lock = SDL_CreateMutex();
f739b8044c26 Allow events at startup so we don't lose important events like SDL_DROPFILE
Sam Lantinga <slouken@libsdl.org>
parents: 6495
diff changeset
   172
    }
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   173
    if (SDL_EventQ.lock == NULL) {
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   174
        return -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   175
    }
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   176
#endif /* !SDL_THREADS_DISABLED */
7077
f8e3dcefed59 Fixed using the event queue lock before the mutex was created.
Ryan C. Gordon <icculus@icculus.org>
parents: 7037
diff changeset
   177
7190
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   178
    /* Process most event types */
7077
f8e3dcefed59 Fixed using the event queue lock before the mutex was created.
Ryan C. Gordon <icculus@icculus.org>
parents: 7037
diff changeset
   179
    SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
f8e3dcefed59 Fixed using the event queue lock before the mutex was created.
Ryan C. Gordon <icculus@icculus.org>
parents: 7037
diff changeset
   180
    SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
f8e3dcefed59 Fixed using the event queue lock before the mutex was created.
Ryan C. Gordon <icculus@icculus.org>
parents: 7037
diff changeset
   181
    SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
f8e3dcefed59 Fixed using the event queue lock before the mutex was created.
Ryan C. Gordon <icculus@icculus.org>
parents: 7037
diff changeset
   182
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   183
    SDL_AtomicSet(&SDL_EventQ.active, 1);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   184
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   185
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
/* Add an event to the event queue -- called with the queue locked */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   190
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   191
SDL_AddEvent(SDL_Event * event)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
{
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   193
    SDL_EventEntry *entry;
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   194
    const int initial_count = SDL_AtomicGet(&SDL_EventQ.count);
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   195
    int final_count;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   197
    if (initial_count >= SDL_MAX_QUEUED_EVENTS) {
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   198
        SDL_SetError("Event queue is full (%d events)", initial_count);
7306
1516fe08e6ec Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
Sam Lantinga <slouken@libsdl.org>
parents: 7305
diff changeset
   199
        return 0;
1516fe08e6ec Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
Sam Lantinga <slouken@libsdl.org>
parents: 7305
diff changeset
   200
    }
1516fe08e6ec Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
Sam Lantinga <slouken@libsdl.org>
parents: 7305
diff changeset
   201
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   202
    if (SDL_EventQ.free == NULL) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   203
        entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   204
        if (!entry) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   205
            return 0;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   206
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   207
    } else {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   208
        entry = SDL_EventQ.free;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   209
        SDL_EventQ.free = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   210
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   211
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   212
    entry->event = *event;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   213
    if (event->type == SDL_SYSWMEVENT) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   214
        entry->msg = *event->syswm.msg;
7305
d918643aee17 Update the queued event wmmsg pointer to point to the queued event data.
Sam Lantinga <slouken@libsdl.org>
parents: 7304
diff changeset
   215
        entry->event.syswm.msg = &entry->msg;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   216
    }
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   217
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   218
    if (SDL_EventQ.tail) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   219
        SDL_EventQ.tail->next = entry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   220
        entry->prev = SDL_EventQ.tail;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   221
        SDL_EventQ.tail = entry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   222
        entry->next = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   223
    } else {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   224
        SDL_assert(!SDL_EventQ.head);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   225
        SDL_EventQ.head = entry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   226
        SDL_EventQ.tail = entry;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   227
        entry->prev = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   228
        entry->next = NULL;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   229
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   230
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   231
    final_count = SDL_AtomicAdd(&SDL_EventQ.count, 1) + 1;
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   232
    if (final_count > SDL_EventQ.max_events_seen) {
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   233
        SDL_EventQ.max_events_seen = final_count;
9437
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   234
    }
569cfb86df95 Keep track of maximum number of events in-flight in the SDL queue at once.
Ryan C. Gordon <icculus@icculus.org>
parents: 8910
diff changeset
   235
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   236
    return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   237
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   239
/* Remove an event from the queue -- called with the queue locked */
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   240
static void
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   241
SDL_CutEvent(SDL_EventEntry *entry)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   242
{
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   243
    if (entry->prev) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   244
        entry->prev->next = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   245
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   246
    if (entry->next) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   247
        entry->next->prev = entry->prev;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   248
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   249
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   250
    if (entry == SDL_EventQ.head) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   251
        SDL_assert(entry->prev == NULL);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   252
        SDL_EventQ.head = entry->next;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   253
    }
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   254
    if (entry == SDL_EventQ.tail) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   255
        SDL_assert(entry->next == NULL);
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   256
        SDL_EventQ.tail = entry->prev;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   257
    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   258
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   259
    entry->next = SDL_EventQ.free;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   260
    SDL_EventQ.free = entry;
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   261
    SDL_assert(SDL_AtomicGet(&SDL_EventQ.count) > 0);
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   262
    SDL_AtomicAdd(&SDL_EventQ.count, -1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   263
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   264
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   265
/* Lock the event queue, take a peep at it, and unlock it */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   266
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   267
SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   268
               Uint32 minType, Uint32 maxType)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   269
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   270
    int i, used;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   271
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   272
    /* Don't look after we've quit */
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   273
    if (!SDL_AtomicGet(&SDL_EventQ.active)) {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   274
        /* We get a few spurious events at shutdown, so don't warn then */
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   275
        if (action != SDL_ADDEVENT) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   276
            SDL_SetError("The event system has been shut down");
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   277
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   278
        return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   279
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   280
    /* Lock the event queue */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   281
    used = 0;
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6949
diff changeset
   282
    if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   283
        if (action == SDL_ADDEVENT) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   284
            for (i = 0; i < numevents; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   285
                used += SDL_AddEvent(&events[i]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   286
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   287
        } else {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   288
            SDL_EventEntry *entry, *next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   289
            SDL_SysWMEntry *wmmsg, *wmmsg_next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   290
            Uint32 type;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   291
10060
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   292
            if (action == SDL_GETEVENT) {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   293
                /* Clean out any used wmmsg data
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   294
                   FIXME: Do we want to retain the data for some period of time?
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   295
                 */
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   296
                for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   297
                    wmmsg_next = wmmsg->next;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   298
                    wmmsg->next = SDL_EventQ.wmmsg_free;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   299
                    SDL_EventQ.wmmsg_free = wmmsg;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   300
                }
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   301
                SDL_EventQ.wmmsg_used = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   302
            }
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   303
10060
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   304
            for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   305
                next = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   306
                type = entry->event.type;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   307
                if (minType <= type && type <= maxType) {
10060
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   308
                    if (events) {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   309
                        events[used] = entry->event;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   310
                        if (entry->event.type == SDL_SYSWMEVENT) {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   311
                            /* We need to copy the wmmsg somewhere safe.
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   312
                               For now we'll guarantee it's valid at least until
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   313
                               the next call to SDL_PeepEvents()
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   314
                             */
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   315
                            if (SDL_EventQ.wmmsg_free) {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   316
                                wmmsg = SDL_EventQ.wmmsg_free;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   317
                                SDL_EventQ.wmmsg_free = wmmsg->next;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   318
                            } else {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   319
                                wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   320
                            }
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   321
                            wmmsg->msg = *entry->event.syswm.msg;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   322
                            wmmsg->next = SDL_EventQ.wmmsg_used;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   323
                            SDL_EventQ.wmmsg_used = wmmsg;
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   324
                            events[used].syswm.msg = &wmmsg->msg;
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   325
                        }
10060
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   326
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   327
                        if (action == SDL_GETEVENT) {
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   328
                            SDL_CutEvent(entry);
739bc5c7d339 Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
Sam Lantinga <slouken@libsdl.org>
parents: 10003
diff changeset
   329
                        }
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   330
                    }
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   331
                    ++used;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   332
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   333
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   334
        }
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6949
diff changeset
   335
        SDL_UnlockMutex(SDL_EventQ.lock);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   336
    } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6977
diff changeset
   337
        return SDL_SetError("Couldn't lock event queue");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   338
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   339
    return (used);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   340
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   341
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   342
SDL_bool
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   343
SDL_HasEvent(Uint32 type)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   344
{
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   345
    return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   346
}
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   347
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   348
SDL_bool
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   349
SDL_HasEvents(Uint32 minType, Uint32 maxType)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   350
{
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   351
    return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   352
}
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   353
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   354
void
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   355
SDL_FlushEvent(Uint32 type)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   356
{
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   357
    SDL_FlushEvents(type, type);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   358
}
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   359
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   360
void
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   361
SDL_FlushEvents(Uint32 minType, Uint32 maxType)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   362
{
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   363
    /* Don't look after we've quit */
10003
d91a2c45825e Remove almost all instances of "volatile" keyword.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
   364
    if (!SDL_AtomicGet(&SDL_EventQ.active)) {
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   365
        return;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   366
    }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   367
4460
363604b42e84 Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   368
    /* Make sure the events are current */
5293
7e9cdbbf7ba1 Fixed crash while resizing a window on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   369
#if 0
7e9cdbbf7ba1 Fixed crash while resizing a window on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   370
    /* Actually, we can't do this since we might be flushing while processing
7e9cdbbf7ba1 Fixed crash while resizing a window on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   371
       a resize event, and calling this might trigger further resize events.
7e9cdbbf7ba1 Fixed crash while resizing a window on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   372
    */
4460
363604b42e84 Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   373
    SDL_PumpEvents();
5293
7e9cdbbf7ba1 Fixed crash while resizing a window on Mac OS X.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   374
#endif
4460
363604b42e84 Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   375
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   376
    /* Lock the event queue */
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6949
diff changeset
   377
    if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   378
        SDL_EventEntry *entry, *next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   379
        Uint32 type;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   380
        for (entry = SDL_EventQ.head; entry; entry = next) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   381
            next = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   382
            type = entry->event.type;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   383
            if (minType <= type && type <= maxType) {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   384
                SDL_CutEvent(entry);
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   385
            }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   386
        }
6977
b73d51026c68 Changed the name of SDL_mutexP() SDL_mutexV()
Sam Lantinga <slouken@libsdl.org>
parents: 6949
diff changeset
   387
        SDL_UnlockMutex(SDL_EventQ.lock);
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   388
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   389
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   390
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   391
/* Run the system dependent event loops */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   392
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   393
SDL_PumpEvents(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   394
{
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   395
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   396
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   397
    /* Get events from the video subsystem */
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   398
    if (_this) {
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   399
        _this->PumpEvents(_this);
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   400
    }
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   401
#if !SDL_JOYSTICK_DISABLED
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   402
    /* Check for joystick state change */
8860
c4133d635375 Removed SDL_SYS_JoystickNeedsPolling().
Ryan C. Gordon <icculus@icculus.org>
parents: 8791
diff changeset
   403
    if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
5123
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   404
        SDL_JoystickUpdate();
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5111
diff changeset
   405
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   406
#endif
9720
fd60d77139fc Unix: Don't send quit events during signal handler.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   407
fd60d77139fc Unix: Don't send quit events during signal handler.
Ryan C. Gordon <icculus@icculus.org>
parents: 9619
diff changeset
   408
    SDL_SendPendingQuit();  /* in case we had a signal handler fire, etc. */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   409
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   410
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   411
/* Public functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   412
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   413
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   414
SDL_PollEvent(SDL_Event * event)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   415
{
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   416
    return SDL_WaitEventTimeout(event, 0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   417
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   418
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   419
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   420
SDL_WaitEvent(SDL_Event * event)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   421
{
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   422
    return SDL_WaitEventTimeout(event, -1);
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   423
}
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   424
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   425
int
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   426
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   427
{
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   428
    Uint32 expiration = 0;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   429
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   430
    if (timeout > 0)
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   431
        expiration = SDL_GetTicks() + timeout;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   432
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   433
    for (;;) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   434
        SDL_PumpEvents();
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   435
        switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   436
        case -1:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   437
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   438
        case 0:
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   439
            if (timeout == 0) {
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   440
                /* Polling and no events, just return */
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   441
                return 0;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   442
            }
7857
6388f5229bb7 Added a macro SDL_TICKS_PASSED() to correctly compare two 32-bit tick values.
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   443
            if (timeout > 0 && SDL_TICKS_PASSED(SDL_GetTicks(), expiration)) {
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   444
                /* Timeout expired and no events */
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   445
                return 0;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   446
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   447
            SDL_Delay(10);
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
   448
            break;
10106
d240baef8248 Fixed infinite timeout in SDL_WaitEventTimeout() - thanks Константин Гончарик
Sam Lantinga <slouken@libsdl.org>
parents: 10060
diff changeset
   449
        default:
d240baef8248 Fixed infinite timeout in SDL_WaitEventTimeout() - thanks Константин Гончарик
Sam Lantinga <slouken@libsdl.org>
parents: 10060
diff changeset
   450
            /* Has events */
d240baef8248 Fixed infinite timeout in SDL_WaitEventTimeout() - thanks Константин Гончарик
Sam Lantinga <slouken@libsdl.org>
parents: 10060
diff changeset
   451
            return 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   452
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   453
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   454
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   455
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   456
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   457
SDL_PushEvent(SDL_Event * event)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   458
{
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   459
    SDL_EventWatcher *curr;
7190
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   460
7082
e9d6004d2978 future-proofing for Microsoft's C++/CX extensions, whereby "generic" is a reserved keyword
David Ludwig <dludwig@pobox.com>
parents: 7077
diff changeset
   461
    event->common.timestamp = SDL_GetTicks();
7190
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   462
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   463
    if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   464
        return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   465
    }
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   466
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   467
    for (curr = SDL_event_watchers; curr; curr = curr->next) {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   468
        curr->callback(curr->userdata, event);
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   469
    }
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   470
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   471
    if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0) <= 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   472
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   473
    }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
   474
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
   475
    SDL_GestureProcessEvent(event);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
   476
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   477
    return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   478
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   479
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   480
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   481
SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   482
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   483
    /* Set filter and discard pending events */
7201
c6b3d3c32507 Fixed bug 1113 - SDL_SetEventFilter()'s event deletion process is not safe against intervening event push.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   484
    SDL_EventOK = NULL;
c6b3d3c32507 Fixed bug 1113 - SDL_SetEventFilter()'s event deletion process is not safe against intervening event push.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   485
    SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   486
    SDL_EventOKParam = userdata;
7201
c6b3d3c32507 Fixed bug 1113 - SDL_SetEventFilter()'s event deletion process is not safe against intervening event push.
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   487
    SDL_EventOK = filter;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   488
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   489
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   490
SDL_bool
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   491
SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   492
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   493
    if (filter) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   494
        *filter = SDL_EventOK;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   495
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   496
    if (userdata) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   497
        *userdata = SDL_EventOKParam;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   498
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   499
    return SDL_EventOK ? SDL_TRUE : SDL_FALSE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   500
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   501
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   502
/* FIXME: This is not thread-safe yet */
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   503
void
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   504
SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   505
{
8234
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   506
    SDL_EventWatcher *watcher, *tail;
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   507
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   508
    watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   509
    if (!watcher) {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   510
        /* Uh oh... */
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   511
        return;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   512
    }
8234
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   513
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   514
    /* create the watcher */
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   515
    watcher->callback = filter;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   516
    watcher->userdata = userdata;
8234
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   517
    watcher->next = NULL;
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   518
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   519
    /* add the watcher to the end of the list */
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   520
    if (SDL_event_watchers) {
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   521
        for (tail = SDL_event_watchers; tail->next; tail = tail->next) {
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   522
            continue;
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   523
        }
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   524
        tail->next = watcher;
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   525
    } else {
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   526
        SDL_event_watchers = watcher;
80c193c7c8c8 Fixed bug 2414 - Execute event watchers in the order they were added
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   527
    }
5146
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   528
}
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   529
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   530
/* FIXME: This is not thread-safe yet */
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   531
void
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   532
SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   533
{
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   534
    SDL_EventWatcher *prev = NULL;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   535
    SDL_EventWatcher *curr;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   536
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   537
    for (curr = SDL_event_watchers; curr; prev = curr, curr = curr->next) {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   538
        if (curr->callback == filter && curr->userdata == userdata) {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   539
            if (prev) {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   540
                prev->next = curr->next;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   541
            } else {
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   542
                SDL_event_watchers = curr->next;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   543
            }
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   544
            SDL_free(curr);
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   545
            break;
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   546
        }
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   547
    }
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   548
}
3052772b59db Added functions to watch events as they go through the event queue.
Sam Lantinga <slouken@libsdl.org>
parents: 5123
diff changeset
   549
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   550
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   551
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   552
{
8791
44dc9af6b7c2 Fixed SDL error when filtering events after shutdown.
Sam Lantinga <slouken@libsdl.org>
parents: 8583
diff changeset
   553
    if (SDL_EventQ.lock && SDL_LockMutex(SDL_EventQ.lock) == 0) {
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   554
        SDL_EventEntry *entry, *next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   555
        for (entry = SDL_EventQ.head; entry; entry = next) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   556
            next = entry->next;
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   557
            if (!filter(userdata, &entry->event)) {
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   558
                SDL_CutEvent(entry);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   559
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   560
        }
7304
9598cbf46957 Made the SDL event queue dynamically allocated so we don't ever drop events.
Sam Lantinga <slouken@libsdl.org>
parents: 7201
diff changeset
   561
        SDL_UnlockMutex(SDL_EventQ.lock);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   562
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   563
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   564
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   565
Uint8
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   566
SDL_EventState(Uint32 type, int state)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   567
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   568
    Uint8 current_state;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   569
    Uint8 hi = ((type >> 8) & 0xff);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   570
    Uint8 lo = (type & 0xff);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   571
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   572
    if (SDL_disabled_events[hi] &&
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   573
        (SDL_disabled_events[hi]->bits[lo/32] & (1 << (lo&31)))) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   574
        current_state = SDL_DISABLE;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   575
    } else {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   576
        current_state = SDL_ENABLE;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   577
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   578
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   579
    if (state != current_state)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   580
    {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   581
        switch (state) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   582
        case SDL_DISABLE:
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   583
            /* Disable this event type and discard pending events */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   584
            if (!SDL_disabled_events[hi]) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   585
                SDL_disabled_events[hi] = (SDL_DisabledEventBlock*) SDL_calloc(1, sizeof(SDL_DisabledEventBlock));
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   586
                if (!SDL_disabled_events[hi]) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   587
                    /* Out of memory, nothing we can do... */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   588
                    break;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   589
                }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   590
            }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   591
            SDL_disabled_events[hi]->bits[lo/32] |= (1 << (lo&31));
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   592
            SDL_FlushEvent(type);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   593
            break;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   594
        case SDL_ENABLE:
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   595
            SDL_disabled_events[hi]->bits[lo/32] &= ~(1 << (lo&31));
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   596
            break;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   597
        default:
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   598
            /* Querying state... */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   599
            break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   600
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   601
    }
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   602
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   603
    return current_state;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   604
}
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   605
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   606
Uint32
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   607
SDL_RegisterEvents(int numevents)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   608
{
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   609
    Uint32 event_base;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   610
7611
ed6f4b8557e4 SDL_RegisterEvents() now rejects requests for numevents <= 0.
Ryan C. Gordon <icculus@icculus.org>
parents: 7306
diff changeset
   611
    if ((numevents > 0) && (SDL_userevents+numevents <= SDL_LASTEVENT)) {
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   612
        event_base = SDL_userevents;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   613
        SDL_userevents += numevents;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   614
    } else {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   615
        event_base = (Uint32)-1;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   616
    }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   617
    return event_base;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   618
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   619
7190
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   620
int
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   621
SDL_SendAppEvent(SDL_EventType eventType)
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   622
{
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   623
    int posted;
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   624
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   625
    posted = 0;
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   626
    if (SDL_GetEventState(eventType) == SDL_ENABLE) {
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   627
        SDL_Event event;
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   628
        event.type = eventType;
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   629
        posted = (SDL_PushEvent(&event) > 0);
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   630
    }
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   631
    return (posted);
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   632
}
11612d544fcd Added mobile application events, with implementations for iOS and Android
Sam Lantinga <slouken@libsdl.org>
parents: 7082
diff changeset
   633
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   634
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   635
SDL_SendSysWMEvent(SDL_SysWMmsg * message)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   636
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   637
    int posted;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   638
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   639
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   640
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   641
        SDL_Event event;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   642
        SDL_memset(&event, 0, sizeof(event));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   643
        event.type = SDL_SYSWMEVENT;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   644
        event.syswm.msg = message;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   645
        posted = (SDL_PushEvent(&event) > 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   646
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   647
    /* Update internal event state */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   648
    return (posted);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   649
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   650
9898
0da384bef562 Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
Sam Lantinga <slouken@libsdl.org>
parents: 9720
diff changeset
   651
int
0da384bef562 Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
Sam Lantinga <slouken@libsdl.org>
parents: 9720
diff changeset
   652
SDL_SendKeymapChangedEvent(void)
0da384bef562 Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
Sam Lantinga <slouken@libsdl.org>
parents: 9720
diff changeset
   653
{
0da384bef562 Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
Sam Lantinga <slouken@libsdl.org>
parents: 9720
diff changeset
   654
    return SDL_SendAppEvent(SDL_KEYMAPCHANGED);
0da384bef562 Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
Sam Lantinga <slouken@libsdl.org>
parents: 9720
diff changeset
   655
}
0da384bef562 Add a new SDL_KEYMAPCHANGED SDL event to abstract notification of keyboard layout or input language changes.
Sam Lantinga <slouken@libsdl.org>
parents: 9720
diff changeset
   656
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   657
/* vi: set ts=4 sw=4 expandtab: */