Mercurial > sdl-ios-xcode
annotate src/events/SDL_events.c @ 4630:02895e9c796b
Added some comments.
author | Sunny Sachanandani <sunnysachanandani@gmail.com> |
---|---|
date | Mon, 02 Aug 2010 17:14:09 +0530 |
parents | 363604b42e84 |
children | 057e8762d2a1 52697090c967 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
0 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 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 | 23 |
24 /* General event handling code for SDL */ | |
25 | |
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 | 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" |
0 | 30 #include "SDL_sysevents.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
31 #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
|
32 #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
|
33 #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
|
34 #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
|
35 #endif |
0 | 36 |
37 /* Public data -- the event filter */ | |
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 | 47 |
48 /* Private data -- event queue */ | |
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 | 59 } SDL_EventQ; |
60 | |
61 /* Private data -- event locking structure */ | |
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
|
62 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
|
63 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
64 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
|
65 int safe; |
0 | 66 } SDL_EventLock; |
67 | |
68 /* Thread functions */ | |
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
|
69 static SDL_Thread *SDL_EventThread = NULL; /* Thread handle */ |
3578 | 70 static SDL_threadID event_thread; /* The event thread id */ |
0 | 71 |
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
|
72 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
|
73 SDL_Lock_EventThread(void) |
0 | 74 { |
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
|
75 if (SDL_EventThread && (SDL_ThreadID() != event_thread)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
76 /* Grab lock and spin until we're sure event thread stopped */ |
c121d94672cb
SDL 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 SDL_mutexP(SDL_EventLock.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
|
78 while (!SDL_EventLock.safe) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
79 SDL_Delay(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
|
80 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
81 } |
0 | 82 } |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2129
diff
changeset
|
83 |
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
|
84 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
|
85 SDL_Unlock_EventThread(void) |
0 | 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 if (SDL_EventThread && (SDL_ThreadID() != event_thread)) { |
c121d94672cb
SDL 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_mutexV(SDL_EventLock.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
|
89 } |
0 | 90 } |
91 | |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
92 static __inline__ SDL_bool |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
93 SDL_ShouldPollJoystick() |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
94 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
95 if (SDL_numjoysticks && |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
96 (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
97 SDL_JoystickEventState(SDL_QUERY))) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
98 return SDL_TRUE; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
99 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
100 return SDL_FALSE; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
101 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
102 |
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
|
103 static int SDLCALL |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
104 SDL_GobbleEvents(void *unused) |
0 | 105 { |
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
|
106 event_thread = SDL_ThreadID(); |
1190 | 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 while (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
|
109 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0 | 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 /* Get events from the video subsystem */ |
c121d94672cb
SDL 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 if (_this) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
113 _this->PumpEvents(_this); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
114 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
115 #if !SDL_JOYSTICK_DISABLED |
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
|
116 /* Check for joystick state change */ |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
117 if (SDL_ShouldPollJoystick()) { |
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
|
118 SDL_JoystickUpdate(); |
c121d94672cb
SDL 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 } |
0 | 120 #endif |
121 | |
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
|
122 /* Give up the CPU for the rest of our timeslice */ |
c121d94672cb
SDL 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 SDL_EventLock.safe = 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
|
124 if (SDL_timer_running) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
125 SDL_ThreadedTimerCheck(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
126 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
127 SDL_Delay(1); |
0 | 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
|
129 /* Check for event locking. |
c121d94672cb
SDL 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 On the P of the lock mutex, if the lock is held, this thread |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
131 will wait until the lock is released before continuing. The |
c121d94672cb
SDL 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 safe flag will be set, meaning that the other thread can go |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
133 about it's business. The safe flag is reset before the V, |
c121d94672cb
SDL 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 so as soon as the mutex is free, other threads can see that |
c121d94672cb
SDL 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 it's not safe to interfere with the event thread. |
c121d94672cb
SDL 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 */ |
c121d94672cb
SDL 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 SDL_mutexP(SDL_EventLock.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
|
138 SDL_EventLock.safe = 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
|
139 SDL_mutexV(SDL_EventLock.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
|
140 } |
c121d94672cb
SDL 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 SDL_SetTimerThreaded(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
|
142 event_thread = 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
|
143 return (0); |
0 | 144 } |
145 | |
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
|
146 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
|
147 SDL_StartEventThread(Uint32 flags) |
0 | 148 { |
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
|
149 /* Reset everything to zero */ |
c121d94672cb
SDL 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 SDL_EventThread = 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
|
151 SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock)); |
0 | 152 |
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
|
153 /* Create the lock and set ourselves active */ |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
154 #if !SDL_THREADS_DISABLED |
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
|
155 SDL_EventQ.lock = SDL_CreateMutex(); |
c121d94672cb
SDL 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 if (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
|
157 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
|
158 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
159 #endif /* !SDL_THREADS_DISABLED */ |
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
|
160 SDL_EventQ.active = 1; |
0 | 161 |
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
|
162 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { |
c121d94672cb
SDL 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_EventLock.lock = SDL_CreateMutex(); |
c121d94672cb
SDL 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 if (SDL_EventLock.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
|
165 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
|
166 } |
c121d94672cb
SDL 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 SDL_EventLock.safe = 0; |
0 | 168 |
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
|
169 /* The event thread will handle timers too */ |
c121d94672cb
SDL 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 SDL_SetTimerThreaded(2); |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
171 #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
172 #undef SDL_CreateThread |
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
|
173 SDL_EventThread = |
c121d94672cb
SDL 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 SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
175 #else |
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
|
176 SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL); |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
177 #endif |
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
|
178 if (SDL_EventThread == 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
|
179 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
|
180 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
181 } 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
|
182 event_thread = 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
|
183 } |
c121d94672cb
SDL 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 return (0); |
0 | 185 } |
186 | |
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
|
187 static 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
|
188 SDL_StopEventThread(void) |
0 | 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 SDL_EventQ.active = 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
|
191 if (SDL_EventThread) { |
c121d94672cb
SDL 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 SDL_WaitThread(SDL_EventThread, 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
|
193 SDL_EventThread = 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
|
194 SDL_DestroyMutex(SDL_EventLock.lock); |
3611
57823d017f02
Merged r4121:4122 from branches/SDL-1.2: more double-free fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
3578
diff
changeset
|
195 SDL_EventLock.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
|
196 } |
3259
22ac66da0765
Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3072
diff
changeset
|
197 if (SDL_EventQ.lock) { |
22ac66da0765
Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3072
diff
changeset
|
198 SDL_DestroyMutex(SDL_EventQ.lock); |
22ac66da0765
Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3072
diff
changeset
|
199 SDL_EventQ.lock = NULL; |
22ac66da0765
Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3072
diff
changeset
|
200 } |
0 | 201 } |
202 | |
3578 | 203 SDL_threadID |
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
|
204 SDL_EventThreadID(void) |
0 | 205 { |
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
|
206 return (event_thread); |
0 | 207 } |
208 | |
209 /* Public functions */ | |
210 | |
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
|
211 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
|
212 SDL_StopEventLoop(void) |
0 | 213 { |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
214 int i; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
215 |
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 /* Halt the event thread, if running */ |
c121d94672cb
SDL 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 SDL_StopEventThread(); |
0 | 218 |
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
|
219 /* Shutdown event handlers */ |
c121d94672cb
SDL 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 SDL_KeyboardQuit(); |
c121d94672cb
SDL 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 SDL_MouseQuit(); |
c121d94672cb
SDL 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 SDL_QuitQuit(); |
1123
28ac87a38c17
Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
1028
diff
changeset
|
223 |
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
|
224 /* 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
|
225 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
|
226 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
|
227 SDL_EventQ.wmmsg_next = 0; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
228 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
229 /* Clear disabled event state */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
230 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
|
231 if (SDL_disabled_events[i]) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
232 SDL_free(SDL_disabled_events[i]); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
233 SDL_disabled_events[i] = NULL; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
234 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
235 } |
0 | 236 } |
237 | |
238 /* 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
|
239 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
|
240 SDL_StartEventLoop(Uint32 flags) |
0 | 241 { |
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
|
242 int retcode; |
0 | 243 |
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
|
244 /* 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
|
245 SDL_EventThread = 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
|
246 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
|
247 SDL_StopEventLoop(); |
0 | 248 |
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
|
249 /* 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
|
250 SDL_EventOK = NULL; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
251 SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); |
0 | 252 |
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 /* Initialize event handlers */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
254 retcode = 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
|
255 retcode += SDL_KeyboardInit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
256 retcode += SDL_MouseInit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
257 retcode += SDL_QuitInit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
258 if (retcode < 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
|
259 /* We don't expect them to fail, but... */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
260 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
|
261 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
262 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
263 /* Create the lock and event thread */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
264 if (SDL_StartEventThread(flags) < 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
|
265 SDL_StopEventLoop(); |
c121d94672cb
SDL 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 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
|
267 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
268 return (0); |
0 | 269 } |
270 | |
271 | |
272 /* 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
|
273 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
|
274 SDL_AddEvent(SDL_Event * event) |
0 | 275 { |
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
|
276 int tail, added; |
0 | 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 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
|
279 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
|
280 /* 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
|
281 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
|
282 } 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
|
283 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
|
284 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
|
285 /* 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
|
286 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
|
287 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
|
288 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
|
289 &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
|
290 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
|
291 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
292 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
|
293 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
|
294 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
295 return (added); |
0 | 296 } |
297 | |
298 /* Cut an event, and return the next valid spot, or the tail */ | |
299 /* -- 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
|
300 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
|
301 SDL_CutEvent(int spot) |
0 | 302 { |
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
|
303 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
|
304 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
|
305 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
|
306 } 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
|
307 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
|
308 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
|
309 } 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
|
310 /* 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
|
311 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
312 int here, next; |
0 | 313 |
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
|
314 /* 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
|
315 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
|
316 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
|
317 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 } |
c121d94672cb
SDL 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 (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
|
323 } |
c121d94672cb
SDL 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 /* NOTREACHED */ |
0 | 325 } |
326 | |
327 /* 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
|
328 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
|
329 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
|
330 Uint32 minType, Uint32 maxType) |
0 | 331 { |
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 int i, used; |
0 | 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 /* 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
|
335 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
|
336 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
|
337 } |
c121d94672cb
SDL 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 /* 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 } |
c121d94672cb
SDL 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 } 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
|
346 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
|
347 int spot; |
0 | 348 |
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
|
349 /* 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
355 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
|
356 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
|
357 Uint32 type = SDL_EventQ.event[spot].type; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 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
|
362 } 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
|
363 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
|
364 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
365 } 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
|
366 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
|
367 } |
c121d94672cb
SDL 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 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
369 } |
c121d94672cb
SDL 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 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
|
371 } 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
|
372 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
|
373 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
|
374 } |
c121d94672cb
SDL 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 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
|
376 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
377 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
378 SDL_bool |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
379 SDL_HasEvent(Uint32 type) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
380 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
381 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
|
382 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
383 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
384 SDL_bool |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
385 SDL_HasEvents(Uint32 minType, Uint32 maxType) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
386 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
387 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
|
388 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
389 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
390 void |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
391 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
|
392 { |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
393 SDL_FlushEvents(type, type); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
394 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
395 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
396 void |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
397 SDL_FlushEvents(Uint32 minType, Uint32 maxType) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
398 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
399 /* Don't look after we've quit */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
400 if (!SDL_EventQ.active) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
401 return; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
402 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
403 |
4460
363604b42e84
Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents:
4429
diff
changeset
|
404 /* Make sure the events are current */ |
363604b42e84
Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents:
4429
diff
changeset
|
405 SDL_PumpEvents(); |
363604b42e84
Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents:
4429
diff
changeset
|
406 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
407 /* Lock the event queue */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
408 if (SDL_mutexP(SDL_EventQ.lock) == 0) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
409 int spot = SDL_EventQ.head; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
410 while (spot != SDL_EventQ.tail) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
411 Uint32 type = SDL_EventQ.event[spot].type; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
412 if (minType <= type && type <= maxType) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
413 spot = SDL_CutEvent(spot); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
414 } else { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
415 spot = (spot + 1) % MAXEVENTS; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
416 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
417 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
418 SDL_mutexV(SDL_EventQ.lock); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
419 } |
0 | 420 } |
421 | |
422 /* 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
|
423 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
|
424 SDL_PumpEvents(void) |
0 | 425 { |
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
|
426 if (!SDL_EventThread) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
427 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0 | 428 |
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
|
429 /* Get events from the video subsystem */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
430 if (_this) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
431 _this->PumpEvents(_this); |
c121d94672cb
SDL 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 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
433 #if !SDL_JOYSTICK_DISABLED |
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 /* Check for joystick state change */ |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
435 if (SDL_ShouldPollJoystick()) { |
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 SDL_JoystickUpdate(); |
c121d94672cb
SDL 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 } |
0 | 438 #endif |
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
|
439 } |
0 | 440 } |
441 | |
442 /* Public functions */ | |
443 | |
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
|
444 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
|
445 SDL_PollEvent(SDL_Event * event) |
0 | 446 { |
3072 | 447 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
|
448 } |
0 | 449 |
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
|
450 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
|
451 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
|
452 { |
3072 | 453 return SDL_WaitEventTimeout(event, -1); |
454 } | |
455 | |
456 int | |
457 SDL_WaitEventTimeout(SDL_Event * event, int timeout) | |
458 { | |
459 Uint32 expiration = 0; | |
460 | |
461 if (timeout > 0) | |
462 expiration = SDL_GetTicks() + timeout; | |
463 | |
464 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
|
465 SDL_PumpEvents(); |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 case 0: |
3072 | 472 if (timeout == 0) { |
473 /* Polling and no events, just return */ | |
474 return 0; | |
475 } | |
476 if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) { | |
477 /* Timeout expired and no events */ | |
478 return 0; | |
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 SDL_Delay(10); |
3072 | 481 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
|
482 } |
c121d94672cb
SDL 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 } |
0 | 484 } |
485 | |
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 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
|
487 SDL_PushEvent(SDL_Event * event) |
0 | 488 { |
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
|
489 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
|
490 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
|
491 } |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
492 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
|
493 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
|
494 } |
c121d94672cb
SDL 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 return 1; |
0 | 496 } |
497 | |
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
|
498 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
|
499 SDL_SetEventFilter(SDL_EventFilter filter, void *userdata) |
0 | 500 { |
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
|
501 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
|
502 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
503 /* 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
|
504 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
|
505 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
|
506 while (SDL_PollEvent(&bitbucket) > 0); |
0 | 507 } |
508 | |
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
|
509 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
|
510 SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata) |
0 | 511 { |
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
|
512 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
|
513 *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
|
514 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
515 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
|
516 *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
|
517 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
518 return SDL_EventOK ? SDL_TRUE : SDL_FALSE; |
0 | 519 } |
520 | |
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
|
521 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
|
522 SDL_FilterEvents(SDL_EventFilter filter, void *userdata) |
0 | 523 { |
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
|
524 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
|
525 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
|
526 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
531 } 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
|
532 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
|
533 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
534 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
535 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
536 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
|
537 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
538 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
539 Uint8 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
540 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
|
541 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
542 Uint8 current_state; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
543 Uint8 hi = ((type >> 8) & 0xff); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
544 Uint8 lo = (type & 0xff); |
0 | 545 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
546 if (SDL_disabled_events[hi] && |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
547 (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
|
548 current_state = SDL_DISABLE; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
549 } else { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
550 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
|
551 } |
0 | 552 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
553 if (state != current_state) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
554 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
555 switch (state) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
556 case SDL_DISABLE: |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
557 /* 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
|
558 if (!SDL_disabled_events[hi]) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
559 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
|
560 if (!SDL_disabled_events[hi]) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
561 /* Out of memory, nothing we can do... */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
562 break; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
563 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
564 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
565 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
|
566 SDL_FlushEvent(type); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
567 break; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
568 case SDL_ENABLE: |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
569 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
|
570 break; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
571 default: |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
572 /* Querying state... */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
573 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
|
574 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
575 } |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
576 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
577 return current_state; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
578 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
579 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
580 Uint32 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
581 SDL_RegisterEvents(int numevents) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
582 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
583 Uint32 event_base; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
584 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
585 if (SDL_userevents+numevents <= SDL_LASTEVENT) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
586 event_base = SDL_userevents; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
587 SDL_userevents += numevents; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
588 } else { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
589 event_base = (Uint32)-1; |
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 return event_base; |
0 | 592 } |
593 | |
594 /* This is a generic event handler. | |
595 */ | |
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
|
596 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
|
597 SDL_SendSysWMEvent(SDL_SysWMmsg * message) |
0 | 598 { |
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
|
599 int posted; |
0 | 600 |
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
|
601 posted = 0; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
609 /* 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
|
610 return (posted); |
0 | 611 } |
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
|
612 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
613 /* vi: set ts=4 sw=4 expandtab: */ |