21 #include "../SDL_internal.h"
29 #include "../timer/SDL_timer_c.h"
30 #if !SDL_JOYSTICK_DISABLED
31 #include "../joystick/SDL_joystick_c.h"
33 #include "../video/SDL_sysvideo.h"
39 #define SDL_MAX_QUEUED_EVENTS 65535
61 typedef struct _SDL_EventEntry
65 struct _SDL_EventEntry *
prev;
66 struct _SDL_EventEntry *
next;
69 typedef struct _SDL_SysWMEntry
72 struct _SDL_SysWMEntry *
next;
89 #ifdef SDL_DEBUG_EVENTS
92 #define uint unsigned int
98 printf(
"SDL EVENT: ");
101 printf(
"SDL_USEREVENT");
105 printf(
" (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
111 switch (event->
type) {
112 #define SDL_EVENT_CASE(x) case x: printf("%s", #x);
113 SDL_EVENT_CASE(
SDL_FIRSTEVENT) printf("(THIS IS PROBABLY A BUG!)"); break;
114 SDL_EVENT_CASE(
SDL_QUIT) printf("(timestamp=%u)", (uint) event->
quit.timestamp); break;
125 #undef SDL_EVENT_CASE
127 #define SDL_EVENT_CASE(x) case x: printf("%s ", #x);
130 printf("(timestamp=%u windowid=%u event=", (uint) event->
window.timestamp, (uint) event->
window.windowID);
131 switch(event->
window.event) {
133 #define SDL_WINDOWEVENT_CASE(x) case x: printf("%s", #x); break
150 #undef SDL_WINDOWEVENT_CASE
151 default: printf(
"UNKNOWN(bug? fixme?)");
break;
157 printf("(timestamp=%u)", (uint) event->syswm.timestamp);
161 #define PRINT_KEY_EVENT(event) \
162 printf("(timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
163 (uint) event->key.timestamp, (uint) event->key.windowID, \
164 event->key.state == SDL_PRESSED ? "pressed" : "released", \
165 event->key.repeat ? "true" : "false", \
166 (uint) event->key.keysym.scancode, \
167 (uint) event->key.keysym.sym, \
168 (uint) event->key.keysym.mod)
169 SDL_EVENT_CASE(
SDL_KEYDOWN) PRINT_KEY_EVENT(event); break;
170 SDL_EVENT_CASE(
SDL_KEYUP) PRINT_KEY_EVENT(event); break;
171 #undef PRINT_KEY_EVENT
175 (uint) event->edit.timestamp, (uint) event->edit.windowID,
180 printf("(timestamp=%u windowid=%u text='%
s')", (uint) event->text.timestamp, (uint) event->text.windowID, event->text.text);
185 printf("(timestamp=%u windowid=%u which=%u
state=%u
x=%d
y=%d xrel=%d yrel=%d)",
186 (uint) event->motion.timestamp, (uint) event->motion.windowID,
187 (uint) event->motion.which, (uint) event->motion.
state,
188 (
int) event->motion.
x, (
int) event->motion.
y,
189 (
int) event->motion.xrel, (
int) event->motion.yrel);
192 #define PRINT_MBUTTON_EVENT(event) \
193 printf("(timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
194 (uint) event->button.timestamp, (uint) event->button.windowID, \
195 (uint) event->button.which, (uint) event->button.button, \
196 event->button.state == SDL_PRESSED ? "pressed" : "released", \
197 (uint) event->button.clicks, (int) event->button.x, (int) event->button.y)
200 #undef PRINT_MBUTTON_EVENT
204 printf("(timestamp=%u windowid=%u which=%u x=%d y=%d direction=%s)",
205 (uint) event->wheel.timestamp, (uint) event->wheel.windowID,
206 (uint) event->wheel.which, (
int) event->wheel.x, (
int) event->wheel.y,
211 printf("(timestamp=%u which=%d
axis=%u
value=%d)",
212 (uint) event->jaxis.timestamp, (
int) event->jaxis.which,
213 (uint) event->jaxis.
axis, (
int) event->jaxis.
value);
217 printf("(timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
218 (uint) event->jball.timestamp, (
int) event->jball.which,
219 (uint) event->jball.ball, (
int) event->jball.xrel, (
int) event->jball.yrel);
223 printf("(timestamp=%u which=%d hat=%u value=%u)",
224 (uint) event->jhat.timestamp, (
int) event->jhat.which,
225 (uint) event->jhat.hat, (uint) event->jhat.value);
228 #define PRINT_JBUTTON_EVENT(event) \
229 printf("(timestamp=%u which=%d button=%u state=%s)", \
230 (uint) event->jbutton.timestamp, (int) event->jbutton.which, \
231 (uint) event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
234 #undef PRINT_JBUTTON_EVENT
236 #define PRINT_JOYDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which)
239 #undef PRINT_JOYDEV_EVENT
242 printf("(timestamp=%u which=%d axis=%u value=%d)",
243 (uint) event->caxis.timestamp, (
int) event->caxis.which,
244 (uint) event->caxis.axis, (
int) event->caxis.value);
247 #define PRINT_CBUTTON_EVENT(event) \
248 printf("(timestamp=%u which=%d button=%u state=%s)", \
249 (uint) event->cbutton.timestamp, (int) event->cbutton.which, \
250 (uint) event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
253 #undef PRINT_CBUTTON_EVENT
255 #define PRINT_CONTROLLERDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which)
259 #undef PRINT_CONTROLLERDEV_EVENT
261 #define PRINT_FINGER_EVENT(event) \
262 printf("(timestamp=%u touchid=%lld fingerid=%lld x=%f y=%f dx=%f dy=%f pressure=%f)", \
263 (uint) event->tfinger.timestamp, (long long) event->tfinger.touchId, \
264 (long long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, \
265 event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
267 SDL_EVENT_CASE(
SDL_FINGERUP) PRINT_FINGER_EVENT(event); break;
269 #undef PRINT_FINGER_EVENT
271 #define PRINT_DOLLAR_EVENT(event) \
272 printf("(timestamp=%u touchid=%lld gestureid=%lld numfingers=%u error=%f x=%f y=%f)", \
273 (uint) event->dgesture.timestamp, (long long) event->dgesture.touchId, \
274 (long long) event->dgesture.gestureId, (uint) event->dgesture.numFingers, \
275 event->dgesture.error, event->dgesture.x, event->dgesture.y);
278 #undef PRINT_DOLLAR_EVENT
281 printf("(timestamp=%u touchid=%lld dtheta=%
f ddist=%
f x=%
f y=%
f numfingers=%u)",
282 (uint) event->mgesture.timestamp, (
long long) event->mgesture.touchId,
283 event->mgesture.dTheta, event->mgesture.dDist,
284 event->mgesture.x, event->mgesture.y, (uint) event->mgesture.numFingers);
287 #define PRINT_DROP_EVENT(event) printf("(file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID)
288 SDL_EVENT_CASE(
SDL_DROPFILE) PRINT_DROP_EVENT(event); break;
289 SDL_EVENT_CASE(
SDL_DROPTEXT) PRINT_DROP_EVENT(event); break;
290 SDL_EVENT_CASE(
SDL_DROPBEGIN) PRINT_DROP_EVENT(event); break;
292 #undef PRINT_DROP_EVENT
294 #define PRINT_AUDIODEV_EVENT(event) printf("(timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false");
297 #undef PRINT_AUDIODEV_EVENT
299 #undef SDL_EVENT_CASE
302 printf(
"UNKNOWN SDL EVENT #%u! (Bug? FIXME?)", (uint) event->type);
318 const char *report =
SDL_GetHint(
"SDL_EVENT_QUEUE_STATISTICS");
330 SDL_Log(
"SDL EVENT QUEUE: Maximum events in-flight: %d\n",
345 for (wmmsg =
SDL_EventQ.wmmsg_used; wmmsg; ) {
350 for (wmmsg =
SDL_EventQ.wmmsg_free; wmmsg; ) {
367 SDL_disabled_events[
i] =
NULL;
370 while (SDL_event_watchers) {
372 SDL_event_watchers = tmp->
next;
395 #if !SDL_THREADS_DISABLED
424 SDL_SetError(
"Event queue is full (%d events)", initial_count);
438 #ifdef SDL_DEBUG_EVENTS
439 SDL_DebugPrintEvent(event);
444 entry->
msg = *
event->syswm.
msg;
462 if (final_count >
SDL_EventQ.max_events_seen) {
514 for (i = 0; i < numevents; ++
i) {
526 for (wmmsg =
SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
527 wmmsg_next = wmmsg->
next;
534 for (entry =
SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
537 if (minType <= type && type <= maxType) {
539 events[used] = entry->
event;
612 for (entry =
SDL_EventQ.head; entry; entry = next) {
615 if (minType <= type && type <= maxType) {
633 #if !SDL_JOYSTICK_DISABLED
699 for (curr = SDL_event_watchers; curr; curr = curr->
next) {
752 if (SDL_event_watchers) {
753 for (tail = SDL_event_watchers; tail->
next; tail = tail->
next) {
756 tail->
next = watcher;
758 SDL_event_watchers = watcher;
769 for (curr = SDL_event_watchers; curr; prev = curr, curr = curr->
next) {
770 if (curr->callback == filter && curr->userdata == userdata) {
774 SDL_event_watchers = curr->
next;
787 for (entry =
SDL_EventQ.head; entry; entry = next) {
801 Uint8 hi = ((type >> 8) & 0xff);
802 Uint8 lo = (type & 0xff);
804 if (SDL_disabled_events[hi] &&
805 (SDL_disabled_events[hi]->
bits[lo/32] & (1 << (lo&31)))) {
811 if (state != current_state)
816 if (!SDL_disabled_events[hi]) {
818 if (!SDL_disabled_events[hi]) {
823 SDL_disabled_events[hi]->
bits[lo/32] |= (1 << (lo&31));
827 SDL_disabled_events[hi]->
bits[lo/32] &= ~(1 << (lo&31));
835 return current_state;
860 event.type = eventType;
SDL_SysWMEntry * wmmsg_used
int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, Uint32 minType, Uint32 maxType)
int SDL_WaitEventTimeout(SDL_Event *event, int timeout)
Waits until the specified timeout (in milliseconds) for the next available event. ...
int(* SDL_EventFilter)(void *userdata, SDL_Event *event)
SDL_bool SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata)
struct _SDL_EventEntry * next
static SDL_EventWatcher * SDL_event_watchers
void SDL_PumpEvents(void)
GLint GLint GLint GLint GLint x
GLuint GLsizei const GLchar * message
SDL_bool SDL_HasEvent(Uint32 type)
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
static int SDL_AddEvent(SDL_Event *event)
static SDL_Event events[EVENT_BUF_SIZE]
int SDL_StartEventLoop(void)
#define SDL_MAX_QUEUED_EVENTS
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
union SDL_SysWMmsg::@16 msg
SDL_bool SDL_HasEvents(Uint32 minType, Uint32 maxType)
int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
static SDL_VideoDevice * _this
struct _SDL_SysWMEntry * next
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void SDL_GestureProcessEvent(SDL_Event *event)
void SDL_FlushEvents(Uint32 minType, Uint32 maxType)
void * SDL_calloc(size_t nmemb, size_t size)
#define SDL_GetEventState(type)
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
struct SDL_EventWatcher * next
SDL_EventFilter SDL_EventOK
static struct @20 SDL_EventQ
GLsizei const GLfloat * value
SDL_EventType
The types of events that can be delivered.
void SDL_FlushEvent(Uint32 type)
int SDL_PushEvent(SDL_Event *event)
Add an event to the event queue.
void SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
GLint GLint GLint GLint GLint GLint y
void(* PumpEvents)(_THIS)
static void SDL_CutEvent(SDL_EventEntry *entry)
Uint8 SDL_EventState(Uint32 type, int state)
#define SDL_assert(condition)
#define SDL_JoystickUpdate
static char text[MAX_TEXT_LENGTH]
int SDL_SendKeymapChangedEvent(void)
void SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
struct _SDL_EventEntry * prev
EGLSurface EGLNativeWindowType * window
GLbitfield GLuint64 timeout
static Uint32 SDL_userevents
static SDL_DisabledEventBlock * SDL_disabled_events[256]
SDL_SysWMEntry * wmmsg_free
#define SDL_JoystickEventState
GLuint GLuint GLsizei GLenum type
SDL_VideoDevice * SDL_GetVideoDevice(void)
void SDL_SendPendingQuit(void)
#define SDL_arraysize(array)
int SDL_PollEvent(SDL_Event *event)
Polls for currently pending events.
int SDL_SendAppEvent(SDL_EventType eventType)
void SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
int SDL_WaitEvent(SDL_Event *event)
Waits indefinitely for the next available event.
GLuint GLsizei GLsizei * length
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
void SDL_StopEventLoop(void)
Uint32 SDL_RegisterEvents(int numevents)