annotate src/events/SDL_events.c @ 5125:dc0dfdd58f27

Removed completely non-portable event thread hack. Next I'll be working on generalizing the event sources and making the event queue lock-free. :)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 27 Jan 2011 22:44:08 -0800
parents 481dabb098ef
children 3052772b59db
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3611
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* General event handling code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include "SDL.h"
2984
0b160c970b7e Fixed some dependency issues with SDL_revision.h
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
27 #include "SDL_events.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include "SDL_syswm.h"
2984
0b160c970b7e Fixed some dependency issues with SDL_revision.h
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
29 #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
30 #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
31 #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
32 #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
33 #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
34 #endif
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
35 #include "../video/SDL_sysvideo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 /* Public data -- the event filter */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 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
39 void *SDL_EventOKParam;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
40
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
41 typedef struct {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
42 Uint32 bits[8];
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
43 } SDL_DisabledEventBlock;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
44
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
45 static SDL_DisabledEventBlock *SDL_disabled_events[256];
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
46 static Uint32 SDL_userevents = SDL_USEREVENT;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 /* Private data -- event queue */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #define MAXEVENTS 128
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
50 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
51 {
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
52 SDL_mutex *lock;
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
53 int active;
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
54 int head;
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
55 int tail;
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
56 SDL_Event event[MAXEVENTS];
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
57 int wmmsg_next;
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
58 struct SDL_SysWMmsg wmmsg[MAXEVENTS];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 } SDL_EventQ;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
62 static __inline__ SDL_bool
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
63 SDL_ShouldPollJoystick()
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
64 {
4698
52697090c967 Fix a compile error when SDL_JOYSTICK_DISABLED is set
Paul Hunkin <paul@bieh.net>
parents: 4460
diff changeset
65 #if !SDL_JOYSTICK_DISABLED
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
66 if (SDL_numjoysticks &&
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
67 (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
68 SDL_JoystickEventState(SDL_QUERY))) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
69 return SDL_TRUE;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
70 }
4698
52697090c967 Fix a compile error when SDL_JOYSTICK_DISABLED is set
Paul Hunkin <paul@bieh.net>
parents: 4460
diff changeset
71 #endif
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
72 return SDL_FALSE;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
73 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
74
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 /* Public functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76
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
77 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
78 SDL_StopEventLoop(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 {
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
80 int i;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
81
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
82 if (SDL_EventQ.lock) {
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
83 SDL_DestroyMutex(SDL_EventQ.lock);
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
84 SDL_EventQ.lock = NULL;
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
85 }
1123
28ac87a38c17 Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents: 1028
diff changeset
86
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
87 /* Clean out EventQ */
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
88 SDL_EventQ.head = 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
89 SDL_EventQ.tail = 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
90 SDL_EventQ.wmmsg_next = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
91
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
92 /* Clear disabled event state */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
93 for (i = 0; i < SDL_arraysize(SDL_disabled_events); ++i) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
94 if (SDL_disabled_events[i]) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
95 SDL_free(SDL_disabled_events[i]);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
96 SDL_disabled_events[i] = NULL;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
97 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
98 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 /* 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
102 int
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
103 SDL_StartEventLoop(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 {
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
105 int retcode;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106
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
107 /* Clean out 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
108 SDL_EventQ.lock = NULL;
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
109 SDL_StopEventLoop();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110
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
111 /* No filter to start with, process most event types */
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
112 SDL_EventOK = NULL;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
113 SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
115 /* Create the lock and set ourselves active */
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
116 #if !SDL_THREADS_DISABLED
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
117 SDL_EventQ.lock = SDL_CreateMutex();
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
118 if (SDL_EventQ.lock == 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
119 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
120 }
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
121 #endif /* !SDL_THREADS_DISABLED */
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
122 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
123
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
124 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 /* 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
129 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
130 SDL_AddEvent(SDL_Event * event)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 {
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
132 int tail, added;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133
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
134 tail = (SDL_EventQ.tail + 1) % MAXEVENTS;
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
135 if (tail == SDL_EventQ.head) {
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
136 /* Overflow, drop 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
137 added = 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
138 } else {
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
139 SDL_EventQ.event[SDL_EventQ.tail] = *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
140 if (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
141 /* Note that it's possible to lose an 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
142 int next = SDL_EventQ.wmmsg_next;
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
143 SDL_EventQ.wmmsg[next] = *event->syswm.msg;
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
144 SDL_EventQ.event[SDL_EventQ.tail].syswm.msg =
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
145 &SDL_EventQ.wmmsg[next];
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
146 SDL_EventQ.wmmsg_next = (next + 1) % MAXEVENTS;
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
147 }
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
148 SDL_EventQ.tail = tail;
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
149 added = 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
150 }
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
151 return (added);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 /* Cut an event, and return the next valid spot, or the tail */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 /* -- 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
156 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
157 SDL_CutEvent(int spot)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 {
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 if (spot == SDL_EventQ.head) {
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
160 SDL_EventQ.head = (SDL_EventQ.head + 1) % MAXEVENTS;
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
161 return (SDL_EventQ.head);
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
162 } else if ((spot + 1) % MAXEVENTS == SDL_EventQ.tail) {
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
163 SDL_EventQ.tail = spot;
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
164 return (SDL_EventQ.tail);
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
165 } else
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
166 /* We cut the middle -- shift everything over */
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
167 {
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
168 int here, next;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169
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
170 /* This can probably be optimized with SDL_memcpy() -- careful! */
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
171 if (--SDL_EventQ.tail < 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
172 SDL_EventQ.tail = MAXEVENTS - 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
173 }
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
174 for (here = spot; here != SDL_EventQ.tail; here = next) {
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 next = (here + 1) % MAXEVENTS;
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
176 SDL_EventQ.event[here] = SDL_EventQ.event[next];
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
177 }
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
178 return (spot);
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
179 }
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
180 /* NOTREACHED */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 /* 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
184 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
185 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
186 Uint32 minType, Uint32 maxType)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 {
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
188 int i, used;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189
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 /* Don't look after we've quit */
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 if (!SDL_EventQ.active) {
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
192 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
193 }
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
194 /* 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
195 used = 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
196 if (SDL_mutexP(SDL_EventQ.lock) == 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
197 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
198 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
199 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
200 }
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
201 } else {
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
202 SDL_Event tmpevent;
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
203 int spot;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204
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
205 /* If 'events' is NULL, just see if they exist */
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
206 if (events == NULL) {
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 action = SDL_PEEKEVENT;
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
208 numevents = 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
209 events = &tmpevent;
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
210 }
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
211 spot = SDL_EventQ.head;
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
212 while ((used < numevents) && (spot != SDL_EventQ.tail)) {
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
213 Uint32 type = SDL_EventQ.event[spot].type;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
214 if (minType <= type && type <= maxType) {
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
215 events[used++] = SDL_EventQ.event[spot];
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 if (action == SDL_GETEVENT) {
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
217 spot = SDL_CutEvent(spot);
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
218 } else {
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
219 spot = (spot + 1) % MAXEVENTS;
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
220 }
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
221 } else {
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
222 spot = (spot + 1) % MAXEVENTS;
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
223 }
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
224 }
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
225 }
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
226 SDL_mutexV(SDL_EventQ.lock);
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
227 } else {
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
228 SDL_SetError("Couldn't lock 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
229 used = -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
230 }
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
231 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
232 }
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
233
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
234 SDL_bool
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
235 SDL_HasEvent(Uint32 type)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
236 {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
237 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
238 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
239
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
240 SDL_bool
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
241 SDL_HasEvents(Uint32 minType, Uint32 maxType)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
242 {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
243 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
244 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
245
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
246 void
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
247 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
248 {
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
249 SDL_FlushEvents(type, type);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
250 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
251
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
252 void
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
253 SDL_FlushEvents(Uint32 minType, Uint32 maxType)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
254 {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
255 /* Don't look after we've quit */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
256 if (!SDL_EventQ.active) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
257 return;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
258 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
259
4460
363604b42e84 Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
260 /* Make sure the events are current */
363604b42e84 Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
261 SDL_PumpEvents();
363604b42e84 Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
262
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
263 /* Lock the event queue */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
264 if (SDL_mutexP(SDL_EventQ.lock) == 0) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
265 int spot = SDL_EventQ.head;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
266 while (spot != SDL_EventQ.tail) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
267 Uint32 type = SDL_EventQ.event[spot].type;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
268 if (minType <= type && type <= maxType) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
269 spot = SDL_CutEvent(spot);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
270 } else {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
271 spot = (spot + 1) % MAXEVENTS;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
272 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
273 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
274 SDL_mutexV(SDL_EventQ.lock);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
275 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 /* 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
279 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
280 SDL_PumpEvents(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 {
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
282 SDL_VideoDevice *_this = SDL_GetVideoDevice();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
284 /* Get events from the video subsystem */
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
285 if (_this) {
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
286 _this->PumpEvents(_this);
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
287 }
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
288 #if !SDL_JOYSTICK_DISABLED
5125
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
289 /* Check for joystick state change */
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
290 if (SDL_ShouldPollJoystick()) {
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
291 SDL_JoystickUpdate();
dc0dfdd58f27 Removed completely non-portable event thread hack.
Sam Lantinga <slouken@libsdl.org>
parents: 5113
diff changeset
292 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 /* Public functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297
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
298 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
299 SDL_PollEvent(SDL_Event * event)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 {
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
301 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
302 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303
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
304 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
305 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
306 {
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
307 return SDL_WaitEventTimeout(event, -1);
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
308 }
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
309
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
310 int
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
311 SDL_WaitEventTimeout(SDL_Event * event, int timeout)
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
312 {
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
313 Uint32 expiration = 0;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
314
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
315 if (timeout > 0)
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
316 expiration = SDL_GetTicks() + timeout;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
317
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
318 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
319 SDL_PumpEvents();
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
320 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
321 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
322 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
323 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
324 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
325 case 0:
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
326 if (timeout == 0) {
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
327 /* Polling and no events, just return */
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
328 return 0;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
329 }
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
330 if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) {
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
331 /* Timeout expired and no events */
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
332 return 0;
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
333 }
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
334 SDL_Delay(10);
3072
9da8f57ab92c Fixed bug #684
Sam Lantinga <slouken@libsdl.org>
parents: 2984
diff changeset
335 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
336 }
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
337 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339
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
340 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
341 SDL_PushEvent(SDL_Event * event)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 {
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
343 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
344 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
345 }
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
346 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
347 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
348 }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
349
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
350 SDL_GestureProcessEvent(event);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
351
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
352
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
353 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355
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 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
357 SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 {
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
359 SDL_Event bitbucket;
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
360
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
361 /* Set filter and discard pending events */
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
362 SDL_EventOK = 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
363 SDL_EventOKParam = 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
364 while (SDL_PollEvent(&bitbucket) > 0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366
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
367 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
368 SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 {
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
370 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
371 *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
372 }
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
373 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
374 *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
375 }
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
376 return SDL_EventOK ? SDL_TRUE : SDL_FALSE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378
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
379 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
380 SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 {
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
382 if (SDL_mutexP(SDL_EventQ.lock) == 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
383 int spot;
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
384
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
385 spot = SDL_EventQ.head;
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
386 while (spot != SDL_EventQ.tail) {
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
387 if (filter(userdata, &SDL_EventQ.event[spot])) {
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
388 spot = (spot + 1) % MAXEVENTS;
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
389 } else {
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
390 spot = SDL_CutEvent(spot);
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
391 }
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 }
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 }
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
394 SDL_mutexV(SDL_EventQ.lock);
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
395 }
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
396
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
397 Uint8
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
398 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
399 {
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
400 Uint8 current_state;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
401 Uint8 hi = ((type >> 8) & 0xff);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
402 Uint8 lo = (type & 0xff);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
404 if (SDL_disabled_events[hi] &&
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
405 (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
406 current_state = SDL_DISABLE;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
407 } else {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
408 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
409 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
411 if (state != current_state)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
412 {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
413 switch (state) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
414 case SDL_DISABLE:
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
415 /* 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
416 if (!SDL_disabled_events[hi]) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
417 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
418 if (!SDL_disabled_events[hi]) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
419 /* Out of memory, nothing we can do... */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
420 break;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
421 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
422 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
423 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
424 SDL_FlushEvent(type);
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
425 break;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
426 case SDL_ENABLE:
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
427 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
428 break;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
429 default:
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
430 /* Querying state... */
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
431 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
432 }
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
433 }
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
434
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
435 return current_state;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
436 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
437
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
438 Uint32
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
439 SDL_RegisterEvents(int numevents)
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
440 {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
441 Uint32 event_base;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
442
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
443 if (SDL_userevents+numevents <= SDL_LASTEVENT) {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
444 event_base = SDL_userevents;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
445 SDL_userevents += numevents;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
446 } else {
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
447 event_base = (Uint32)-1;
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
448 }
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
449 return event_base;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 /* This is a generic event handler.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453 */
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
454 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
455 SDL_SendSysWMEvent(SDL_SysWMmsg * message)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 {
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
457 int posted;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458
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
459 posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
460 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
461 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
462 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
463 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
464 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
465 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
466 }
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
467 /* 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
468 return (posted);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
469 }
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
470
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
471 /* vi: set ts=4 sw=4 expandtab: */