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 
129     /* Touch events */
130     SDL_FINGERDOWN      = 0x700,
131     SDL_FINGERUP,
132     SDL_FINGERMOTION,
133 
134     /* Gesture events */
135     SDL_DOLLARGESTURE   = 0x800,
136     SDL_DOLLARRECORD,
137     SDL_MULTIGESTURE,
138 
139     /* Clipboard events */
140     SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
141 
142     /* Drag and drop events */
143     SDL_DROPFILE        = 0x1000, /**< The system requests a file open */
144     SDL_DROPTEXT,                 /**< text/plain drag-and-drop event */
145     SDL_DROPBEGIN,                /**< A new set of drops is beginning (NULL filename) */
146     SDL_DROPCOMPLETE,             /**< Current set of drops is now complete (NULL filename) */
147 
148     /* Audio hotplug events */
149     SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */
150     SDL_AUDIODEVICEREMOVED,        /**< An audio device has been removed. */
151 
152     /* Sensor events */
153     SDL_SENSORUPDATE = 0x1200,     /**< A sensor was updated */
154 
155     /* Render events */
156     SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
157     SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
158 
159     /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
160      *  and should be allocated with SDL_RegisterEvents()
161      */
162     SDL_USEREVENT    = 0x8000,
163 
164     /**
165      *  This last event is only for bounding internal arrays
166      */
167     SDL_LASTEVENT    = 0xFFFF
168 } SDL_EventType;
169 
170 /**
171  *  \brief Fields shared by every event
172  */
173 typedef struct SDL_CommonEvent
174 {
175     Uint32 type;
176     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
177 } SDL_CommonEvent;
178 
179 /**
180  *  \brief Display state change event data (event.display.*)
181  */
182 typedef struct SDL_DisplayEvent
183 {
184     Uint32 type;        /**< ::SDL_DISPLAYEVENT */
185     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
186     Uint32 display;     /**< The associated display index */
187     Uint8 event;        /**< ::SDL_DisplayEventID */
188     Uint8 padding1;
189     Uint8 padding2;
190     Uint8 padding3;
191     Sint32 data1;       /**< event dependent data */
192 } SDL_DisplayEvent;
193 
194 /**
195  *  \brief Window state change event data (event.window.*)
196  */
197 typedef struct SDL_WindowEvent
198 {
199     Uint32 type;        /**< ::SDL_WINDOWEVENT */
200     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
201     Uint32 windowID;    /**< The associated window */
202     Uint8 event;        /**< ::SDL_WindowEventID */
203     Uint8 padding1;
204     Uint8 padding2;
205     Uint8 padding3;
206     Sint32 data1;       /**< event dependent data */
207     Sint32 data2;       /**< event dependent data */
208 } SDL_WindowEvent;
209 
210 /**
211  *  \brief Keyboard button event structure (event.key.*)
212  */
213 typedef struct SDL_KeyboardEvent
214 {
215     Uint32 type;        /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
216     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
217     Uint32 windowID;    /**< The window with keyboard focus, if any */
218     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
219     Uint8 repeat;       /**< Non-zero if this is a key repeat */
220     Uint8 padding2;
221     Uint8 padding3;
222     SDL_Keysym keysym;  /**< The key that was pressed or released */
223 } SDL_KeyboardEvent;
224 
225 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
226 /**
227  *  \brief Keyboard text editing event structure (event.edit.*)
228  */
229 typedef struct SDL_TextEditingEvent
230 {
231     Uint32 type;                                /**< ::SDL_TEXTEDITING */
232     Uint32 timestamp;                           /**< In milliseconds, populated using SDL_GetTicks() */
233     Uint32 windowID;                            /**< The window with keyboard focus, if any */
234     char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
235     Sint32 start;                               /**< The start cursor of selected editing text */
236     Sint32 length;                              /**< The length of selected editing text */
237 } SDL_TextEditingEvent;
238 
239 
240 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
241 /**
242  *  \brief Keyboard text input event structure (event.text.*)
243  */
244 typedef struct SDL_TextInputEvent
245 {
246     Uint32 type;                              /**< ::SDL_TEXTINPUT */
247     Uint32 timestamp;                         /**< In milliseconds, populated using SDL_GetTicks() */
248     Uint32 windowID;                          /**< The window with keyboard focus, if any */
249     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
250 } SDL_TextInputEvent;
251 
252 /**
253  *  \brief Mouse motion event structure (event.motion.*)
254  */
255 typedef struct SDL_MouseMotionEvent
256 {
257     Uint32 type;        /**< ::SDL_MOUSEMOTION */
258     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
259     Uint32 windowID;    /**< The window with mouse focus, if any */
260     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
261     Uint32 state;       /**< The current button state */
262     Sint32 x;           /**< X coordinate, relative to window */
263     Sint32 y;           /**< Y coordinate, relative to window */
264     Sint32 xrel;        /**< The relative motion in the X direction */
265     Sint32 yrel;        /**< The relative motion in the Y direction */
266 } SDL_MouseMotionEvent;
267 
268 /**
269  *  \brief Mouse button event structure (event.button.*)
270  */
271 typedef struct SDL_MouseButtonEvent
272 {
273     Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
274     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
275     Uint32 windowID;    /**< The window with mouse focus, if any */
276     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
277     Uint8 button;       /**< The mouse button index */
278     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
279     Uint8 clicks;       /**< 1 for single-click, 2 for double-click, etc. */
280     Uint8 padding1;
281     Sint32 x;           /**< X coordinate, relative to window */
282     Sint32 y;           /**< Y coordinate, relative to window */
283 } SDL_MouseButtonEvent;
284 
285 /**
286  *  \brief Mouse wheel event structure (event.wheel.*)
287  */
288 typedef struct SDL_MouseWheelEvent
289 {
290     Uint32 type;        /**< ::SDL_MOUSEWHEEL */
291     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
292     Uint32 windowID;    /**< The window with mouse focus, if any */
293     Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
294     Sint32 x;           /**< The amount scrolled horizontally, positive to the right and negative to the left */
295     Sint32 y;           /**< The amount scrolled vertically, positive away from the user and negative toward the user */
296     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 */
297 } SDL_MouseWheelEvent;
298 
299 /**
300  *  \brief Joystick axis motion event structure (event.jaxis.*)
301  */
302 typedef struct SDL_JoyAxisEvent
303 {
304     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
305     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
306     SDL_JoystickID which; /**< The joystick instance id */
307     Uint8 axis;         /**< The joystick axis index */
308     Uint8 padding1;
309     Uint8 padding2;
310     Uint8 padding3;
311     Sint16 value;       /**< The axis value (range: -32768 to 32767) */
312     Uint16 padding4;
313 } SDL_JoyAxisEvent;
314 
315 /**
316  *  \brief Joystick trackball motion event structure (event.jball.*)
317  */
318 typedef struct SDL_JoyBallEvent
319 {
320     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
321     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
322     SDL_JoystickID which; /**< The joystick instance id */
323     Uint8 ball;         /**< The joystick trackball index */
324     Uint8 padding1;
325     Uint8 padding2;
326     Uint8 padding3;
327     Sint16 xrel;        /**< The relative motion in the X direction */
328     Sint16 yrel;        /**< The relative motion in the Y direction */
329 } SDL_JoyBallEvent;
330 
331 /**
332  *  \brief Joystick hat position change event structure (event.jhat.*)
333  */
334 typedef struct SDL_JoyHatEvent
335 {
336     Uint32 type;        /**< ::SDL_JOYHATMOTION */
337     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
338     SDL_JoystickID which; /**< The joystick instance id */
339     Uint8 hat;          /**< The joystick hat index */
340     Uint8 value;        /**< The hat position value.
341                          *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
342                          *   \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
343                          *   \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
344                          *
345                          *   Note that zero means the POV is centered.
346                          */
347     Uint8 padding1;
348     Uint8 padding2;
349 } SDL_JoyHatEvent;
350 
351 /**
352  *  \brief Joystick button event structure (event.jbutton.*)
353  */
354 typedef struct SDL_JoyButtonEvent
355 {
356     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
357     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
358     SDL_JoystickID which; /**< The joystick instance id */
359     Uint8 button;       /**< The joystick button index */
360     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
361     Uint8 padding1;
362     Uint8 padding2;
363 } SDL_JoyButtonEvent;
364 
365 /**
366  *  \brief Joystick device event structure (event.jdevice.*)
367  */
368 typedef struct SDL_JoyDeviceEvent
369 {
370     Uint32 type;        /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
371     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
372     Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
373 } SDL_JoyDeviceEvent;
374 
375 
376 /**
377  *  \brief Game controller axis motion event structure (event.caxis.*)
378  */
379 typedef struct SDL_ControllerAxisEvent
380 {
381     Uint32 type;        /**< ::SDL_CONTROLLERAXISMOTION */
382     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
383     SDL_JoystickID which; /**< The joystick instance id */
384     Uint8 axis;         /**< The controller axis (SDL_GameControllerAxis) */
385     Uint8 padding1;
386     Uint8 padding2;
387     Uint8 padding3;
388     Sint16 value;       /**< The axis value (range: -32768 to 32767) */
389     Uint16 padding4;
390 } SDL_ControllerAxisEvent;
391 
392 
393 /**
394  *  \brief Game controller button event structure (event.cbutton.*)
395  */
396 typedef struct SDL_ControllerButtonEvent
397 {
398     Uint32 type;        /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
399     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
400     SDL_JoystickID which; /**< The joystick instance id */
401     Uint8 button;       /**< The controller button (SDL_GameControllerButton) */
402     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
403     Uint8 padding1;
404     Uint8 padding2;
405 } SDL_ControllerButtonEvent;
406 
407 
408 /**
409  *  \brief Controller device event structure (event.cdevice.*)
410  */
411 typedef struct SDL_ControllerDeviceEvent
412 {
413     Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
414     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
415     Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
416 } SDL_ControllerDeviceEvent;
417 
418 /**
419  *  \brief Audio device event structure (event.adevice.*)
420  */
421 typedef struct SDL_AudioDeviceEvent
422 {
423     Uint32 type;        /**< ::SDL_AUDIODEVICEADDED, or ::SDL_AUDIODEVICEREMOVED */
424     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
425     Uint32 which;       /**< The audio device index for the ADDED event (valid until next SDL_GetNumAudioDevices() call), SDL_AudioDeviceID for the REMOVED event */
426     Uint8 iscapture;    /**< zero if an output device, non-zero if a capture device. */
427     Uint8 padding1;
428     Uint8 padding2;
429     Uint8 padding3;
430 } SDL_AudioDeviceEvent;
431 
432 
433 /**
434  *  \brief Touch finger event structure (event.tfinger.*)
435  */
436 typedef struct SDL_TouchFingerEvent
437 {
438     Uint32 type;        /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
439     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
440     SDL_TouchID touchId; /**< The touch device id */
441     SDL_FingerID fingerId;
442     float x;            /**< Normalized in the range 0...1 */
443     float y;            /**< Normalized in the range 0...1 */
444     float dx;           /**< Normalized in the range -1...1 */
445     float dy;           /**< Normalized in the range -1...1 */
446     float pressure;     /**< Normalized in the range 0...1 */
447     Uint32 windowID;    /**< The window underneath the finger, if any */
448 } SDL_TouchFingerEvent;
449 
450 
451 /**
452  *  \brief Multiple Finger Gesture Event (event.mgesture.*)
453  */
454 typedef struct SDL_MultiGestureEvent
455 {
456     Uint32 type;        /**< ::SDL_MULTIGESTURE */
457     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
458     SDL_TouchID touchId; /**< The touch device id */
459     float dTheta;
460     float dDist;
461     float x;
462     float y;
463     Uint16 numFingers;
464     Uint16 padding;
465 } SDL_MultiGestureEvent;
466 
467 
468 /**
469  * \brief Dollar Gesture Event (event.dgesture.*)
470  */
471 typedef struct SDL_DollarGestureEvent
472 {
473     Uint32 type;        /**< ::SDL_DOLLARGESTURE or ::SDL_DOLLARRECORD */
474     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
475     SDL_TouchID touchId; /**< The touch device id */
476     SDL_GestureID gestureId;
477     Uint32 numFingers;
478     float error;
479     float x;            /**< Normalized center of gesture */
480     float y;            /**< Normalized center of gesture */
481 } SDL_DollarGestureEvent;
482 
483 
484 /**
485  *  \brief An event used to request a file open by the system (event.drop.*)
486  *         This event is enabled by default, you can disable it with SDL_EventState().
487  *  \note If this event is enabled, you must free the filename in the event.
488  */
489 typedef struct SDL_DropEvent
490 {
491     Uint32 type;        /**< ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE */
492     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
493     char *file;         /**< The file name, which should be freed with SDL_free(), is NULL on begin/complete */
494     Uint32 windowID;    /**< The window that was dropped on, if any */
495 } SDL_DropEvent;
496 
497 
498 /**
499  *  \brief Sensor event structure (event.sensor.*)
500  */
501 typedef struct SDL_SensorEvent
502 {
503     Uint32 type;        /**< ::SDL_SENSORUPDATE */
504     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
505     Sint32 which;       /**< The instance ID of the sensor */
506     float data[6];      /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */
507 } SDL_SensorEvent;
508 
509 /**
510  *  \brief The "quit requested" event
511  */
512 typedef struct SDL_QuitEvent
513 {
514     Uint32 type;        /**< ::SDL_QUIT */
515     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
516 } SDL_QuitEvent;
517 
518 /**
519  *  \brief OS Specific event
520  */
521 typedef struct SDL_OSEvent
522 {
523     Uint32 type;        /**< ::SDL_QUIT */
524     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
525 } SDL_OSEvent;
526 
527 /**
528  *  \brief A user-defined event type (event.user.*)
529  */
530 typedef struct SDL_UserEvent
531 {
532     Uint32 type;        /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */
533     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
534     Uint32 windowID;    /**< The associated window if any */
535     Sint32 code;        /**< User defined event code */
536     void *data1;        /**< User defined data pointer */
537     void *data2;        /**< User defined data pointer */
538 } SDL_UserEvent;
539 
540 
541 struct SDL_SysWMmsg;
542 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
543 
544 /**
545  *  \brief A video driver dependent system event (event.syswm.*)
546  *         This event is disabled by default, you can enable it with SDL_EventState()
547  *
548  *  \note If you want to use this event, you should include SDL_syswm.h.
549  */
550 typedef struct SDL_SysWMEvent
551 {
552     Uint32 type;        /**< ::SDL_SYSWMEVENT */
553     Uint32 timestamp;   /**< In milliseconds, populated using SDL_GetTicks() */
554     SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
555 } SDL_SysWMEvent;
556 
557 /**
558  *  \brief General event structure
559  */
560 typedef union SDL_Event
561 {
562     Uint32 type;                    /**< Event type, shared with all events */
563     SDL_CommonEvent common;         /**< Common event data */
564     SDL_DisplayEvent display;       /**< Display event data */
565     SDL_WindowEvent window;         /**< Window event data */
566     SDL_KeyboardEvent key;          /**< Keyboard event data */
567     SDL_TextEditingEvent edit;      /**< Text editing event data */
568     SDL_TextInputEvent text;        /**< Text input event data */
569     SDL_MouseMotionEvent motion;    /**< Mouse motion event data */
570     SDL_MouseButtonEvent button;    /**< Mouse button event data */
571     SDL_MouseWheelEvent wheel;      /**< Mouse wheel event data */
572     SDL_JoyAxisEvent jaxis;         /**< Joystick axis event data */
573     SDL_JoyBallEvent jball;         /**< Joystick ball event data */
574     SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
575     SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
576     SDL_JoyDeviceEvent jdevice;     /**< Joystick device change event data */
577     SDL_ControllerAxisEvent caxis;      /**< Game Controller axis event data */
578     SDL_ControllerButtonEvent cbutton;  /**< Game Controller button event data */
579     SDL_ControllerDeviceEvent cdevice;  /**< Game Controller device event data */
580     SDL_AudioDeviceEvent adevice;   /**< Audio device event data */
581     SDL_SensorEvent sensor;         /**< Sensor event data */
582     SDL_QuitEvent quit;             /**< Quit request event data */
583     SDL_UserEvent user;             /**< Custom event data */
584     SDL_SysWMEvent syswm;           /**< System dependent window event data */
585     SDL_TouchFingerEvent tfinger;   /**< Touch finger event data */
586     SDL_MultiGestureEvent mgesture; /**< Gesture event data */
587     SDL_DollarGestureEvent dgesture; /**< Gesture event data */
588     SDL_DropEvent drop;             /**< Drag and drop event data */
589 
590     /* This is necessary for ABI compatibility between Visual C++ and GCC
591        Visual C++ will respect the push pack pragma and use 52 bytes for
592        this structure, and GCC will use the alignment of the largest datatype
593        within the union, which is 8 bytes.
594 
595        So... we'll add padding to force the size to be 56 bytes for both.
596     */
597     Uint8 padding[56];
598 } SDL_Event;
599 
600 /* Make sure we haven't broken binary compatibility */
601 SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == 56);
602 
603 
604 /* Function prototypes */
605 
606 /**
607  *  Pumps the event loop, gathering events from the input devices.
608  *
609  *  This function updates the event queue and internal input device state.
610  *
611  *  This should only be run in the thread that sets the video mode.
612  */
613 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
614 
615 /* @{ */
616 typedef enum
617 {
618     SDL_ADDEVENT,
619     SDL_PEEKEVENT,
620     SDL_GETEVENT
621 } SDL_eventaction;
622 
623 /**
624  *  Checks the event queue for messages and optionally returns them.
625  *
626  *  If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
627  *  the back of the event queue.
628  *
629  *  If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
630  *  of the event queue, within the specified minimum and maximum type,
631  *  will be returned and will not be removed from the queue.
632  *
633  *  If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
634  *  of the event queue, within the specified minimum and maximum type,
635  *  will be returned and will be removed from the queue.
636  *
637  *  \return The number of events actually stored, or -1 if there was an error.
638  *
639  *  This function is thread-safe.
640  */
641 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
642                                            SDL_eventaction action,
643                                            Uint32 minType, Uint32 maxType);
644 /* @} */
645 
646 /**
647  *  Checks to see if certain event types are in the event queue.
648  */
649 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
650 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
651 
652 /**
653  *  This function clears events from the event queue
654  *  This function only affects currently queued events. If you want to make
655  *  sure that all pending OS events are flushed, you can call SDL_PumpEvents()
656  *  on the main thread immediately before the flush call.
657  */
658 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
659 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
660 
661 /**
662  *  \brief Polls for currently pending events.
663  *
664  *  \return 1 if there are any pending events, or 0 if there are none available.
665  *
666  *  \param event If not NULL, the next event is removed from the queue and
667  *               stored in that area.
668  */
669 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
670 
671 /**
672  *  \brief Waits indefinitely for the next available event.
673  *
674  *  \return 1, or 0 if there was an error while waiting for events.
675  *
676  *  \param event If not NULL, the next event is removed from the queue and
677  *               stored in that area.
678  */
679 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
680 
681 /**
682  *  \brief Waits until the specified timeout (in milliseconds) for the next
683  *         available event.
684  *
685  *  \return 1, or 0 if there was an error while waiting for events.
686  *
687  *  \param event If not NULL, the next event is removed from the queue and
688  *               stored in that area.
689  *  \param timeout The timeout (in milliseconds) to wait for next event.
690  */
691 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
692                                                  int timeout);
693 
694 /**
695  *  \brief Add an event to the event queue.
696  *
697  *  \return 1 on success, 0 if the event was filtered, or -1 if the event queue
698  *          was full or there was some other error.
699  */
700 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
701 
702 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
703 
704 /**
705  *  Sets up a filter to process all events before they change internal state and
706  *  are posted to the internal event queue.
707  *
708  *  The filter is prototyped as:
709  *  \code
710  *      int SDL_EventFilter(void *userdata, SDL_Event * event);
711  *  \endcode
712  *
713  *  If the filter returns 1, then the event will be added to the internal queue.
714  *  If it returns 0, then the event will be dropped from the queue, but the
715  *  internal state will still be updated.  This allows selective filtering of
716  *  dynamically arriving events.
717  *
718  *  \warning  Be very careful of what you do in the event filter function, as
719  *            it may run in a different thread!
720  *
721  *  There is one caveat when dealing with the ::SDL_QuitEvent event type.  The
722  *  event filter is only called when the window manager desires to close the
723  *  application window.  If the event filter returns 1, then the window will
724  *  be closed, otherwise the window will remain open if possible.
725  *
726  *  If the quit event is generated by an interrupt signal, it will bypass the
727  *  internal queue and be delivered to the application at the next event poll.
728  */
729 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
730                                                 void *userdata);
731 
732 /**
733  *  Return the current event filter - can be used to "chain" filters.
734  *  If there is no event filter set, this function returns SDL_FALSE.
735  */
736 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
737                                                     void **userdata);
738 
739 /**
740  *  Add a function which is called when an event is added to the queue.
741  */
742 extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
743                                                void *userdata);
744 
745 /**
746  *  Remove an event watch function added with SDL_AddEventWatch()
747  */
748 extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
749                                                void *userdata);
750 
751 /**
752  *  Run the filter function on the current event queue, removing any
753  *  events for which the filter returns 0.
754  */
755 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
756                                               void *userdata);
757 
758 /* @{ */
759 #define SDL_QUERY   -1
760 #define SDL_IGNORE   0
761 #define SDL_DISABLE  0
762 #define SDL_ENABLE   1
763 
764 /**
765  *  This function allows you to set the state of processing certain events.
766  *   - If \c state is set to ::SDL_IGNORE, that event will be automatically
767  *     dropped from the event queue and will not be filtered.
768  *   - If \c state is set to ::SDL_ENABLE, that event will be processed
769  *     normally.
770  *   - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
771  *     current processing state of the specified event.
772  */
773 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
774 /* @} */
775 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
776 
777 /**
778  *  This function allocates a set of user-defined events, and returns
779  *  the beginning event number for that set of events.
780  *
781  *  If there aren't enough user-defined events left, this function
782  *  returns (Uint32)-1
783  */
784 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
785 
786 /* Ends C function definitions when using C++ */
787 #ifdef __cplusplus
788 }
789 #endif
790 #include "close_code.h"
791 
792 #endif /* SDL_events_h_ */
793 
794 /* vi: set ts=4 sw=4 expandtab: */
795