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
62 typedef struct _SDL_EventEntry
66 struct _SDL_EventEntry *
prev;
67 struct _SDL_EventEntry *
next;
70 typedef struct _SDL_SysWMEntry
73 struct _SDL_SysWMEntry *
next;
90 #ifdef SDL_DEBUG_EVENTS
93 #define uint unsigned int
99 printf(
"SDL EVENT: ");
102 printf(
"SDL_USEREVENT");
106 printf(
" (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
112 switch (event->
type) {
113 #define SDL_EVENT_CASE(x) case x: printf("%s", #x);
114 SDL_EVENT_CASE(
SDL_FIRSTEVENT) printf("(THIS IS PROBABLY A BUG!)"); break;
115 SDL_EVENT_CASE(
SDL_QUIT) printf("(timestamp=%u)", (uint) event->
quit.timestamp); break;
126 #undef SDL_EVENT_CASE
128 #define SDL_EVENT_CASE(x) case x: printf("%s ", #x);
131 printf("(timestamp=%u windowid=%u event=", (uint) event->
window.timestamp, (uint) event->
window.windowID);
132 switch(event->
window.event) {
134 #define SDL_WINDOWEVENT_CASE(x) case x: printf("%s", #x); break
151 #undef SDL_WINDOWEVENT_CASE
152 default: printf(
"UNKNOWN(bug? fixme?)");
break;
158 printf("(timestamp=%u)", (uint) event->syswm.timestamp);
162 #define PRINT_KEY_EVENT(event) \
163 printf("(timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
164 (uint) event->key.timestamp, (uint) event->key.windowID, \
165 event->key.state == SDL_PRESSED ? "pressed" : "released", \
166 event->key.repeat ? "true" : "false", \
167 (uint) event->key.keysym.scancode, \
168 (uint) event->key.keysym.sym, \
169 (uint) event->key.keysym.mod)
170 SDL_EVENT_CASE(
SDL_KEYDOWN) PRINT_KEY_EVENT(event); break;
171 SDL_EVENT_CASE(
SDL_KEYUP) PRINT_KEY_EVENT(event); break;
172 #undef PRINT_KEY_EVENT
176 (uint) event->edit.timestamp, (uint) event->edit.windowID,
181 printf("(timestamp=%u windowid=%u text='%
s')", (uint) event->text.timestamp, (uint) event->text.windowID, event->text.text);
186 printf("(timestamp=%u windowid=%u which=%u
state=%u
x=%d
y=%d xrel=%d yrel=%d)",
187 (uint) event->motion.timestamp, (uint) event->motion.windowID,
188 (uint) event->motion.which, (uint) event->motion.
state,
189 (
int) event->motion.
x, (
int) event->motion.
y,
190 (
int) event->motion.xrel, (
int) event->motion.yrel);
193 #define PRINT_MBUTTON_EVENT(event) \
194 printf("(timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
195 (uint) event->button.timestamp, (uint) event->button.windowID, \
196 (uint) event->button.which, (uint) event->button.button, \
197 event->button.state == SDL_PRESSED ? "pressed" : "released", \
198 (uint) event->button.clicks, (int) event->button.x, (int) event->button.y)
201 #undef PRINT_MBUTTON_EVENT
205 printf("(timestamp=%u windowid=%u which=%u x=%d y=%d direction=%s)",
206 (uint) event->wheel.timestamp, (uint) event->wheel.windowID,
207 (uint) event->wheel.which, (
int) event->wheel.x, (
int) event->wheel.y,
212 printf("(timestamp=%u which=%d
axis=%u
value=%d)",
213 (uint) event->jaxis.timestamp, (
int) event->jaxis.which,
214 (uint) event->jaxis.
axis, (
int) event->jaxis.
value);
218 printf("(timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
219 (uint) event->jball.timestamp, (
int) event->jball.which,
220 (uint) event->jball.ball, (
int) event->jball.xrel, (
int) event->jball.yrel);
224 printf("(timestamp=%u which=%d hat=%u value=%u)",
225 (uint) event->jhat.timestamp, (
int) event->jhat.which,
226 (uint) event->jhat.hat, (uint) event->jhat.value);
229 #define PRINT_JBUTTON_EVENT(event) \
230 printf("(timestamp=%u which=%d button=%u state=%s)", \
231 (uint) event->jbutton.timestamp, (int) event->jbutton.which, \
232 (uint) event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
235 #undef PRINT_JBUTTON_EVENT
237 #define PRINT_JOYDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which)
240 #undef PRINT_JOYDEV_EVENT
243 printf("(timestamp=%u which=%d axis=%u value=%d)",
244 (uint) event->caxis.timestamp, (
int) event->caxis.which,
245 (uint) event->caxis.axis, (
int) event->caxis.value);
248 #define PRINT_CBUTTON_EVENT(event) \
249 printf("(timestamp=%u which=%d button=%u state=%s)", \
250 (uint) event->cbutton.timestamp, (int) event->cbutton.which, \
251 (uint) event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
254 #undef PRINT_CBUTTON_EVENT
256 #define PRINT_CONTROLLERDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which)
260 #undef PRINT_CONTROLLERDEV_EVENT
262 #define PRINT_FINGER_EVENT(event) \
263 printf("(timestamp=%u touchid=%lld fingerid=%lld x=%f y=%f dx=%f dy=%f pressure=%f)", \
264 (uint) event->tfinger.timestamp, (long long) event->tfinger.touchId, \
265 (long long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, \
266 event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
268 SDL_EVENT_CASE(
SDL_FINGERUP) PRINT_FINGER_EVENT(event); break;
270 #undef PRINT_FINGER_EVENT
272 #define PRINT_DOLLAR_EVENT(event) \
273 printf("(timestamp=%u touchid=%lld gestureid=%lld numfingers=%u error=%f x=%f y=%f)", \
274 (uint) event->dgesture.timestamp, (long long) event->dgesture.touchId, \
275 (long long) event->dgesture.gestureId, (uint) event->dgesture.numFingers, \
276 event->dgesture.error, event->dgesture.x, event->dgesture.y);
279 #undef PRINT_DOLLAR_EVENT
282 printf("(timestamp=%u touchid=%lld dtheta=%
f ddist=%
f x=%
f y=%
f numfingers=%u)",
283 (uint) event->mgesture.timestamp, (
long long) event->mgesture.touchId,
284 event->mgesture.dTheta, event->mgesture.dDist,
285 event->mgesture.x, event->mgesture.y, (uint) event->mgesture.numFingers);
288 #define PRINT_DROP_EVENT(event) printf("(file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID)
289 SDL_EVENT_CASE(
SDL_DROPFILE) PRINT_DROP_EVENT(event); break;
290 SDL_EVENT_CASE(
SDL_DROPTEXT) PRINT_DROP_EVENT(event); break;
291 SDL_EVENT_CASE(
SDL_DROPBEGIN) PRINT_DROP_EVENT(event); break;
293 #undef PRINT_DROP_EVENT
295 #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");
298 #undef PRINT_AUDIODEV_EVENT
300 #undef SDL_EVENT_CASE
303 printf(
"UNKNOWN SDL EVENT #%u! (Bug? FIXME?)", (uint) event->type);
319 const char *report =
SDL_GetHint(
"SDL_EVENT_QUEUE_STATISTICS");
331 SDL_Log(
"SDL EVENT QUEUE: Maximum events in-flight: %d\n",
346 for (wmmsg =
SDL_EventQ.wmmsg_used; wmmsg; ) {
351 for (wmmsg =
SDL_EventQ.wmmsg_free; wmmsg; ) {
368 SDL_disabled_events[
i] =
NULL;
371 if (SDL_event_watchers_lock) {
373 SDL_event_watchers_lock =
NULL;
375 if (SDL_event_watchers) {
377 SDL_event_watchers =
NULL;
400 #if !SDL_THREADS_DISABLED
408 if (!SDL_event_watchers_lock) {
410 if (SDL_event_watchers_lock ==
NULL) {
440 SDL_SetError(
"Event queue is full (%d events)", initial_count);
454 #ifdef SDL_DEBUG_EVENTS
455 SDL_DebugPrintEvent(event);
460 entry->
msg = *
event->syswm.
msg;
478 if (final_count >
SDL_EventQ.max_events_seen) {
530 for (i = 0; i < numevents; ++
i) {
542 for (wmmsg =
SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
543 wmmsg_next = wmmsg->
next;
550 for (entry =
SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
553 if (minType <= type && type <= maxType) {
555 events[used] = entry->
event;
632 for (entry =
SDL_EventQ.head; entry; entry = next) {
635 if (minType <= type && type <= maxType) {
655 #if !SDL_JOYSTICK_DISABLED
662 #if !SDL_SENSOR_DISABLED
723 if (!SDL_event_watchers_lock ||
SDL_LockMutex(SDL_event_watchers_lock) == 0) {
725 if (SDL_event_watchers_lock) {
736 for (i = 0; i < event_watchers_count; ++
i) {
737 if (!SDL_event_watchers[i].removed) {
738 SDL_event_watchers[
i].
callback(SDL_event_watchers[i].userdata, event);
745 if (SDL_event_watchers[i].removed) {
756 if (SDL_event_watchers_lock) {
774 if (!SDL_event_watchers_lock ||
SDL_LockMutex(SDL_event_watchers_lock) == 0) {
780 if (SDL_event_watchers_lock) {
791 if (!SDL_event_watchers_lock ||
SDL_LockMutex(SDL_event_watchers_lock) == 0) {
794 if (SDL_event_watchers_lock) {
813 if (!SDL_event_watchers_lock ||
SDL_LockMutex(SDL_event_watchers_lock) == 0) {
817 if (event_watchers) {
820 SDL_event_watchers = event_watchers;
828 if (SDL_event_watchers_lock) {
837 if (!SDL_event_watchers_lock ||
SDL_LockMutex(SDL_event_watchers_lock) == 0) {
841 if (SDL_event_watchers[i].
callback == filter && SDL_event_watchers[i].userdata == userdata) {
847 if (i < SDL_event_watchers_count) {
848 SDL_memmove(&SDL_event_watchers[i], &SDL_event_watchers[i+1], (SDL_event_watchers_count - i) *
sizeof(SDL_event_watchers[i]));
855 if (SDL_event_watchers_lock) {
866 for (entry =
SDL_EventQ.head; entry; entry = next) {
884 Uint8 hi = ((type >> 8) & 0xff);
885 Uint8 lo = (type & 0xff);
887 if (SDL_disabled_events[hi] &&
888 (SDL_disabled_events[hi]->
bits[lo/32] & (1 << (lo&31)))) {
894 if (state != current_state)
899 if (!SDL_disabled_events[hi]) {
901 if (!SDL_disabled_events[hi]) {
906 SDL_disabled_events[hi]->
bits[lo/32] |= (1 << (lo&31));
910 SDL_disabled_events[hi]->
bits[lo/32] &= ~(1 << (lo&31));
924 return current_state;
949 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
static int SDL_event_watchers_count
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
static SDL_bool SDL_event_watchers_dispatching
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)
#define SDL_GetEventState(type)
static SDL_bool SDL_event_watchers_removed
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
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.
static Uint32 callback(Uint32 interval, void *param)
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)
void SDL_ToggleDragAndDropSupport(void)
#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]
static SDL_mutex * SDL_event_watchers_lock
SDL_SysWMEntry * wmmsg_free
#define SDL_JoystickEventState
GLuint GLuint GLsizei GLenum type
SDL_VideoDevice * SDL_GetVideoDevice(void)
static SDL_EventWatcher SDL_EventOK
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)