SDL
2.0
|
#include "../SDL_internal.h"
#include "SDL.h"
#include "SDL_events.h"
#include "SDL_thread.h"
#include "SDL_events_c.h"
#include "../timer/SDL_timer_c.h"
#include "../joystick/SDL_joystick_c.h"
#include "../video/SDL_sysvideo.h"
#include "SDL_syswm.h"
Go to the source code of this file.
Data Structures | |
struct | SDL_EventWatcher |
struct | SDL_DisabledEventBlock |
struct | SDL_EventEntry |
struct | SDL_SysWMEntry |
Macros | |
#define | SDL_PRIs64 "I64d" |
#define | SDL_MAX_QUEUED_EVENTS 65535 |
#define | uint unsigned int |
#define | SDL_EVENT_CASE(x) case x: SDL_strlcpy(name, #x, sizeof (name)); |
#define | SDL_WINDOWEVENT_CASE(x) case x: SDL_strlcpy(name2, #x, sizeof (name2)); break |
#define | PRINT_KEY_EVENT(event) |
#define | PRINT_MBUTTON_EVENT(event) |
#define | PRINT_JBUTTON_EVENT(event) |
#define | PRINT_JOYDEV_EVENT(event) SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which) |
#define | PRINT_CBUTTON_EVENT(event) |
#define | PRINT_CONTROLLERDEV_EVENT(event) SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which) |
#define | PRINT_FINGER_EVENT(event) |
#define | PRINT_DOLLAR_EVENT(event) |
#define | PRINT_DROP_EVENT(event) SDL_snprintf(details, sizeof (details), " (file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID) |
#define | PRINT_AUDIODEV_EVENT(event) SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false"); |
Variables | |
static SDL_mutex * | SDL_event_watchers_lock |
static SDL_EventWatcher | SDL_EventOK |
static SDL_EventWatcher * | SDL_event_watchers = NULL |
static int | SDL_event_watchers_count = 0 |
static SDL_bool | SDL_event_watchers_dispatching = SDL_FALSE |
static SDL_bool | SDL_event_watchers_removed = SDL_FALSE |
static SDL_DisabledEventBlock * | SDL_disabled_events [256] |
static Uint32 | SDL_userevents = SDL_USEREVENT |
struct { | |
SDL_mutex * lock | |
SDL_atomic_t active | |
SDL_atomic_t count | |
int max_events_seen | |
SDL_EventEntry * head | |
SDL_EventEntry * tail | |
SDL_EventEntry * free | |
SDL_SysWMEntry * wmmsg_used | |
SDL_SysWMEntry * wmmsg_free | |
} | SDL_EventQ = { NULL, { 1 }, { 0 }, 0, NULL, NULL, NULL, NULL, NULL } |
static int | SDL_DoEventLogging = 0 |
#define PRINT_AUDIODEV_EVENT | ( | event | ) | SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false"); |
#define PRINT_CBUTTON_EVENT | ( | event | ) |
#define PRINT_CONTROLLERDEV_EVENT | ( | event | ) | SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which) |
#define PRINT_DOLLAR_EVENT | ( | event | ) |
#define PRINT_DROP_EVENT | ( | event | ) | SDL_snprintf(details, sizeof (details), " (file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID) |
#define PRINT_FINGER_EVENT | ( | event | ) |
#define PRINT_JBUTTON_EVENT | ( | event | ) |
#define PRINT_JOYDEV_EVENT | ( | event | ) | SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which) |
#define PRINT_KEY_EVENT | ( | event | ) |
#define PRINT_MBUTTON_EVENT | ( | event | ) |
#define SDL_EVENT_CASE | ( | x | ) | case x: SDL_strlcpy(name, #x, sizeof (name)); |
#define SDL_MAX_QUEUED_EVENTS 65535 |
Definition at line 45 of file SDL_events.c.
#define SDL_PRIs64 "I64d" |
Definition at line 39 of file SDL_events.c.
#define SDL_WINDOWEVENT_CASE | ( | x | ) | case x: SDL_strlcpy(name2, #x, sizeof (name2)); break |
#define uint unsigned int |
|
static |
Definition at line 463 of file SDL_events.c.
References SDL_EventEntry::event, SDL_EventEntry::msg, SDL_SysWMmsg::msg, SDL_SysWMEvent::msg, SDL_EventEntry::next, NULL, SDL_EventEntry::prev, SDL_assert, SDL_AtomicAdd, SDL_AtomicGet, SDL_DoEventLogging, SDL_EventQ, SDL_LogEvent(), SDL_malloc, SDL_MAX_QUEUED_EVENTS, SDL_SetError, SDL_SYSWMEVENT, and SDL_Event::syswm.
Referenced by SDL_PeepEvents().
void SDL_AddEventWatch | ( | SDL_EventFilter | filter, |
void * | userdata | ||
) |
Add a function which is called when an event is added to the queue.
Definition at line 841 of file SDL_events.c.
References SDL_EventWatcher::callback, SDL_EventWatcher::removed, SDL_event_watchers, SDL_event_watchers_count, SDL_event_watchers_lock, SDL_FALSE, SDL_LockMutex, SDL_realloc, SDL_UnlockMutex, and SDL_EventWatcher::userdata.
|
static |
Definition at line 517 of file SDL_events.c.
References SDL_EventEntry::next, NULL, SDL_EventEntry::prev, SDL_assert, SDL_AtomicAdd, SDL_AtomicGet, and SDL_EventQ.
Referenced by SDL_FilterEvents(), SDL_FlushEvents(), and SDL_PeepEvents().
void SDL_DelEventWatch | ( | SDL_EventFilter | filter, |
void * | userdata | ||
) |
Remove an event watch function added with SDL_AddEventWatch()
Definition at line 865 of file SDL_events.c.
References callback(), i, SDL_EventWatcher::removed, SDL_event_watchers, SDL_event_watchers_count, SDL_event_watchers_dispatching, SDL_event_watchers_lock, SDL_event_watchers_removed, SDL_LockMutex, SDL_memmove, SDL_TRUE, and SDL_UnlockMutex.
|
static |
Definition at line 99 of file SDL_events.c.
References SDL_atoi, SDL_DoEventLogging, SDL_max, and SDL_min.
Referenced by SDL_EventsInit(), and SDL_EventsQuit().
int SDL_EventsInit | ( | void | ) |
Definition at line 1009 of file SDL_events.c.
References NULL, SDL_AddHintCallback, SDL_DelHintCallback, SDL_EventLoggingChanged(), SDL_HINT_EVENT_LOGGING, SDL_QuitInit(), and SDL_StartEventLoop().
Referenced by SDL_InitSubSystem().
Definition at line 1023 of file SDL_events.c.
References NULL, SDL_DelHintCallback, SDL_EventLoggingChanged(), SDL_HINT_EVENT_LOGGING, SDL_QuitQuit(), and SDL_StopEventLoop().
Referenced by SDL_QuitSubSystem().
This function allows you to set the state of processing certain events.
state
is set to SDL_IGNORE, that event will be automatically dropped from the event queue and will not be filtered.state
is set to SDL_ENABLE, that event will be processed normally.state
is set to SDL_QUERY, SDL_EventState() will return the current processing state of the specified event. Definition at line 909 of file SDL_events.c.
References SDL_DisabledEventBlock::bits, SDL_calloc, SDL_DISABLE, SDL_disabled_events, SDL_DROPFILE, SDL_DROPTEXT, SDL_ENABLE, SDL_FlushEvent(), SDL_ToggleDragAndDropSupport(), and state.
Referenced by SDL_StartEventLoop().
void SDL_FilterEvents | ( | SDL_EventFilter | filter, |
void * | userdata | ||
) |
Run the filter function on the current event queue, removing any events for which the filter returns 0.
Definition at line 892 of file SDL_events.c.
References SDL_EventEntry::event, SDL_EventEntry::next, SDL_CutEvent(), SDL_EventQ, SDL_LockMutex, and SDL_UnlockMutex.
This function clears events from the event queue This function only affects currently queued events. If you want to make sure that all pending OS events are flushed, you can call SDL_PumpEvents() on the main thread immediately before the flush call.
Definition at line 633 of file SDL_events.c.
References SDL_FlushEvents().
Referenced by SDL_EventState().
Definition at line 639 of file SDL_events.c.
References SDL_EventEntry::event, SDL_EventEntry::next, SDL_AtomicGet, SDL_CutEvent(), SDL_EventQ, SDL_LockMutex, SDL_PumpEvents(), SDL_UnlockMutex, and SDL_Event::type.
Referenced by SDL_FlushEvent(), and SDL_SetEventFilter().
SDL_bool SDL_GetEventFilter | ( | SDL_EventFilter * | filter, |
void ** | userdata | ||
) |
Return the current event filter - can be used to "chain" filters. If there is no event filter set, this function returns SDL_FALSE.
Definition at line 817 of file SDL_events.c.
References SDL_EventWatcher::callback, SDL_event_watchers_lock, SDL_EventOK, SDL_FALSE, SDL_LockMutex, SDL_TRUE, SDL_UnlockMutex, SDL_zero, and SDL_EventWatcher::userdata.
Checks to see if certain event types are in the event queue.
Definition at line 621 of file SDL_events.c.
References NULL, SDL_PEEKEVENT, and SDL_PeepEvents().
Definition at line 627 of file SDL_events.c.
References NULL, SDL_PEEKEVENT, and SDL_PeepEvents().
Definition at line 105 of file SDL_events.c.
References PRINT_AUDIODEV_EVENT, PRINT_CBUTTON_EVENT, PRINT_CONTROLLERDEV_EVENT, PRINT_DOLLAR_EVENT, PRINT_DROP_EVENT, PRINT_FINGER_EVENT, PRINT_JBUTTON_EVENT, PRINT_JOYDEV_EVENT, PRINT_KEY_EVENT, PRINT_MBUTTON_EVENT, SDL_APP_DIDENTERBACKGROUND, SDL_APP_DIDENTERFOREGROUND, SDL_APP_LOWMEMORY, SDL_APP_TERMINATING, SDL_APP_WILLENTERBACKGROUND, SDL_APP_WILLENTERFOREGROUND, SDL_AUDIODEVICEADDED, SDL_AUDIODEVICEREMOVED, SDL_CLIPBOARDUPDATE, SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMAPPED, SDL_CONTROLLERDEVICEREMOVED, SDL_DoEventLogging, SDL_DOLLARGESTURE, SDL_DOLLARRECORD, SDL_DROPBEGIN, SDL_DROPCOMPLETE, SDL_DROPFILE, SDL_DROPTEXT, SDL_EVENT_CASE, SDL_FINGERDOWN, SDL_FINGERMOTION, SDL_FINGERUP, SDL_FIRSTEVENT, SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED, SDL_JOYHATMOTION, SDL_KEYDOWN, SDL_KEYMAPCHANGED, SDL_KEYUP, SDL_LASTEVENT, SDL_Log, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEMOTION, SDL_MOUSEWHEEL, SDL_MOUSEWHEEL_NORMAL, SDL_MULTIGESTURE, SDL_PRIs64, SDL_QUIT, SDL_RENDER_DEVICE_RESET, SDL_RENDER_TARGETS_RESET, SDL_snprintf, SDL_strlcpy, SDL_SYSWMEVENT, SDL_TEXTEDITING, SDL_TEXTINPUT, SDL_USEREVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT_CASE, SDL_WINDOWEVENT_CLOSE, SDL_WINDOWEVENT_ENTER, SDL_WINDOWEVENT_EXPOSED, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_HIT_TEST, SDL_WINDOWEVENT_LEAVE, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_NONE, SDL_WINDOWEVENT_RESIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_SHOWN, SDL_WINDOWEVENT_SIZE_CHANGED, SDL_WINDOWEVENT_TAKE_FOCUS, and uint.
Referenced by SDL_AddEvent().
int SDL_PeepEvents | ( | SDL_Event * | events, |
int | numevents, | ||
SDL_eventaction | action, | ||
Uint32 | minType, | ||
Uint32 | maxType | ||
) |
Checks the event queue for messages and optionally returns them.
If action
is SDL_ADDEVENT, up to numevents
events will be added to the back of the event queue.
If action
is SDL_PEEKEVENT, up to numevents
events at the front of the event queue, within the specified minimum and maximum type, will be returned and will not be removed from the queue.
If action
is SDL_GETEVENT, up to numevents
events at the front of the event queue, within the specified minimum and maximum type, will be returned and will be removed from the queue.
This function is thread-safe.
Definition at line 543 of file SDL_events.c.
References action, SDL_EventEntry::event, events, i, SDL_SysWMEntry::msg, SDL_SysWMEvent::msg, SDL_EventEntry::next, SDL_SysWMEntry::next, NULL, SDL_AddEvent(), SDL_ADDEVENT, SDL_AtomicGet, SDL_CutEvent(), SDL_EventQ, SDL_GETEVENT, SDL_LockMutex, SDL_malloc, SDL_SetError, SDL_SYSWMEVENT, SDL_UnlockMutex, SDL_Event::syswm, and SDL_Event::type.
Referenced by SDL_HasEvent(), SDL_HasEvents(), SDL_PushEvent(), and SDL_WaitEventTimeout().
int SDL_PollEvent | ( | SDL_Event * | event | ) |
Polls for currently pending events.
event | If not NULL, the next event is removed from the queue and stored in that area. |
Definition at line 705 of file SDL_events.c.
References SDL_WaitEventTimeout().
Pumps the event loop, gathering events from the input devices.
This function updates the event queue and internal input device state.
This should only be run in the thread that sets the video mode.
Definition at line 677 of file SDL_events.c.
References _this, SDL_VideoDevice::PumpEvents, SDL_disabled_events, SDL_GetVideoDevice(), SDL_JOYAXISMOTION, SDL_JoystickEventState, SDL_JoystickUpdate, SDL_QUERY, SDL_SendPendingSignalEvents(), SDL_SENSORUPDATE, and SDL_SensorUpdate.
Referenced by SDL_FlushEvents(), and SDL_WaitEventTimeout().
int SDL_PushEvent | ( | SDL_Event * | event | ) |
Add an event to the event queue.
Definition at line 748 of file SDL_events.c.
References SDL_EventWatcher::callback, i, SDL_ADDEVENT, SDL_event_watchers, SDL_event_watchers_count, SDL_event_watchers_dispatching, SDL_event_watchers_lock, SDL_event_watchers_removed, SDL_EventOK, SDL_FALSE, SDL_GestureProcessEvent(), SDL_GetTicks(), SDL_LockMutex, SDL_memmove, SDL_PeepEvents(), SDL_TRUE, SDL_UnlockMutex, and SDL_EventWatcher::userdata.
Referenced by SDL_SendAppEvent(), and SDL_SendSysWMEvent().
Uint32 SDL_RegisterEvents | ( | int | numevents | ) |
This function allocates a set of user-defined events, and returns the beginning event number for that set of events.
If there aren't enough user-defined events left, this function returns (Uint32)-1
Definition at line 958 of file SDL_events.c.
References SDL_LASTEVENT, and SDL_userevents.
int SDL_SendAppEvent | ( | SDL_EventType | eventType | ) |
Definition at line 972 of file SDL_events.c.
References SDL_ENABLE, SDL_GetEventState, and SDL_PushEvent().
Referenced by SDL_OnApplicationDidBecomeActive(), SDL_OnApplicationDidEnterBackground(), SDL_OnApplicationDidReceiveMemoryWarning(), SDL_OnApplicationWillEnterForeground(), SDL_OnApplicationWillResignActive(), SDL_OnApplicationWillTerminate(), SDL_SendKeymapChangedEvent(), and SDL_SendQuit().
int SDL_SendKeymapChangedEvent | ( | void | ) |
Definition at line 1003 of file SDL_events.c.
References SDL_KEYMAPCHANGED, and SDL_SendAppEvent().
int SDL_SendSysWMEvent | ( | SDL_SysWMmsg * | message | ) |
Definition at line 986 of file SDL_events.c.
References SDL_ENABLE, SDL_GetEventState, SDL_memset, SDL_PushEvent(), and SDL_SYSWMEVENT.
void SDL_SetEventFilter | ( | SDL_EventFilter | filter, |
void * | userdata | ||
) |
Sets up a filter to process all events before they change internal state and are posted to the internal event queue.
The filter is prototyped as:
If the filter returns 1, then the event will be added to the internal queue. If it returns 0, then the event will be dropped from the queue, but the internal state will still be updated. This allows selective filtering of dynamically arriving events.
There is one caveat when dealing with the SDL_QuitEvent event type. The event filter is only called when the window manager desires to close the application window. If the event filter returns 1, then the window will be closed, otherwise the window will remain open if possible.
If the quit event is generated by an interrupt signal, it will bypass the internal queue and be delivered to the application at the next event poll.
Definition at line 802 of file SDL_events.c.
References SDL_EventWatcher::callback, SDL_event_watchers_lock, SDL_EventOK, SDL_FIRSTEVENT, SDL_FlushEvents(), SDL_LASTEVENT, SDL_LockMutex, SDL_UnlockMutex, and SDL_EventWatcher::userdata.
int SDL_StartEventLoop | ( | void | ) |
Definition at line 421 of file SDL_events.c.
References NULL, SDL_AtomicSet, SDL_CreateMutex, SDL_DISABLE, SDL_DROPFILE, SDL_DROPTEXT, SDL_event_watchers_lock, SDL_EventQ, SDL_EventState(), SDL_SYSWMEVENT, SDL_TEXTEDITING, and SDL_TEXTINPUT.
Referenced by SDL_EventsInit().
Definition at line 347 of file SDL_events.c.
References i, SDL_EventEntry::next, SDL_SysWMEntry::next, NULL, SDL_arraysize, SDL_atoi, SDL_AtomicSet, SDL_DestroyMutex, SDL_disabled_events, SDL_event_watchers, SDL_event_watchers_count, SDL_event_watchers_lock, SDL_EventOK, SDL_EventQ, SDL_free, SDL_GetHint, SDL_LockMutex, SDL_Log, SDL_UnlockMutex, and SDL_zero.
Referenced by SDL_EventsQuit().
int SDL_WaitEvent | ( | SDL_Event * | event | ) |
Waits indefinitely for the next available event.
event | If not NULL, the next event is removed from the queue and stored in that area. |
Definition at line 711 of file SDL_events.c.
References SDL_WaitEventTimeout().
int SDL_WaitEventTimeout | ( | SDL_Event * | event, |
int | timeout | ||
) |
Waits until the specified timeout (in milliseconds) for the next available event.
event | If not NULL, the next event is removed from the queue and stored in that area. |
timeout | The timeout (in milliseconds) to wait for next event. |
Definition at line 717 of file SDL_events.c.
References SDL_Delay, SDL_FIRSTEVENT, SDL_GETEVENT, SDL_GetTicks(), SDL_LASTEVENT, SDL_PeepEvents(), SDL_PumpEvents(), and SDL_TICKS_PASSED.
Referenced by SDL_PollEvent(), and SDL_WaitEvent().
SDL_atomic_t active |
Definition at line 84 of file SDL_events.c.
Referenced by SDL_BWin::WindowActivated().
Definition at line 85 of file SDL_events.c.
SDL_EventEntry* free |
Definition at line 89 of file SDL_events.c.
Referenced by decode_edid(), SDL_BWin::DirectConnected(), glGetConfig(), SDL_PromptAssertion(), and SDL_BWin::~ SDL_BWin().
SDL_EventEntry* head |
Definition at line 87 of file SDL_events.c.
Referenced by mmap_alloc().
SDL_mutex* lock |
Definition at line 83 of file SDL_events.c.
Referenced by RunBasicTest(), SDL_AtomicLock(), SDL_AtomicTryLock(), SDL_AtomicUnlock(), SDL_InitDynamicAPI(), SDL_SYS_GetTLSData(), and SDL_ThreadID().
int max_events_seen |
Definition at line 86 of file SDL_events.c.
|
static |
Definition at line 63 of file SDL_events.c.
Referenced by SDL_EventState(), SDL_PumpEvents(), and SDL_StopEventLoop().
|
static |
Definition at line 96 of file SDL_events.c.
Referenced by SDL_AddEvent(), SDL_EventLoggingChanged(), and SDL_LogEvent().
|
static |
Definition at line 54 of file SDL_events.c.
Referenced by SDL_AddEventWatch(), SDL_DelEventWatch(), SDL_PushEvent(), and SDL_StopEventLoop().
|
static |
Definition at line 55 of file SDL_events.c.
Referenced by SDL_AddEventWatch(), SDL_DelEventWatch(), SDL_PushEvent(), and SDL_StopEventLoop().
Definition at line 56 of file SDL_events.c.
Referenced by SDL_DelEventWatch(), and SDL_PushEvent().
|
static |
Definition at line 52 of file SDL_events.c.
Referenced by SDL_AddEventWatch(), SDL_DelEventWatch(), SDL_GetEventFilter(), SDL_PushEvent(), SDL_SetEventFilter(), SDL_StartEventLoop(), and SDL_StopEventLoop().
Definition at line 57 of file SDL_events.c.
Referenced by SDL_DelEventWatch(), and SDL_PushEvent().
|
static |
Definition at line 53 of file SDL_events.c.
Referenced by SDL_GetEventFilter(), SDL_PushEvent(), SDL_SetEventFilter(), and SDL_StopEventLoop().
struct { ... } SDL_EventQ |
Referenced by SDL_AddEvent(), SDL_CutEvent(), SDL_FilterEvents(), SDL_FlushEvents(), SDL_PeepEvents(), SDL_StartEventLoop(), and SDL_StopEventLoop().
|
static |
Definition at line 64 of file SDL_events.c.
Referenced by SDL_RegisterEvents().
SDL_EventEntry* tail |
Definition at line 88 of file SDL_events.c.
SDL_SysWMEntry* wmmsg_free |
Definition at line 91 of file SDL_events.c.
SDL_SysWMEntry* wmmsg_used |
Definition at line 90 of file SDL_events.c.