SDL  2.0
SDL_events.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /**
23  * \file SDL_events.h
24  *
25  * Include file for SDL event handling.
26  */
27 
28 #ifndef SDL_events_h_
29 #define SDL_events_h_
30 
31 #include "SDL_stdinc.h"
32 #include "SDL_error.h"
33 #include "SDL_video.h"
34 #include "SDL_keyboard.h"
35 #include "SDL_mouse.h"
36 #include "SDL_joystick.h"
37 #include "SDL_gamecontroller.h"
38 #include "SDL_quit.h"
39 #include "SDL_gesture.h"
40 #include "SDL_touch.h"
41 
42 #include "begin_code.h"
43 /* Set up for C function definitions, even when using C++ */
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /* General keyboard/mouse state definitions */
49 #define SDL_RELEASED 0
50 #define SDL_PRESSED 1
51 
52 /**
53  * \brief The types of events that can be delivered.
54  */
55 typedef enum
56 {
57  SDL_FIRSTEVENT = 0, /**< Unused (do not remove) */
58 
59  /* Application events */
60  SDL_QUIT = 0x100, /**< User-requested quit */
61 
62  /* These application events have special meaning on iOS, see README-ios.md for details */
63  SDL_APP_TERMINATING, /**< The application is being terminated by the OS
64  Called on iOS in applicationWillTerminate()
65  Called on Android in onDestroy()
66  */
67  SDL_APP_LOWMEMORY, /**< The application is low on memory, free memory if possible.
68  Called on iOS in applicationDidReceiveMemoryWarning()
69  Called on Android in onLowMemory()
70  */
71  SDL_APP_WILLENTERBACKGROUND, /**< The application is about to enter the background
72  Called on iOS in applicationWillResignActive()
73  Called on Android in onPause()
74  */
75  SDL_APP_DIDENTERBACKGROUND, /**< The application did enter the background and may not get CPU for some time
76  Called on iOS in applicationDidEnterBackground()
77  Called on Android in onPause()
78  */
79  SDL_APP_WILLENTERFOREGROUND, /**< The application is about to enter the foreground
80  Called on iOS in applicationWillEnterForeground()
81  Called on Android in onResume()
82  */
83  SDL_APP_DIDENTERFOREGROUND, /**< The application is now interactive
84  Called on iOS in applicationDidBecomeActive()
85  Called on Android in onResume()
86  */
87 
88  SDL_LOCALECHANGED, /**< The user's locale preferences have changed. */
89 
90  /* Display events */
91  SDL_DISPLAYEVENT = 0x150, /**< Display state change */
92 
93  /* Window events */
94  SDL_WINDOWEVENT = 0x200, /**< Window state change */
95  SDL_SYSWMEVENT, /**< System specific event */
96 
97  /* Keyboard events */
98  SDL_KEYDOWN = 0x300, /**< Key pressed */
99  SDL_KEYUP, /**< Key released */
100  SDL_TEXTEDITING, /**< Keyboard text editing (composition) */
101  SDL_TEXTINPUT, /**< Keyboard text input */
102  SDL_KEYMAPCHANGED, /**< Keymap changed due to a system event such as an
103  input language or keyboard layout change.
104  */
105 
106  /* Mouse events */
107  SDL_MOUSEMOTION = 0x400, /**< Mouse moved */
108  SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
109  SDL_MOUSEBUTTONUP, /**< Mouse button released */
110  SDL_MOUSEWHEEL, /**< Mouse wheel motion */
111 
112  /* Joystick events */
113  SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */
114  SDL_JOYBALLMOTION, /**< Joystick trackball motion */
115  SDL_JOYHATMOTION, /**< Joystick hat position change */
116  SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
117  SDL_JOYBUTTONUP, /**< Joystick button released */
118  SDL_JOYDEVICEADDED, /**< A new joystick has been inserted into the system */
119  SDL_JOYDEVICEREMOVED, /**< An opened joystick has been removed */
120 
121  /* Game controller events */
122  SDL_CONTROLLERAXISMOTION = 0x650, /**< Game controller axis motion */
123  SDL_CONTROLLERBUTTONDOWN, /**< Game controller button pressed */
124  SDL_CONTROLLERBUTTONUP, /**< Game controller button released */
125  SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */
126  SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */
127  SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */
128  SDL_CONTROLLERTOUCHPADDOWN, /**< Game controller touchpad was touched */
129  SDL_CONTROLLERTOUCHPADMOTION, /**< Game controller touchpad finger was moved */
130  SDL_CONTROLLERTOUCHPADUP, /**< Game controller touchpad finger was lifted */
131  SDL_CONTROLLERSENSORUPDATE, /**< Game controller sensor was updated */
132 
133  /* Touch events */
134  SDL_FINGERDOWN = 0x700,
137 
138  /* Gesture events */
142 
143  /* Clipboard events */
144  SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
145 
146  /* Drag and drop events */
147  SDL_DROPFILE = 0x1000, /**< The system requests a file open */
148  SDL_DROPTEXT, /**< text/plain drag-and-drop event */
149  SDL_DROPBEGIN, /**< A new set of drops is beginning (NULL filename) */
150  SDL_DROPCOMPLETE, /**< Current set of drops is now complete (NULL filename) */
151 
152  /* Audio hotplug events */
153  SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */
154  SDL_AUDIODEVICEREMOVED, /**< An audio device has been removed. */
155 
156  /* Sensor events */
157  SDL_SENSORUPDATE = 0x1200, /**< A sensor was updated */
158 
159  /* Render events */
160  SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
161  SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
162 
163  /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
164  * and should be allocated with SDL_RegisterEvents()
165  */
166  SDL_USEREVENT = 0x8000,
167 
168  /**
169  * This last event is only for bounding internal arrays
170  */
171  SDL_LASTEVENT = 0xFFFF
173 
174 /**
175  * \brief Fields shared by every event
176  */
177 typedef struct SDL_CommonEvent
178 {
180  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
182 
183 /**
184  * \brief Display state change event data (event.display.*)
185  */
186 typedef struct SDL_DisplayEvent
187 {
188  Uint32 type; /**< ::SDL_DISPLAYEVENT */
189  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
190  Uint32 display; /**< The associated display index */
191  Uint8 event; /**< ::SDL_DisplayEventID */
195  Sint32 data1; /**< event dependent data */
197 
198 /**
199  * \brief Window state change event data (event.window.*)
200  */
201 typedef struct SDL_WindowEvent
202 {
203  Uint32 type; /**< ::SDL_WINDOWEVENT */
204  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
205  Uint32 windowID; /**< The associated window */
206  Uint8 event; /**< ::SDL_WindowEventID */
210  Sint32 data1; /**< event dependent data */
211  Sint32 data2; /**< event dependent data */
213 
214 /**
215  * \brief Keyboard button event structure (event.key.*)
216  */
217 typedef struct SDL_KeyboardEvent
218 {
219  Uint32 type; /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
220  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
221  Uint32 windowID; /**< The window with keyboard focus, if any */
222  Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
223  Uint8 repeat; /**< Non-zero if this is a key repeat */
226  SDL_Keysym keysym; /**< The key that was pressed or released */
228 
229 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
230 /**
231  * \brief Keyboard text editing event structure (event.edit.*)
232  */
233 typedef struct SDL_TextEditingEvent
234 {
235  Uint32 type; /**< ::SDL_TEXTEDITING */
236  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
237  Uint32 windowID; /**< The window with keyboard focus, if any */
238  char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */
239  Sint32 start; /**< The start cursor of selected editing text */
240  Sint32 length; /**< The length of selected editing text */
242 
243 
244 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
245 /**
246  * \brief Keyboard text input event structure (event.text.*)
247  */
248 typedef struct SDL_TextInputEvent
249 {
250  Uint32 type; /**< ::SDL_TEXTINPUT */
251  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
252  Uint32 windowID; /**< The window with keyboard focus, if any */
253  char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */
255 
256 /**
257  * \brief Mouse motion event structure (event.motion.*)
258  */
259 typedef struct SDL_MouseMotionEvent
260 {
261  Uint32 type; /**< ::SDL_MOUSEMOTION */
262  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
263  Uint32 windowID; /**< The window with mouse focus, if any */
264  Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
265  Uint32 state; /**< The current button state */
266  Sint32 x; /**< X coordinate, relative to window */
267  Sint32 y; /**< Y coordinate, relative to window */
268  Sint32 xrel; /**< The relative motion in the X direction */
269  Sint32 yrel; /**< The relative motion in the Y direction */
271 
272 /**
273  * \brief Mouse button event structure (event.button.*)
274  */
275 typedef struct SDL_MouseButtonEvent
276 {
277  Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
278  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
279  Uint32 windowID; /**< The window with mouse focus, if any */
280  Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
281  Uint8 button; /**< The mouse button index */
282  Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
283  Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
285  Sint32 x; /**< X coordinate, relative to window */
286  Sint32 y; /**< Y coordinate, relative to window */
288 
289 /**
290  * \brief Mouse wheel event structure (event.wheel.*)
291  */
292 typedef struct SDL_MouseWheelEvent
293 {
294  Uint32 type; /**< ::SDL_MOUSEWHEEL */
295  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
296  Uint32 windowID; /**< The window with mouse focus, if any */
297  Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
298  Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
299  Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
300  Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
302 
303 /**
304  * \brief Joystick axis motion event structure (event.jaxis.*)
305  */
306 typedef struct SDL_JoyAxisEvent
307 {
308  Uint32 type; /**< ::SDL_JOYAXISMOTION */
309  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
310  SDL_JoystickID which; /**< The joystick instance id */
311  Uint8 axis; /**< The joystick axis index */
315  Sint16 value; /**< The axis value (range: -32768 to 32767) */
318 
319 /**
320  * \brief Joystick trackball motion event structure (event.jball.*)
321  */
322 typedef struct SDL_JoyBallEvent
323 {
324  Uint32 type; /**< ::SDL_JOYBALLMOTION */
325  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
326  SDL_JoystickID which; /**< The joystick instance id */
327  Uint8 ball; /**< The joystick trackball index */
331  Sint16 xrel; /**< The relative motion in the X direction */
332  Sint16 yrel; /**< The relative motion in the Y direction */
334 
335 /**
336  * \brief Joystick hat position change event structure (event.jhat.*)
337  */
338 typedef struct SDL_JoyHatEvent
339 {
340  Uint32 type; /**< ::SDL_JOYHATMOTION */
341  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
342  SDL_JoystickID which; /**< The joystick instance id */
343  Uint8 hat; /**< The joystick hat index */
344  Uint8 value; /**< The hat position value.
345  * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
346  * \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
347  * \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
348  *
349  * Note that zero means the POV is centered.
350  */
354 
355 /**
356  * \brief Joystick button event structure (event.jbutton.*)
357  */
358 typedef struct SDL_JoyButtonEvent
359 {
360  Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
361  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
362  SDL_JoystickID which; /**< The joystick instance id */
363  Uint8 button; /**< The joystick button index */
364  Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
368 
369 /**
370  * \brief Joystick device event structure (event.jdevice.*)
371  */
372 typedef struct SDL_JoyDeviceEvent
373 {
374  Uint32 type; /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
375  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
376  Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
378 
379 
380 /**
381  * \brief Game controller axis motion event structure (event.caxis.*)
382  */
384 {
385  Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */
386  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
387  SDL_JoystickID which; /**< The joystick instance id */
388  Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */
392  Sint16 value; /**< The axis value (range: -32768 to 32767) */
395 
396 
397 /**
398  * \brief Game controller button event structure (event.cbutton.*)
399  */
401 {
402  Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
403  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
404  SDL_JoystickID which; /**< The joystick instance id */
405  Uint8 button; /**< The controller button (SDL_GameControllerButton) */
406  Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
410 
411 
412 /**
413  * \brief Controller device event structure (event.cdevice.*)
414  */
416 {
417  Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
418  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
419  Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
421 
422 /**
423  * \brief Game controller touchpad event structure (event.ctouchpad.*)
424  */
426 {
427  Uint32 type; /**< ::SDL_CONTROLLERTOUCHPADDOWN or ::SDL_CONTROLLERTOUCHPADMOTION or ::SDL_CONTROLLERTOUCHPADUP */
428  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
429  SDL_JoystickID which; /**< The joystick instance id */
430  Sint32 touchpad; /**< The index of the touchpad */
431  Sint32 finger; /**< The index of the finger on the touchpad */
432  float x; /**< Normalized in the range 0...1 with 0 being on the left */
433  float y; /**< Normalized in the range 0...1 with 0 being at the top */
434  float pressure; /**< Normalized in the range 0...1 */
436 
437 /**
438  * \brief Game controller sensor event structure (event.csensor.*)
439  */
441 {
442  Uint32 type; /**< ::SDL_CONTROLLERSENSORUPDATE */
443  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
444  SDL_JoystickID which; /**< The joystick instance id */
445  Sint32 sensor; /**< The type of the sensor, one of the values of ::SDL_SensorType */
446  float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */
448 
449 /**
450  * \brief Audio device event structure (event.adevice.*)
451  */
452 typedef struct SDL_AudioDeviceEvent
453 {
454  Uint32 type; /**< ::SDL_AUDIODEVICEADDED, or ::SDL_AUDIODEVICEREMOVED */
455  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
456  Uint32 which; /**< The audio device index for the ADDED event (valid until next SDL_GetNumAudioDevices() call), SDL_AudioDeviceID for the REMOVED event */
457  Uint8 iscapture; /**< zero if an output device, non-zero if a capture device. */
462 
463 
464 /**
465  * \brief Touch finger event structure (event.tfinger.*)
466  */
467 typedef struct SDL_TouchFingerEvent
468 {
469  Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
470  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
471  SDL_TouchID touchId; /**< The touch device id */
473  float x; /**< Normalized in the range 0...1 */
474  float y; /**< Normalized in the range 0...1 */
475  float dx; /**< Normalized in the range -1...1 */
476  float dy; /**< Normalized in the range -1...1 */
477  float pressure; /**< Normalized in the range 0...1 */
478  Uint32 windowID; /**< The window underneath the finger, if any */
480 
481 
482 /**
483  * \brief Multiple Finger Gesture Event (event.mgesture.*)
484  */
485 typedef struct SDL_MultiGestureEvent
486 {
487  Uint32 type; /**< ::SDL_MULTIGESTURE */
488  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
489  SDL_TouchID touchId; /**< The touch device id */
490  float dTheta;
491  float dDist;
492  float x;
493  float y;
497 
498 
499 /**
500  * \brief Dollar Gesture Event (event.dgesture.*)
501  */
503 {
504  Uint32 type; /**< ::SDL_DOLLARGESTURE or ::SDL_DOLLARRECORD */
505  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
506  SDL_TouchID touchId; /**< The touch device id */
509  float error;
510  float x; /**< Normalized center of gesture */
511  float y; /**< Normalized center of gesture */
513 
514 
515 /**
516  * \brief An event used to request a file open by the system (event.drop.*)
517  * This event is enabled by default, you can disable it with SDL_EventState().
518  * \note If this event is enabled, you must free the filename in the event.
519  */
520 typedef struct SDL_DropEvent
521 {
522  Uint32 type; /**< ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE */
523  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
524  char *file; /**< The file name, which should be freed with SDL_free(), is NULL on begin/complete */
525  Uint32 windowID; /**< The window that was dropped on, if any */
526 } SDL_DropEvent;
527 
528 
529 /**
530  * \brief Sensor event structure (event.sensor.*)
531  */
532 typedef struct SDL_SensorEvent
533 {
534  Uint32 type; /**< ::SDL_SENSORUPDATE */
535  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
536  Sint32 which; /**< The instance ID of the sensor */
537  float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */
539 
540 /**
541  * \brief The "quit requested" event
542  */
543 typedef struct SDL_QuitEvent
544 {
545  Uint32 type; /**< ::SDL_QUIT */
546  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
547 } SDL_QuitEvent;
548 
549 /**
550  * \brief OS Specific event
551  */
552 typedef struct SDL_OSEvent
553 {
554  Uint32 type; /**< ::SDL_QUIT */
555  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
556 } SDL_OSEvent;
557 
558 /**
559  * \brief A user-defined event type (event.user.*)
560  */
561 typedef struct SDL_UserEvent
562 {
563  Uint32 type; /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */
564  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
565  Uint32 windowID; /**< The associated window if any */
566  Sint32 code; /**< User defined event code */
567  void *data1; /**< User defined data pointer */
568  void *data2; /**< User defined data pointer */
569 } SDL_UserEvent;
570 
571 
572 struct SDL_SysWMmsg;
573 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
574 
575 /**
576  * \brief A video driver dependent system event (event.syswm.*)
577  * This event is disabled by default, you can enable it with SDL_EventState()
578  *
579  * \note If you want to use this event, you should include SDL_syswm.h.
580  */
581 typedef struct SDL_SysWMEvent
582 {
583  Uint32 type; /**< ::SDL_SYSWMEVENT */
584  Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
585  SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */
587 
588 /**
589  * \brief General event structure
590  */
591 typedef union SDL_Event
592 {
593  Uint32 type; /**< Event type, shared with all events */
594  SDL_CommonEvent common; /**< Common event data */
595  SDL_DisplayEvent display; /**< Display event data */
596  SDL_WindowEvent window; /**< Window event data */
597  SDL_KeyboardEvent key; /**< Keyboard event data */
598  SDL_TextEditingEvent edit; /**< Text editing event data */
599  SDL_TextInputEvent text; /**< Text input event data */
600  SDL_MouseMotionEvent motion; /**< Mouse motion event data */
601  SDL_MouseButtonEvent button; /**< Mouse button event data */
602  SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
603  SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
604  SDL_JoyBallEvent jball; /**< Joystick ball event data */
605  SDL_JoyHatEvent jhat; /**< Joystick hat event data */
606  SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
607  SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
608  SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */
609  SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */
610  SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */
611  SDL_ControllerTouchpadEvent ctouchpad; /**< Game Controller touchpad event data */
612  SDL_ControllerSensorEvent csensor; /**< Game Controller sensor event data */
613  SDL_AudioDeviceEvent adevice; /**< Audio device event data */
614  SDL_SensorEvent sensor; /**< Sensor event data */
615  SDL_QuitEvent quit; /**< Quit request event data */
616  SDL_UserEvent user; /**< Custom event data */
617  SDL_SysWMEvent syswm; /**< System dependent window event data */
618  SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
619  SDL_MultiGestureEvent mgesture; /**< Gesture event data */
620  SDL_DollarGestureEvent dgesture; /**< Gesture event data */
621  SDL_DropEvent drop; /**< Drag and drop event data */
622 
623  /* This is necessary for ABI compatibility between Visual C++ and GCC
624  Visual C++ will respect the push pack pragma and use 52 bytes for
625  this structure, and GCC will use the alignment of the largest datatype
626  within the union, which is 8 bytes.
627 
628  So... we'll add padding to force the size to be 56 bytes for both.
629  */
631 } SDL_Event;
632 
633 /* Make sure we haven't broken binary compatibility */
635 
636 
637 /* Function prototypes */
638 
639 /**
640  * Pumps the event loop, gathering events from the input devices.
641  *
642  * This function updates the event queue and internal input device state.
643  *
644  * This should only be run in the thread that sets the video mode.
645  */
646 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
647 
648 /* @{ */
649 typedef enum
650 {
655 
656 /**
657  * Checks the event queue for messages and optionally returns them.
658  *
659  * If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
660  * the back of the event queue.
661  *
662  * If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
663  * of the event queue, within the specified minimum and maximum type,
664  * will be returned and will not be removed from the queue.
665  *
666  * If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
667  * of the event queue, within the specified minimum and maximum type,
668  * will be returned and will be removed from the queue.
669  *
670  * \return The number of events actually stored, or -1 if there was an error.
671  *
672  * This function is thread-safe.
673  */
674 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
675  SDL_eventaction action,
676  Uint32 minType, Uint32 maxType);
677 /* @} */
678 
679 /**
680  * Checks to see if certain event types are in the event queue.
681  */
682 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
683 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
684 
685 /**
686  * This function clears events from the event queue
687  * This function only affects currently queued events. If you want to make
688  * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
689  * on the main thread immediately before the flush call.
690  */
691 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
692 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
693 
694 /**
695  * \brief Polls for currently pending events.
696  *
697  * \return 1 if there are any pending events, or 0 if there are none available.
698  *
699  * \param event If not NULL, the next event is removed from the queue and
700  * stored in that area.
701  */
702 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
703 
704 /**
705  * \brief Waits indefinitely for the next available event.
706  *
707  * \return 1, or 0 if there was an error while waiting for events.
708  *
709  * \param event If not NULL, the next event is removed from the queue and
710  * stored in that area.
711  */
712 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
713 
714 /**
715  * \brief Waits until the specified timeout (in milliseconds) for the next
716  * available event.
717  *
718  * \return 1, or 0 if there was an error while waiting for events.
719  *
720  * \param event If not NULL, the next event is removed from the queue and
721  * stored in that area.
722  * \param timeout The timeout (in milliseconds) to wait for next event.
723  */
724 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
725  int timeout);
726 
727 /**
728  * \brief Add an event to the event queue.
729  *
730  * \return 1 on success, 0 if the event was filtered, or -1 if the event queue
731  * was full or there was some other error.
732  */
733 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
734 
735 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
736 
737 /**
738  * Sets up a filter to process all events before they change internal state and
739  * are posted to the internal event queue.
740  *
741  * The filter is prototyped as:
742  * \code
743  * int SDL_EventFilter(void *userdata, SDL_Event * event);
744  * \endcode
745  *
746  * If the filter returns 1, then the event will be added to the internal queue.
747  * If it returns 0, then the event will be dropped from the queue, but the
748  * internal state will still be updated. This allows selective filtering of
749  * dynamically arriving events.
750  *
751  * \warning Be very careful of what you do in the event filter function, as
752  * it may run in a different thread!
753  *
754  * There is one caveat when dealing with the ::SDL_QuitEvent event type. The
755  * event filter is only called when the window manager desires to close the
756  * application window. If the event filter returns 1, then the window will
757  * be closed, otherwise the window will remain open if possible.
758  *
759  * If the quit event is generated by an interrupt signal, it will bypass the
760  * internal queue and be delivered to the application at the next event poll.
761  */
762 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
763  void *userdata);
764 
765 /**
766  * Return the current event filter - can be used to "chain" filters.
767  * If there is no event filter set, this function returns SDL_FALSE.
768  */
769 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
770  void **userdata);
771 
772 /**
773  * Add a function which is called when an event is added to the queue.
774  */
775 extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
776  void *userdata);
777 
778 /**
779  * Remove an event watch function added with SDL_AddEventWatch()
780  */
781 extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
782  void *userdata);
783 
784 /**
785  * Run the filter function on the current event queue, removing any
786  * events for which the filter returns 0.
787  */
788 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
789  void *userdata);
790 
791 /* @{ */
792 #define SDL_QUERY -1
793 #define SDL_IGNORE 0
794 #define SDL_DISABLE 0
795 #define SDL_ENABLE 1
796 
797 /**
798  * This function allows you to set the state of processing certain events.
799  * - If \c state is set to ::SDL_IGNORE, that event will be automatically
800  * dropped from the event queue and will not be filtered.
801  * - If \c state is set to ::SDL_ENABLE, that event will be processed
802  * normally.
803  * - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
804  * current processing state of the specified event.
805  */
806 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
807 /* @} */
808 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
809 
810 /**
811  * This function allocates a set of user-defined events, and returns
812  * the beginning event number for that set of events.
813  *
814  * If there aren't enough user-defined events left, this function
815  * returns (Uint32)-1
816  */
817 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
818 
819 /* Ends C function definitions when using C++ */
820 #ifdef __cplusplus
821 }
822 #endif
823 #include "close_code.h"
824 
825 #endif /* SDL_events_h_ */
826 
827 /* vi: set ts=4 sw=4 expandtab: */
int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, Uint32 minType, Uint32 maxType)
void SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
#define SDL_TEXTEDITINGEVENT_TEXT_SIZE
Definition: SDL_events.h:229
void SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
SDL_bool SDL_HasEvent(Uint32 type)
int(* SDL_EventFilter)(void *userdata, SDL_Event *event)
Definition: SDL_events.h:735
int SDL_PollEvent(SDL_Event *event)
Polls for currently pending events.
Uint32 SDL_RegisterEvents(int numevents)
SDL_EventType
The types of events that can be delivered.
Definition: SDL_events.h:56
@ SDL_MOUSEMOTION
Definition: SDL_events.h:107
@ SDL_JOYDEVICEADDED
Definition: SDL_events.h:118
@ SDL_DROPBEGIN
Definition: SDL_events.h:149
@ SDL_SENSORUPDATE
Definition: SDL_events.h:157
@ SDL_CONTROLLERTOUCHPADDOWN
Definition: SDL_events.h:128
@ SDL_FINGERMOTION
Definition: SDL_events.h:136
@ SDL_TEXTEDITING
Definition: SDL_events.h:100
@ SDL_DROPTEXT
Definition: SDL_events.h:148
@ SDL_QUIT
Definition: SDL_events.h:60
@ SDL_APP_LOWMEMORY
Definition: SDL_events.h:67
@ SDL_JOYBUTTONDOWN
Definition: SDL_events.h:116
@ SDL_APP_WILLENTERFOREGROUND
Definition: SDL_events.h:79
@ SDL_USEREVENT
Definition: SDL_events.h:166
@ SDL_MOUSEBUTTONUP
Definition: SDL_events.h:109
@ SDL_JOYDEVICEREMOVED
Definition: SDL_events.h:119
@ SDL_TEXTINPUT
Definition: SDL_events.h:101
@ SDL_WINDOWEVENT
Definition: SDL_events.h:94
@ SDL_MOUSEWHEEL
Definition: SDL_events.h:110
@ SDL_CONTROLLERTOUCHPADMOTION
Definition: SDL_events.h:129
@ SDL_CLIPBOARDUPDATE
Definition: SDL_events.h:144
@ SDL_SYSWMEVENT
Definition: SDL_events.h:95
@ SDL_LOCALECHANGED
Definition: SDL_events.h:88
@ SDL_JOYBUTTONUP
Definition: SDL_events.h:117
@ SDL_JOYBALLMOTION
Definition: SDL_events.h:114
@ SDL_DISPLAYEVENT
Definition: SDL_events.h:91
@ SDL_FINGERUP
Definition: SDL_events.h:135
@ SDL_RENDER_DEVICE_RESET
Definition: SDL_events.h:161
@ SDL_CONTROLLERBUTTONUP
Definition: SDL_events.h:124
@ SDL_MOUSEBUTTONDOWN
Definition: SDL_events.h:108
@ SDL_CONTROLLERDEVICEADDED
Definition: SDL_events.h:125
@ SDL_APP_DIDENTERFOREGROUND
Definition: SDL_events.h:83
@ SDL_DOLLARRECORD
Definition: SDL_events.h:140
@ SDL_APP_WILLENTERBACKGROUND
Definition: SDL_events.h:71
@ SDL_MULTIGESTURE
Definition: SDL_events.h:141
@ SDL_FINGERDOWN
Definition: SDL_events.h:134
@ SDL_DROPCOMPLETE
Definition: SDL_events.h:150
@ SDL_DOLLARGESTURE
Definition: SDL_events.h:139
@ SDL_CONTROLLERBUTTONDOWN
Definition: SDL_events.h:123
@ SDL_APP_DIDENTERBACKGROUND
Definition: SDL_events.h:75
@ SDL_APP_TERMINATING
Definition: SDL_events.h:63
@ SDL_CONTROLLERAXISMOTION
Definition: SDL_events.h:122
@ SDL_KEYDOWN
Definition: SDL_events.h:98
@ SDL_KEYMAPCHANGED
Definition: SDL_events.h:102
@ SDL_AUDIODEVICEREMOVED
Definition: SDL_events.h:154
@ SDL_DROPFILE
Definition: SDL_events.h:147
@ SDL_AUDIODEVICEADDED
Definition: SDL_events.h:153
@ SDL_KEYUP
Definition: SDL_events.h:99
@ SDL_CONTROLLERDEVICEREMOVED
Definition: SDL_events.h:126
@ SDL_RENDER_TARGETS_RESET
Definition: SDL_events.h:160
@ SDL_CONTROLLERTOUCHPADUP
Definition: SDL_events.h:130
@ SDL_CONTROLLERDEVICEREMAPPED
Definition: SDL_events.h:127
@ SDL_JOYAXISMOTION
Definition: SDL_events.h:113
@ SDL_CONTROLLERSENSORUPDATE
Definition: SDL_events.h:131
@ SDL_JOYHATMOTION
Definition: SDL_events.h:115
@ SDL_FIRSTEVENT
Definition: SDL_events.h:57
@ SDL_LASTEVENT
Definition: SDL_events.h:171
#define SDL_TEXTINPUTEVENT_TEXT_SIZE
Definition: SDL_events.h:244
SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event)==56)
void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
SDL_bool SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata)
void SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
int SDL_WaitEventTimeout(SDL_Event *event, int timeout)
Waits until the specified timeout (in milliseconds) for the next available event.
SDL_eventaction
Definition: SDL_events.h:650
@ SDL_ADDEVENT
Definition: SDL_events.h:651
@ SDL_PEEKEVENT
Definition: SDL_events.h:652
@ SDL_GETEVENT
Definition: SDL_events.h:653
void SDL_FlushEvents(Uint32 minType, Uint32 maxType)
void SDL_FlushEvent(Uint32 type)
int SDL_WaitEvent(SDL_Event *event)
Waits indefinitely for the next available event.
Uint8 SDL_EventState(Uint32 type, int state)
int SDL_PushEvent(SDL_Event *event)
Add an event to the event queue.
SDL_bool SDL_HasEvents(Uint32 minType, Uint32 maxType)
void SDL_PumpEvents(void)
Sint64 SDL_GestureID
Definition: SDL_gesture.h:44
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
uint8_t Uint8
Definition: SDL_stdinc.h:185
uint16_t Uint16
Definition: SDL_stdinc.h:197
int32_t Sint32
Definition: SDL_stdinc.h:203
SDL_bool
Definition: SDL_stdinc.h:168
int16_t Sint16
Definition: SDL_stdinc.h:191
uint32_t Uint32
Definition: SDL_stdinc.h:209
Sint64 SDL_TouchID
Definition: SDL_touch.h:41
Sint64 SDL_FingerID
Definition: SDL_touch.h:42
Audio device event structure (event.adevice.*)
Definition: SDL_events.h:453
Fields shared by every event.
Definition: SDL_events.h:178
Uint32 timestamp
Definition: SDL_events.h:180
Game controller axis motion event structure (event.caxis.*)
Definition: SDL_events.h:384
SDL_JoystickID which
Definition: SDL_events.h:387
Game controller button event structure (event.cbutton.*)
Definition: SDL_events.h:401
SDL_JoystickID which
Definition: SDL_events.h:404
Controller device event structure (event.cdevice.*)
Definition: SDL_events.h:416
Game controller sensor event structure (event.csensor.*)
Definition: SDL_events.h:441
SDL_JoystickID which
Definition: SDL_events.h:444
Game controller touchpad event structure (event.ctouchpad.*)
Definition: SDL_events.h:426
Display state change event data (event.display.*)
Definition: SDL_events.h:187
Dollar Gesture Event (event.dgesture.*)
Definition: SDL_events.h:503
SDL_GestureID gestureId
Definition: SDL_events.h:507
An event used to request a file open by the system (event.drop.*) This event is enabled by default,...
Definition: SDL_events.h:521
Uint32 timestamp
Definition: SDL_events.h:523
Uint32 windowID
Definition: SDL_events.h:525
Joystick axis motion event structure (event.jaxis.*)
Definition: SDL_events.h:307
SDL_JoystickID which
Definition: SDL_events.h:310
Joystick trackball motion event structure (event.jball.*)
Definition: SDL_events.h:323
SDL_JoystickID which
Definition: SDL_events.h:326
Joystick button event structure (event.jbutton.*)
Definition: SDL_events.h:359
SDL_JoystickID which
Definition: SDL_events.h:362
Joystick device event structure (event.jdevice.*)
Definition: SDL_events.h:373
Joystick hat position change event structure (event.jhat.*)
Definition: SDL_events.h:339
SDL_JoystickID which
Definition: SDL_events.h:342
Uint32 timestamp
Definition: SDL_events.h:341
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:218
SDL_Keysym keysym
Definition: SDL_events.h:226
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:48
Mouse button event structure (event.button.*)
Definition: SDL_events.h:276
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:260
Mouse wheel event structure (event.wheel.*)
Definition: SDL_events.h:293
Multiple Finger Gesture Event (event.mgesture.*)
Definition: SDL_events.h:486
SDL_TouchID touchId
Definition: SDL_events.h:489
OS Specific event.
Definition: SDL_events.h:553
Uint32 type
Definition: SDL_events.h:554
Uint32 timestamp
Definition: SDL_events.h:555
The "quit requested" event.
Definition: SDL_events.h:544
Uint32 timestamp
Definition: SDL_events.h:546
Sensor event structure (event.sensor.*)
Definition: SDL_events.h:533
Uint32 timestamp
Definition: SDL_events.h:535
float data[6]
Definition: SDL_events.h:537
A video driver dependent system event (event.syswm.*) This event is disabled by default,...
Definition: SDL_events.h:582
Uint32 timestamp
Definition: SDL_events.h:584
SDL_SysWMmsg * msg
Definition: SDL_events.h:585
Keyboard text editing event structure (event.edit.*)
Definition: SDL_events.h:234
char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]
Definition: SDL_events.h:238
Keyboard text input event structure (event.text.*)
Definition: SDL_events.h:249
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]
Definition: SDL_events.h:253
Touch finger event structure (event.tfinger.*)
Definition: SDL_events.h:468
SDL_FingerID fingerId
Definition: SDL_events.h:472
SDL_TouchID touchId
Definition: SDL_events.h:471
A user-defined event type (event.user.*)
Definition: SDL_events.h:562
void * data2
Definition: SDL_events.h:568
void * data1
Definition: SDL_events.h:567
Uint32 windowID
Definition: SDL_events.h:565
Uint32 timestamp
Definition: SDL_events.h:564
Window state change event data (event.window.*)
Definition: SDL_events.h:202
Uint32 timestamp
Definition: SDL_events.h:204
General event structure.
Definition: SDL_events.h:592
SDL_QuitEvent quit
Definition: SDL_events.h:615
SDL_AudioDeviceEvent adevice
Definition: SDL_events.h:613
SDL_JoyDeviceEvent jdevice
Definition: SDL_events.h:607
Uint32 type
Definition: SDL_events.h:593
SDL_MouseWheelEvent wheel
Definition: SDL_events.h:602
SDL_JoyHatEvent jhat
Definition: SDL_events.h:605
SDL_DollarGestureEvent dgesture
Definition: SDL_events.h:620
SDL_JoyButtonEvent jbutton
Definition: SDL_events.h:606
SDL_WindowEvent window
Definition: SDL_events.h:596
SDL_TextEditingEvent edit
Definition: SDL_events.h:598
SDL_TextInputEvent text
Definition: SDL_events.h:599
SDL_ControllerAxisEvent caxis
Definition: SDL_events.h:608
Uint8 padding[56]
Definition: SDL_events.h:630
SDL_TouchFingerEvent tfinger
Definition: SDL_events.h:618
SDL_SysWMEvent syswm
Definition: SDL_events.h:617
SDL_MouseButtonEvent button
Definition: SDL_events.h:601
SDL_UserEvent user
Definition: SDL_events.h:616
SDL_KeyboardEvent key
Definition: SDL_events.h:597
SDL_CommonEvent common
Definition: SDL_events.h:594
SDL_MultiGestureEvent mgesture
Definition: SDL_events.h:619
SDL_MouseMotionEvent motion
Definition: SDL_events.h:600
SDL_JoyAxisEvent jaxis
Definition: SDL_events.h:603
SDL_DropEvent drop
Definition: SDL_events.h:621
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:610
SDL_ControllerSensorEvent csensor
Definition: SDL_events.h:612
SDL_JoyBallEvent jball
Definition: SDL_events.h:604
SDL_ControllerButtonEvent cbutton
Definition: SDL_events.h:609
SDL_SensorEvent sensor
Definition: SDL_events.h:614
SDL_ControllerTouchpadEvent ctouchpad
Definition: SDL_events.h:611
SDL_DisplayEvent display
Definition: SDL_events.h:595