Mercurial > sdl-ios-xcode
annotate src/events/SDL_events.c @ 5113:481dabb098ef
Improved timer implementation
The new timer model is formalized as using a separate thread to handle timer callbacks. This was the case on almost every platform before, but it's now a requirement, and simplifies the implementation and makes it perform consistently across platforms.
Goals:
* Minimize timer thread blocking
* Dispatch timers as accurately as possible
* SDL_AddTimer() and SDL_RemoveTimer() are completely threadsafe
* SDL_RemoveTimer() doesn't crash with a timer that's expired or removed
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 27 Jan 2011 14:45:06 -0800 |
parents | c2539ff054c8 |
children | dc0dfdd58f27 |
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 { |
4698
52697090c967
Fix a compile error when SDL_JOYSTICK_DISABLED is set
Paul Hunkin <paul@bieh.net>
parents:
4460
diff
changeset
|
95 #if !SDL_JOYSTICK_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
96 if (SDL_numjoysticks && |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
97 (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
98 SDL_JoystickEventState(SDL_QUERY))) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
99 return SDL_TRUE; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
100 } |
4698
52697090c967
Fix a compile error when SDL_JOYSTICK_DISABLED is set
Paul Hunkin <paul@bieh.net>
parents:
4460
diff
changeset
|
101 #endif |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
102 return SDL_FALSE; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
103 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
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 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
|
106 SDL_GobbleEvents(void *unused) |
0 | 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 event_thread = SDL_ThreadID(); |
1190 | 109 |
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
|
110 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
|
111 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0 | 112 |
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
|
113 /* 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
|
114 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
|
115 _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
|
116 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
117 #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
|
118 /* Check for joystick state change */ |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
119 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
|
120 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
|
121 } |
0 | 122 #endif |
123 | |
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
|
124 /* 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
|
125 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
|
126 SDL_Delay(1); |
0 | 127 |
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
|
128 /* 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 */ |
c121d94672cb
SDL 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 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
|
137 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
|
138 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
|
139 } |
c121d94672cb
SDL 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 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
|
141 return (0); |
0 | 142 } |
143 | |
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
|
144 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
|
145 SDL_StartEventThread(Uint32 flags) |
0 | 146 { |
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
|
147 /* 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
|
148 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
|
149 SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock)); |
0 | 150 |
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
|
151 /* 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
|
152 #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
|
153 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
|
154 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
|
155 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
|
156 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
157 #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
|
158 SDL_EventQ.active = 1; |
0 | 159 |
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 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
|
161 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
|
162 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
|
163 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
|
164 } |
c121d94672cb
SDL 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 SDL_EventLock.safe = 0; |
0 | 166 |
5088
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
5062
diff
changeset
|
167 #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
|
168 #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
|
169 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
|
170 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
|
171 #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
|
172 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
|
173 #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
|
174 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
|
175 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
|
176 } |
c121d94672cb
SDL 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 } 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
|
178 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
|
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 return (0); |
0 | 181 } |
182 | |
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
|
183 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
|
184 SDL_StopEventThread(void) |
0 | 185 { |
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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 } |
3259
22ac66da0765
Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
3072
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 } |
0 | 197 } |
198 | |
3578 | 199 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
|
200 SDL_EventThreadID(void) |
0 | 201 { |
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
|
202 return (event_thread); |
0 | 203 } |
204 | |
205 /* Public functions */ | |
206 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
207 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
|
208 SDL_StopEventLoop(void) |
0 | 209 { |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
210 int i; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
211 |
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
|
212 /* 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
|
213 SDL_StopEventThread(); |
0 | 214 |
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 /* 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
|
216 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
|
217 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
|
218 SDL_QuitQuit(); |
1123
28ac87a38c17
Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
Sam Lantinga <slouken@libsdl.org>
parents:
1028
diff
changeset
|
219 |
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
|
220 /* 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
|
221 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
|
222 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
|
223 SDL_EventQ.wmmsg_next = 0; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
224 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
225 /* Clear disabled event state */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
226 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
|
227 if (SDL_disabled_events[i]) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
228 SDL_free(SDL_disabled_events[i]); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
229 SDL_disabled_events[i] = NULL; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
230 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
231 } |
0 | 232 } |
233 | |
234 /* 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
|
235 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
|
236 SDL_StartEventLoop(Uint32 flags) |
0 | 237 { |
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
|
238 int retcode; |
0 | 239 |
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
|
240 /* 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
|
241 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
|
242 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
|
243 SDL_StopEventLoop(); |
0 | 244 |
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
|
245 /* 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
|
246 SDL_EventOK = NULL; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
247 SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); |
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 /* 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
|
250 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
|
251 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
|
252 retcode += SDL_MouseInit(); |
4642
057e8762d2a1
Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents:
4460
diff
changeset
|
253 retcode += SDL_TouchInit(); |
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
|
254 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
|
255 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
|
256 /* 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
|
257 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
|
258 } |
c121d94672cb
SDL 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 |
c121d94672cb
SDL 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 /* 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
|
261 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
|
262 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
|
263 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
|
264 } |
c121d94672cb
SDL 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 return (0); |
0 | 266 } |
267 | |
268 | |
269 /* 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
|
270 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
|
271 SDL_AddEvent(SDL_Event * event) |
0 | 272 { |
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 int tail, added; |
0 | 274 |
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
|
275 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
|
276 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
|
277 /* 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
|
278 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
|
279 } 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
|
280 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
|
281 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
|
282 /* 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
|
283 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
|
284 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
|
285 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
|
286 &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 = (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
|
288 } |
c121d94672cb
SDL 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.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
|
290 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
|
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 return (added); |
0 | 293 } |
294 | |
295 /* Cut an event, and return the next valid spot, or the tail */ | |
296 /* -- 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
|
297 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
|
298 SDL_CutEvent(int spot) |
0 | 299 { |
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 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
|
301 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
|
302 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
|
303 } 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
|
304 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
|
305 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
|
306 } 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
|
307 /* 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
|
308 { |
c121d94672cb
SDL 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 int here, next; |
0 | 310 |
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
|
311 /* 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
|
312 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
|
313 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
|
314 } |
c121d94672cb
SDL 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 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
|
316 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
|
317 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
|
318 } |
c121d94672cb
SDL 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 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
|
320 } |
c121d94672cb
SDL 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 /* NOTREACHED */ |
0 | 322 } |
323 | |
324 /* 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
|
325 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
|
326 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
|
327 Uint32 minType, Uint32 maxType) |
0 | 328 { |
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
|
329 int i, used; |
0 | 330 |
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
|
331 /* 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
|
332 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
|
333 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
|
334 } |
c121d94672cb
SDL 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 /* 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
342 } 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
|
343 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
|
344 int spot; |
0 | 345 |
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
|
346 /* 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 } |
c121d94672cb
SDL 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 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
|
353 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
|
354 Uint32 type = SDL_EventQ.event[spot].type; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 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
|
359 } 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
|
360 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
|
361 } |
c121d94672cb
SDL 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 } |
c121d94672cb
SDL 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 } |
c121d94672cb
SDL 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_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
|
368 } 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
|
369 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
|
370 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
|
371 } |
c121d94672cb
SDL 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 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
|
373 } |
c121d94672cb
SDL 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 SDL_bool |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
376 SDL_HasEvent(Uint32 type) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
377 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
378 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
|
379 } |
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 SDL_bool |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
382 SDL_HasEvents(Uint32 minType, Uint32 maxType) |
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 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
|
385 } |
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 void |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
388 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
|
389 { |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
390 SDL_FlushEvents(type, type); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
391 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
392 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
393 void |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
394 SDL_FlushEvents(Uint32 minType, Uint32 maxType) |
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 /* Don't look after we've quit */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
397 if (!SDL_EventQ.active) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
398 return; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
399 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
400 |
4460
363604b42e84
Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents:
4429
diff
changeset
|
401 /* Make sure the events are current */ |
363604b42e84
Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents:
4429
diff
changeset
|
402 SDL_PumpEvents(); |
363604b42e84
Make sure events are current before flushing them.
Sam Lantinga <slouken@libsdl.org>
parents:
4429
diff
changeset
|
403 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
404 /* Lock the event queue */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
405 if (SDL_mutexP(SDL_EventQ.lock) == 0) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
406 int spot = SDL_EventQ.head; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
407 while (spot != SDL_EventQ.tail) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
408 Uint32 type = SDL_EventQ.event[spot].type; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
409 if (minType <= type && type <= maxType) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
410 spot = SDL_CutEvent(spot); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
411 } else { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
412 spot = (spot + 1) % MAXEVENTS; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
413 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
414 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
415 SDL_mutexV(SDL_EventQ.lock); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
416 } |
0 | 417 } |
418 | |
419 /* 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
|
420 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
|
421 SDL_PumpEvents(void) |
0 | 422 { |
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 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
|
424 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
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 /* 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
|
427 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
|
428 _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
|
429 } |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
430 #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
|
431 /* Check for joystick state change */ |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
432 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
|
433 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
|
434 } |
0 | 435 #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
|
436 } |
0 | 437 } |
438 | |
439 /* Public functions */ | |
440 | |
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
|
441 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
|
442 SDL_PollEvent(SDL_Event * event) |
0 | 443 { |
3072 | 444 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
|
445 } |
0 | 446 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
447 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
|
448 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
|
449 { |
3072 | 450 return SDL_WaitEventTimeout(event, -1); |
451 } | |
452 | |
453 int | |
454 SDL_WaitEventTimeout(SDL_Event * event, int timeout) | |
455 { | |
456 Uint32 expiration = 0; | |
457 | |
458 if (timeout > 0) | |
459 expiration = SDL_GetTicks() + timeout; | |
460 | |
461 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
|
462 SDL_PumpEvents(); |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 case 0: |
3072 | 469 if (timeout == 0) { |
470 /* Polling and no events, just return */ | |
471 return 0; | |
472 } | |
473 if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) { | |
474 /* Timeout expired and no events */ | |
475 return 0; | |
476 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
477 SDL_Delay(10); |
3072 | 478 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
|
479 } |
c121d94672cb
SDL 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 } |
0 | 481 } |
482 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
483 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
|
484 SDL_PushEvent(SDL_Event * event) |
0 | 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 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
|
487 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
|
488 } |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
489 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
|
490 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
|
491 } |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
492 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
493 SDL_GestureProcessEvent(event); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
494 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
4642
diff
changeset
|
495 |
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
|
496 return 1; |
0 | 497 } |
498 | |
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
|
499 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
|
500 SDL_SetEventFilter(SDL_EventFilter filter, void *userdata) |
0 | 501 { |
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
|
502 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
|
503 |
c121d94672cb
SDL 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 /* 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
|
505 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
|
506 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
|
507 while (SDL_PollEvent(&bitbucket) > 0); |
0 | 508 } |
509 | |
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
|
510 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
|
511 SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata) |
0 | 512 { |
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
|
513 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
|
514 *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
|
515 } |
c121d94672cb
SDL 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 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
|
517 *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
|
518 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
519 return SDL_EventOK ? SDL_TRUE : SDL_FALSE; |
0 | 520 } |
521 | |
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
|
522 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
|
523 SDL_FilterEvents(SDL_EventFilter filter, void *userdata) |
0 | 524 { |
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
|
525 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
|
526 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
|
527 |
c121d94672cb
SDL 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 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
|
529 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
|
530 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
|
531 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
|
532 } 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
|
533 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
|
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 } |
c121d94672cb
SDL 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 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
|
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 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
540 Uint8 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
541 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
|
542 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
543 Uint8 current_state; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
544 Uint8 hi = ((type >> 8) & 0xff); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
545 Uint8 lo = (type & 0xff); |
0 | 546 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
547 if (SDL_disabled_events[hi] && |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
548 (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
|
549 current_state = SDL_DISABLE; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
550 } else { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
551 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
|
552 } |
0 | 553 |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
554 if (state != current_state) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
555 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
556 switch (state) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
557 case SDL_DISABLE: |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
558 /* 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
|
559 if (!SDL_disabled_events[hi]) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
560 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
|
561 if (!SDL_disabled_events[hi]) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
562 /* Out of memory, nothing we can do... */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
563 break; |
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 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
566 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
|
567 SDL_FlushEvent(type); |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
568 break; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
569 case SDL_ENABLE: |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
570 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
|
571 break; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
572 default: |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
573 /* Querying state... */ |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
574 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
|
575 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
576 } |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
577 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
578 return current_state; |
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 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
581 Uint32 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
582 SDL_RegisterEvents(int numevents) |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
583 { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
584 Uint32 event_base; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
585 |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
586 if (SDL_userevents+numevents <= SDL_LASTEVENT) { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
587 event_base = SDL_userevents; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
588 SDL_userevents += numevents; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
589 } else { |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
590 event_base = (Uint32)-1; |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
591 } |
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
592 return event_base; |
0 | 593 } |
594 | |
595 /* This is a generic event handler. | |
596 */ | |
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
|
597 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
|
598 SDL_SendSysWMEvent(SDL_SysWMmsg * message) |
0 | 599 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
600 int posted; |
0 | 601 |
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
|
602 posted = 0; |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 } |
c121d94672cb
SDL 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 /* 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
|
611 return (posted); |
0 | 612 } |
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
|
613 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1769
diff
changeset
|
614 /* vi: set ts=4 sw=4 expandtab: */ |