SDL_events.h 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_events.h
  20. *
  21. * Include file for SDL event handling.
  22. */
  23. #ifndef SDL_events_h_
  24. #define SDL_events_h_
  25. #include <SDL3/SDL_audio.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_gamepad.h>
  28. #include <SDL3/SDL_joystick.h>
  29. #include <SDL3/SDL_keyboard.h>
  30. #include <SDL3/SDL_mouse.h>
  31. #include <SDL3/SDL_quit.h>
  32. #include <SDL3/SDL_stdinc.h>
  33. #include <SDL3/SDL_touch.h>
  34. #include <SDL3/SDL_video.h>
  35. #include <SDL3/SDL_begin_code.h>
  36. /* Set up for C function definitions, even when using C++ */
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /* General keyboard/mouse state definitions */
  41. #define SDL_RELEASED 0
  42. #define SDL_PRESSED 1
  43. /**
  44. * The types of events that can be delivered.
  45. */
  46. typedef enum
  47. {
  48. SDL_EVENT_FIRST = 0, /**< Unused (do not remove) */
  49. /* Application events */
  50. SDL_EVENT_QUIT = 0x100, /**< User-requested quit */
  51. /* These application events have special meaning on iOS, see README-ios.md for details */
  52. SDL_EVENT_TERMINATING, /**< The application is being terminated by the OS
  53. Called on iOS in applicationWillTerminate()
  54. Called on Android in onDestroy()
  55. */
  56. SDL_EVENT_LOW_MEMORY, /**< The application is low on memory, free memory if possible.
  57. Called on iOS in applicationDidReceiveMemoryWarning()
  58. Called on Android in onLowMemory()
  59. */
  60. SDL_EVENT_WILL_ENTER_BACKGROUND, /**< The application is about to enter the background
  61. Called on iOS in applicationWillResignActive()
  62. Called on Android in onPause()
  63. */
  64. SDL_EVENT_DID_ENTER_BACKGROUND, /**< The application did enter the background and may not get CPU for some time
  65. Called on iOS in applicationDidEnterBackground()
  66. Called on Android in onPause()
  67. */
  68. SDL_EVENT_WILL_ENTER_FOREGROUND, /**< The application is about to enter the foreground
  69. Called on iOS in applicationWillEnterForeground()
  70. Called on Android in onResume()
  71. */
  72. SDL_EVENT_DID_ENTER_FOREGROUND, /**< The application is now interactive
  73. Called on iOS in applicationDidBecomeActive()
  74. Called on Android in onResume()
  75. */
  76. SDL_EVENT_LOCALE_CHANGED, /**< The user's locale preferences have changed. */
  77. SDL_EVENT_SYSTEM_THEME_CHANGED, /**< The system theme changed */
  78. /* Display events */
  79. /* 0x150 was SDL_DISPLAYEVENT, reserve the number for sdl2-compat */
  80. SDL_EVENT_DISPLAY_ORIENTATION = 0x151, /**< Display orientation has changed to data1 */
  81. SDL_EVENT_DISPLAY_ADDED, /**< Display has been added to the system */
  82. SDL_EVENT_DISPLAY_REMOVED, /**< Display has been removed from the system */
  83. SDL_EVENT_DISPLAY_MOVED, /**< Display has changed position */
  84. SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, /**< Display has changed content scale */
  85. SDL_EVENT_DISPLAY_FIRST = SDL_EVENT_DISPLAY_ORIENTATION,
  86. SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED,
  87. /* Window events */
  88. /* 0x200 was SDL_WINDOWEVENT, reserve the number for sdl2-compat */
  89. SDL_EVENT_SYSWM = 0x201, /**< System specific event */
  90. SDL_EVENT_WINDOW_SHOWN, /**< Window has been shown */
  91. SDL_EVENT_WINDOW_HIDDEN, /**< Window has been hidden */
  92. SDL_EVENT_WINDOW_EXPOSED, /**< Window has been exposed and should be redrawn */
  93. SDL_EVENT_WINDOW_MOVED, /**< Window has been moved to data1, data2 */
  94. SDL_EVENT_WINDOW_RESIZED, /**< Window has been resized to data1xdata2 */
  95. SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED,/**< The pixel size of the window has changed to data1xdata2 */
  96. SDL_EVENT_WINDOW_MINIMIZED, /**< Window has been minimized */
  97. SDL_EVENT_WINDOW_MAXIMIZED, /**< Window has been maximized */
  98. SDL_EVENT_WINDOW_RESTORED, /**< Window has been restored to normal size and position */
  99. SDL_EVENT_WINDOW_MOUSE_ENTER, /**< Window has gained mouse focus */
  100. SDL_EVENT_WINDOW_MOUSE_LEAVE, /**< Window has lost mouse focus */
  101. SDL_EVENT_WINDOW_FOCUS_GAINED, /**< Window has gained keyboard focus */
  102. SDL_EVENT_WINDOW_FOCUS_LOST, /**< Window has lost keyboard focus */
  103. SDL_EVENT_WINDOW_CLOSE_REQUESTED, /**< The window manager requests that the window be closed */
  104. SDL_EVENT_WINDOW_TAKE_FOCUS, /**< Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) */
  105. SDL_EVENT_WINDOW_HIT_TEST, /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL */
  106. SDL_EVENT_WINDOW_ICCPROF_CHANGED, /**< The ICC profile of the window's display has changed */
  107. SDL_EVENT_WINDOW_DISPLAY_CHANGED, /**< Window has been moved to display data1 */
  108. SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED, /**< Window display scale has been changed */
  109. SDL_EVENT_WINDOW_OCCLUDED, /**< The window has been occluded */
  110. SDL_EVENT_WINDOW_DESTROYED, /**< The window with the associated ID is being or has been destroyed. If this message is being handled
  111. in an event watcher, the window handle is still valid and can still be used to retrieve any userdata
  112. associated with the window. Otherwise, the handle has already been destroyed and all resources
  113. associated with it are invalid */
  114. SDL_EVENT_WINDOW_FIRST = SDL_EVENT_WINDOW_SHOWN,
  115. SDL_EVENT_WINDOW_LAST = SDL_EVENT_WINDOW_DESTROYED,
  116. /* Keyboard events */
  117. SDL_EVENT_KEY_DOWN = 0x300, /**< Key pressed */
  118. SDL_EVENT_KEY_UP, /**< Key released */
  119. SDL_EVENT_TEXT_EDITING, /**< Keyboard text editing (composition) */
  120. SDL_EVENT_TEXT_INPUT, /**< Keyboard text input */
  121. SDL_EVENT_KEYMAP_CHANGED, /**< Keymap changed due to a system event such as an
  122. input language or keyboard layout change. */
  123. /* Mouse events */
  124. SDL_EVENT_MOUSE_MOTION = 0x400, /**< Mouse moved */
  125. SDL_EVENT_MOUSE_BUTTON_DOWN, /**< Mouse button pressed */
  126. SDL_EVENT_MOUSE_BUTTON_UP, /**< Mouse button released */
  127. SDL_EVENT_MOUSE_WHEEL, /**< Mouse wheel motion */
  128. /* Joystick events */
  129. SDL_EVENT_JOYSTICK_AXIS_MOTION = 0x600, /**< Joystick axis motion */
  130. SDL_EVENT_JOYSTICK_HAT_MOTION = 0x602, /**< Joystick hat position change */
  131. SDL_EVENT_JOYSTICK_BUTTON_DOWN, /**< Joystick button pressed */
  132. SDL_EVENT_JOYSTICK_BUTTON_UP, /**< Joystick button released */
  133. SDL_EVENT_JOYSTICK_ADDED, /**< A new joystick has been inserted into the system */
  134. SDL_EVENT_JOYSTICK_REMOVED, /**< An opened joystick has been removed */
  135. SDL_EVENT_JOYSTICK_BATTERY_UPDATED, /**< Joystick battery level change */
  136. SDL_EVENT_JOYSTICK_UPDATE_COMPLETE, /**< Joystick update is complete */
  137. /* Gamepad events */
  138. SDL_EVENT_GAMEPAD_AXIS_MOTION = 0x650, /**< Gamepad axis motion */
  139. SDL_EVENT_GAMEPAD_BUTTON_DOWN, /**< Gamepad button pressed */
  140. SDL_EVENT_GAMEPAD_BUTTON_UP, /**< Gamepad button released */
  141. SDL_EVENT_GAMEPAD_ADDED, /**< A new gamepad has been inserted into the system */
  142. SDL_EVENT_GAMEPAD_REMOVED, /**< An opened gamepad has been removed */
  143. SDL_EVENT_GAMEPAD_REMAPPED, /**< The gamepad mapping was updated */
  144. SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN, /**< Gamepad touchpad was touched */
  145. SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION, /**< Gamepad touchpad finger was moved */
  146. SDL_EVENT_GAMEPAD_TOUCHPAD_UP, /**< Gamepad touchpad finger was lifted */
  147. SDL_EVENT_GAMEPAD_SENSOR_UPDATE, /**< Gamepad sensor was updated */
  148. SDL_EVENT_GAMEPAD_UPDATE_COMPLETE, /**< Gamepad update is complete */
  149. /* Touch events */
  150. SDL_EVENT_FINGER_DOWN = 0x700,
  151. SDL_EVENT_FINGER_UP,
  152. SDL_EVENT_FINGER_MOTION,
  153. /* 0x800, 0x801, and 0x802 were the Gesture events from SDL2. Do not reuse these values! sdl2-compat needs them! */
  154. /* Clipboard events */
  155. SDL_EVENT_CLIPBOARD_UPDATE = 0x900, /**< The clipboard or primary selection changed */
  156. /* Drag and drop events */
  157. SDL_EVENT_DROP_FILE = 0x1000, /**< The system requests a file open */
  158. SDL_EVENT_DROP_TEXT, /**< text/plain drag-and-drop event */
  159. SDL_EVENT_DROP_BEGIN, /**< A new set of drops is beginning (NULL filename) */
  160. SDL_EVENT_DROP_COMPLETE, /**< Current set of drops is now complete (NULL filename) */
  161. SDL_EVENT_DROP_POSITION, /**< Position while moving over the window */
  162. /* Audio hotplug events */
  163. SDL_EVENT_AUDIO_DEVICE_ADDED = 0x1100, /**< A new audio device is available */
  164. SDL_EVENT_AUDIO_DEVICE_REMOVED, /**< An audio device has been removed. */
  165. SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED, /**< An audio device's format has been changed by the system. */
  166. /* Sensor events */
  167. SDL_EVENT_SENSOR_UPDATE = 0x1200, /**< A sensor was updated */
  168. /* Render events */
  169. SDL_EVENT_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
  170. SDL_EVENT_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
  171. /* Internal events */
  172. SDL_EVENT_POLL_SENTINEL = 0x7F00, /**< Signals the end of an event poll cycle */
  173. /** Events ::SDL_EVENT_USER through ::SDL_EVENT_LAST are for your use,
  174. * and should be allocated with SDL_RegisterEvents()
  175. */
  176. SDL_EVENT_USER = 0x8000,
  177. /**
  178. * This last event is only for bounding internal arrays
  179. */
  180. SDL_EVENT_LAST = 0xFFFF
  181. } SDL_EventType;
  182. /**
  183. * \brief Fields shared by every event
  184. */
  185. typedef struct SDL_CommonEvent
  186. {
  187. Uint32 type;
  188. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  189. } SDL_CommonEvent;
  190. /**
  191. * \brief Display state change event data (event.display.*)
  192. */
  193. typedef struct SDL_DisplayEvent
  194. {
  195. Uint32 type; /**< ::SDL_DISPLAYEVENT_* */
  196. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  197. SDL_DisplayID displayID;/**< The associated display */
  198. Sint32 data1; /**< event dependent data */
  199. } SDL_DisplayEvent;
  200. /**
  201. * \brief Window state change event data (event.window.*)
  202. */
  203. typedef struct SDL_WindowEvent
  204. {
  205. Uint32 type; /**< ::SDL_WINDOWEVENT_* */
  206. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  207. SDL_WindowID windowID;/**< The associated window */
  208. Sint32 data1; /**< event dependent data */
  209. Sint32 data2; /**< event dependent data */
  210. } SDL_WindowEvent;
  211. /**
  212. * \brief Keyboard button event structure (event.key.*)
  213. */
  214. typedef struct SDL_KeyboardEvent
  215. {
  216. Uint32 type; /**< ::SDL_EVENT_KEY_DOWN or ::SDL_EVENT_KEY_UP */
  217. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  218. SDL_WindowID windowID;/**< The window with keyboard focus, if any */
  219. Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
  220. Uint8 repeat; /**< Non-zero if this is a key repeat */
  221. Uint8 padding2;
  222. Uint8 padding3;
  223. SDL_Keysym keysym; /**< The key that was pressed or released */
  224. } SDL_KeyboardEvent;
  225. #define SDL_TEXTEDITINGEVENT_TEXT_SIZE 64
  226. /**
  227. * \brief Keyboard text editing event structure (event.edit.*)
  228. *
  229. * \note This event should be cleaned up with SDL_CleanupEvent() after processing.
  230. */
  231. typedef struct SDL_TextEditingEvent
  232. {
  233. Uint32 type; /**< ::SDL_EVENT_TEXT_EDITING */
  234. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  235. SDL_WindowID windowID; /**< The window with keyboard focus, if any */
  236. char *text; /**< The editing text */
  237. char short_text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< Memory space for short editing text, use 'text' instead */
  238. Sint32 start; /**< The start cursor of selected editing text */
  239. Sint32 length; /**< The length of selected editing text */
  240. } SDL_TextEditingEvent;
  241. #define SDL_TEXTINPUTEVENT_TEXT_SIZE 64
  242. /**
  243. * \brief Keyboard text input event structure (event.text.*)
  244. *
  245. * \note This event should be cleaned up with SDL_CleanupEvent() after processing.
  246. */
  247. typedef struct SDL_TextInputEvent
  248. {
  249. Uint32 type; /**< ::SDL_EVENT_TEXT_INPUT */
  250. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  251. SDL_WindowID windowID; /**< The window with keyboard focus, if any */
  252. char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */
  253. } SDL_TextInputEvent;
  254. /**
  255. * \brief Mouse motion event structure (event.motion.*)
  256. */
  257. typedef struct SDL_MouseMotionEvent
  258. {
  259. Uint32 type; /**< ::SDL_EVENT_MOUSE_MOTION */
  260. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  261. SDL_WindowID windowID;/**< The window with mouse focus, if any */
  262. SDL_MouseID which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
  263. Uint32 state; /**< The current button state */
  264. float x; /**< X coordinate, relative to window */
  265. float y; /**< Y coordinate, relative to window */
  266. float xrel; /**< The relative motion in the X direction */
  267. float yrel; /**< The relative motion in the Y direction */
  268. } SDL_MouseMotionEvent;
  269. /**
  270. * \brief Mouse button event structure (event.button.*)
  271. */
  272. typedef struct SDL_MouseButtonEvent
  273. {
  274. Uint32 type; /**< ::SDL_EVENT_MOUSE_BUTTON_DOWN or ::SDL_EVENT_MOUSE_BUTTON_UP */
  275. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  276. SDL_WindowID windowID;/**< The window with mouse focus, if any */
  277. SDL_MouseID which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
  278. Uint8 button; /**< The mouse button index */
  279. Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
  280. Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
  281. Uint8 padding;
  282. float x; /**< X coordinate, relative to window */
  283. float y; /**< Y coordinate, relative to window */
  284. } SDL_MouseButtonEvent;
  285. /**
  286. * \brief Mouse wheel event structure (event.wheel.*)
  287. */
  288. typedef struct SDL_MouseWheelEvent
  289. {
  290. Uint32 type; /**< ::SDL_EVENT_MOUSE_WHEEL */
  291. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  292. SDL_WindowID windowID;/**< The window with mouse focus, if any */
  293. SDL_MouseID which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
  294. float x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
  295. float 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. float mouseX; /**< X coordinate, relative to window */
  298. float mouseY; /**< Y coordinate, relative to window */
  299. } SDL_MouseWheelEvent;
  300. /**
  301. * \brief Joystick axis motion event structure (event.jaxis.*)
  302. */
  303. typedef struct SDL_JoyAxisEvent
  304. {
  305. Uint32 type; /**< ::SDL_EVENT_JOYSTICK_AXIS_MOTION */
  306. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  307. SDL_JoystickID which; /**< The joystick instance id */
  308. Uint8 axis; /**< The joystick axis index */
  309. Uint8 padding1;
  310. Uint8 padding2;
  311. Uint8 padding3;
  312. Sint16 value; /**< The axis value (range: -32768 to 32767) */
  313. Uint16 padding4;
  314. } SDL_JoyAxisEvent;
  315. /**
  316. * \brief Joystick hat position change event structure (event.jhat.*)
  317. */
  318. typedef struct SDL_JoyHatEvent
  319. {
  320. Uint32 type; /**< ::SDL_EVENT_JOYSTICK_HAT_MOTION */
  321. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  322. SDL_JoystickID which; /**< The joystick instance id */
  323. Uint8 hat; /**< The joystick hat index */
  324. Uint8 value; /**< The hat position value.
  325. * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
  326. * \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
  327. * \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
  328. *
  329. * Note that zero means the POV is centered.
  330. */
  331. Uint8 padding1;
  332. Uint8 padding2;
  333. } SDL_JoyHatEvent;
  334. /**
  335. * \brief Joystick button event structure (event.jbutton.*)
  336. */
  337. typedef struct SDL_JoyButtonEvent
  338. {
  339. Uint32 type; /**< ::SDL_EVENT_JOYSTICK_BUTTON_DOWN or ::SDL_EVENT_JOYSTICK_BUTTON_UP */
  340. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  341. SDL_JoystickID which; /**< The joystick instance id */
  342. Uint8 button; /**< The joystick button index */
  343. Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
  344. Uint8 padding1;
  345. Uint8 padding2;
  346. } SDL_JoyButtonEvent;
  347. /**
  348. * \brief Joystick device event structure (event.jdevice.*)
  349. */
  350. typedef struct SDL_JoyDeviceEvent
  351. {
  352. Uint32 type; /**< ::SDL_EVENT_JOYSTICK_ADDED or ::SDL_EVENT_JOYSTICK_REMOVED or ::SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */
  353. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  354. SDL_JoystickID which; /**< The joystick instance id */
  355. } SDL_JoyDeviceEvent;
  356. /**
  357. * \brief Joysick battery level change event structure (event.jbattery.*)
  358. */
  359. typedef struct SDL_JoyBatteryEvent
  360. {
  361. Uint32 type; /**< ::SDL_EVENT_JOYSTICK_BATTERY_UPDATED */
  362. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  363. SDL_JoystickID which; /**< The joystick instance id */
  364. SDL_JoystickPowerLevel level; /**< The joystick battery level */
  365. } SDL_JoyBatteryEvent;
  366. /**
  367. * \brief Gamepad axis motion event structure (event.gaxis.*)
  368. */
  369. typedef struct SDL_GamepadAxisEvent
  370. {
  371. Uint32 type; /**< ::SDL_EVENT_GAMEPAD_AXIS_MOTION */
  372. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  373. SDL_JoystickID which; /**< The joystick instance id */
  374. Uint8 axis; /**< The gamepad axis (SDL_GamepadAxis) */
  375. Uint8 padding1;
  376. Uint8 padding2;
  377. Uint8 padding3;
  378. Sint16 value; /**< The axis value (range: -32768 to 32767) */
  379. Uint16 padding4;
  380. } SDL_GamepadAxisEvent;
  381. /**
  382. * \brief Gamepad button event structure (event.gbutton.*)
  383. */
  384. typedef struct SDL_GamepadButtonEvent
  385. {
  386. Uint32 type; /**< ::SDL_EVENT_GAMEPAD_BUTTON_DOWN or ::SDL_EVENT_GAMEPAD_BUTTON_UP */
  387. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  388. SDL_JoystickID which; /**< The joystick instance id */
  389. Uint8 button; /**< The gamepad button (SDL_GamepadButton) */
  390. Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
  391. Uint8 padding1;
  392. Uint8 padding2;
  393. } SDL_GamepadButtonEvent;
  394. /**
  395. * \brief Gamepad device event structure (event.gdevice.*)
  396. */
  397. typedef struct SDL_GamepadDeviceEvent
  398. {
  399. Uint32 type; /**< ::SDL_EVENT_GAMEPAD_ADDED, ::SDL_EVENT_GAMEPAD_REMOVED, or ::SDL_EVENT_GAMEPAD_REMAPPED or ::SDL_EVENT_GAMEPAD_UPDATE_COMPLETE */
  400. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  401. SDL_JoystickID which; /**< The joystick instance id */
  402. } SDL_GamepadDeviceEvent;
  403. /**
  404. * \brief Gamepad touchpad event structure (event.gtouchpad.*)
  405. */
  406. typedef struct SDL_GamepadTouchpadEvent
  407. {
  408. Uint32 type; /**< ::SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or ::SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or ::SDL_EVENT_GAMEPAD_TOUCHPAD_UP */
  409. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  410. SDL_JoystickID which; /**< The joystick instance id */
  411. Sint32 touchpad; /**< The index of the touchpad */
  412. Sint32 finger; /**< The index of the finger on the touchpad */
  413. float x; /**< Normalized in the range 0...1 with 0 being on the left */
  414. float y; /**< Normalized in the range 0...1 with 0 being at the top */
  415. float pressure; /**< Normalized in the range 0...1 */
  416. } SDL_GamepadTouchpadEvent;
  417. /**
  418. * \brief Gamepad sensor event structure (event.gsensor.*)
  419. */
  420. typedef struct SDL_GamepadSensorEvent
  421. {
  422. Uint32 type; /**< ::SDL_EVENT_GAMEPAD_SENSOR_UPDATE */
  423. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  424. SDL_JoystickID which; /**< The joystick instance id */
  425. Sint32 sensor; /**< The type of the sensor, one of the values of ::SDL_SensorType */
  426. float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */
  427. Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
  428. } SDL_GamepadSensorEvent;
  429. /**
  430. * \brief Audio device event structure (event.adevice.*)
  431. */
  432. typedef struct SDL_AudioDeviceEvent
  433. {
  434. Uint32 type; /**< ::SDL_EVENT_AUDIO_DEVICE_ADDED, or ::SDL_EVENT_AUDIO_DEVICE_REMOVED, or ::SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED */
  435. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  436. SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */
  437. Uint8 iscapture; /**< zero if an output device, non-zero if a capture device. */
  438. Uint8 padding1;
  439. Uint8 padding2;
  440. Uint8 padding3;
  441. } SDL_AudioDeviceEvent;
  442. /**
  443. * \brief Touch finger event structure (event.tfinger.*)
  444. */
  445. typedef struct SDL_TouchFingerEvent
  446. {
  447. Uint32 type; /**< ::SDL_EVENT_FINGER_MOTION or ::SDL_EVENT_FINGER_DOWN or ::SDL_EVENT_FINGER_UP */
  448. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  449. SDL_TouchID touchId; /**< The touch device id */
  450. SDL_FingerID fingerId;
  451. float x; /**< Normalized in the range 0...1 */
  452. float y; /**< Normalized in the range 0...1 */
  453. float dx; /**< Normalized in the range -1...1 */
  454. float dy; /**< Normalized in the range -1...1 */
  455. float pressure; /**< Normalized in the range 0...1 */
  456. SDL_WindowID windowID;/**< The window underneath the finger, if any */
  457. } SDL_TouchFingerEvent;
  458. #define SDL_DROPEVENT_DATA_SIZE 64
  459. /**
  460. * \brief An event used to drop text or request a file open by the system (event.drop.*)
  461. *
  462. * \note This event should be cleaned up with SDL_CleanupEvent() after processing.
  463. */
  464. typedef struct SDL_DropEvent
  465. {
  466. Uint32 type; /**< ::SDL_EVENT_DROP_BEGIN or ::SDL_EVENT_DROP_FILE or ::SDL_EVENT_DROP_TEXT or ::SDL_EVENT_DROP_COMPLETE or ::SDL_EVENT_DROP_POSITION */
  467. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  468. SDL_WindowID windowID; /**< The window that was dropped on, if any */
  469. float x; /**< X coordinate, relative to window (not on begin) */
  470. float y; /**< Y coordinate, relative to window (not on begin) */
  471. char *data; /**< The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events */
  472. char short_data[SDL_DROPEVENT_DATA_SIZE]; /**< Memory space for short data, use 'data' instead */
  473. } SDL_DropEvent;
  474. /**
  475. * \brief An event triggered when the clipboard contents have changed (event.clipboard.*)
  476. */
  477. typedef struct SDL_ClipboardEvent
  478. {
  479. Uint32 type; /**< ::SDL_EVENT_CLIPBOARD_UPDATE */
  480. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  481. } SDL_ClipboardEvent;
  482. /**
  483. * \brief Sensor event structure (event.sensor.*)
  484. */
  485. typedef struct SDL_SensorEvent
  486. {
  487. Uint32 type; /**< ::SDL_EVENT_SENSOR_UPDATE */
  488. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  489. SDL_SensorID which; /**< The instance ID of the sensor */
  490. float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_GetSensorData() */
  491. Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
  492. } SDL_SensorEvent;
  493. /**
  494. * \brief The "quit requested" event
  495. */
  496. typedef struct SDL_QuitEvent
  497. {
  498. Uint32 type; /**< ::SDL_EVENT_QUIT */
  499. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  500. } SDL_QuitEvent;
  501. /**
  502. * \brief OS Specific event
  503. */
  504. typedef struct SDL_OSEvent
  505. {
  506. Uint32 type; /**< ::SDL_EVENT_QUIT */
  507. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  508. } SDL_OSEvent;
  509. /**
  510. * \brief A user-defined event type (event.user.*)
  511. */
  512. typedef struct SDL_UserEvent
  513. {
  514. Uint32 type; /**< ::SDL_EVENT_USER through ::SDL_EVENT_LAST-1 */
  515. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  516. SDL_WindowID windowID;/**< The associated window if any */
  517. Sint32 code; /**< User defined event code */
  518. void *data1; /**< User defined data pointer */
  519. void *data2; /**< User defined data pointer */
  520. } SDL_UserEvent;
  521. struct SDL_SysWMmsg;
  522. typedef struct SDL_SysWMmsg SDL_SysWMmsg;
  523. /**
  524. * \brief A video driver dependent system event (event.syswm.*)
  525. * This event is disabled by default, you can enable it with SDL_SetEventEnabled()
  526. *
  527. * \note This event should be cleaned up with SDL_CleanupEvent() after processing.
  528. *
  529. * \note If you want to use this event, you should include SDL_syswm.h.
  530. */
  531. typedef struct SDL_SysWMEvent
  532. {
  533. Uint32 type; /**< ::SDL_EVENT_SYSWM */
  534. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  535. SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */
  536. } SDL_SysWMEvent;
  537. /**
  538. * \brief General event structure
  539. */
  540. typedef union SDL_Event
  541. {
  542. Uint32 type; /**< Event type, shared with all events */
  543. SDL_CommonEvent common; /**< Common event data */
  544. SDL_DisplayEvent display; /**< Display event data */
  545. SDL_WindowEvent window; /**< Window event data */
  546. SDL_KeyboardEvent key; /**< Keyboard event data */
  547. SDL_TextEditingEvent edit; /**< Text editing event data */
  548. SDL_TextInputEvent text; /**< Text input event data */
  549. SDL_MouseMotionEvent motion; /**< Mouse motion event data */
  550. SDL_MouseButtonEvent button; /**< Mouse button event data */
  551. SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
  552. SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
  553. SDL_JoyHatEvent jhat; /**< Joystick hat event data */
  554. SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
  555. SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
  556. SDL_JoyBatteryEvent jbattery; /**< Joystick battery event data */
  557. SDL_GamepadAxisEvent gaxis; /**< Gamepad axis event data */
  558. SDL_GamepadButtonEvent gbutton; /**< Gamepad button event data */
  559. SDL_GamepadDeviceEvent gdevice; /**< Gamepad device event data */
  560. SDL_GamepadTouchpadEvent gtouchpad; /**< Gamepad touchpad event data */
  561. SDL_GamepadSensorEvent gsensor; /**< Gamepad sensor event data */
  562. SDL_AudioDeviceEvent adevice; /**< Audio device event data */
  563. SDL_SensorEvent sensor; /**< Sensor event data */
  564. SDL_QuitEvent quit; /**< Quit request event data */
  565. SDL_UserEvent user; /**< Custom event data */
  566. SDL_SysWMEvent syswm; /**< System dependent window event data */
  567. SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
  568. SDL_DropEvent drop; /**< Drag and drop event data */
  569. SDL_ClipboardEvent clipboard; /**< Clipboard cancelled event data */
  570. /* This is necessary for ABI compatibility between Visual C++ and GCC.
  571. Visual C++ will respect the push pack pragma and use 52 bytes (size of
  572. SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit
  573. architectures) for this union, and GCC will use the alignment of the
  574. largest datatype within the union, which is 8 bytes on 64-bit
  575. architectures.
  576. So... we'll add padding to force the size to be 56 bytes for both.
  577. On architectures where pointers are 16 bytes, this needs rounding up to
  578. the next multiple of 16, 64, and on architectures where pointers are
  579. even larger the size of SDL_UserEvent will dominate as being 3 pointers.
  580. */
  581. Uint8 padding[128];
  582. } SDL_Event;
  583. /* Make sure we haven't broken binary compatibility */
  584. SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == sizeof(((SDL_Event *)NULL)->padding));
  585. /* Function prototypes */
  586. /**
  587. * Pump the event loop, gathering events from the input devices.
  588. *
  589. * This function updates the event queue and internal input device state.
  590. *
  591. * **WARNING**: This should only be run in the thread that initialized the
  592. * video subsystem, and for extra safety, you should consider only doing those
  593. * things on the main thread in any case.
  594. *
  595. * SDL_PumpEvents() gathers all the pending input information from devices and
  596. * places it in the event queue. Without calls to SDL_PumpEvents() no events
  597. * would ever be placed on the queue. Often the need for calls to
  598. * SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and
  599. * SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not
  600. * polling or waiting for events (e.g. you are filtering them), then you must
  601. * call SDL_PumpEvents() to force an event queue update.
  602. *
  603. * \since This function is available since SDL 3.0.0.
  604. *
  605. * \sa SDL_PollEvent
  606. * \sa SDL_WaitEvent
  607. */
  608. extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
  609. /* @{ */
  610. typedef enum
  611. {
  612. SDL_ADDEVENT,
  613. SDL_PEEKEVENT,
  614. SDL_GETEVENT
  615. } SDL_eventaction;
  616. /**
  617. * Check the event queue for messages and optionally return them.
  618. *
  619. * `action` may be any of the following:
  620. *
  621. * - `SDL_ADDEVENT`: up to `numevents` events will be added to the back of the
  622. * event queue.
  623. * - `SDL_PEEKEVENT`: `numevents` events at the front of the event queue,
  624. * within the specified minimum and maximum type, will be returned to the
  625. * caller and will _not_ be removed from the queue.
  626. * - `SDL_GETEVENT`: up to `numevents` events at the front of the event queue,
  627. * within the specified minimum and maximum type, will be returned to the
  628. * caller and will be removed from the queue.
  629. *
  630. * You may have to call SDL_PumpEvents() before calling this function.
  631. * Otherwise, the events may not be ready to be filtered when you call
  632. * SDL_PeepEvents().
  633. *
  634. * This function is thread-safe.
  635. *
  636. * \param events destination buffer for the retrieved events
  637. * \param numevents if action is SDL_ADDEVENT, the number of events to add
  638. * back to the event queue; if action is SDL_PEEKEVENT or
  639. * SDL_GETEVENT, the maximum number of events to retrieve
  640. * \param action action to take; see [[#action|Remarks]] for details
  641. * \param minType minimum value of the event type to be considered;
  642. * SDL_EVENT_FIRST is a safe choice
  643. * \param maxType maximum value of the event type to be considered;
  644. * SDL_EVENT_LAST is a safe choice
  645. * \returns the number of events actually stored or a negative error code on
  646. * failure; call SDL_GetError() for more information.
  647. *
  648. * \since This function is available since SDL 3.0.0.
  649. *
  650. * \sa SDL_PollEvent
  651. * \sa SDL_PumpEvents
  652. * \sa SDL_PushEvent
  653. */
  654. extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, Uint32 minType, Uint32 maxType);
  655. /* @} */
  656. /**
  657. * Check for the existence of a certain event type in the event queue.
  658. *
  659. * If you need to check for a range of event types, use SDL_HasEvents()
  660. * instead.
  661. *
  662. * \param type the type of event to be queried; see SDL_EventType for details
  663. * \returns SDL_TRUE if events matching `type` are present, or SDL_FALSE if
  664. * events matching `type` are not present.
  665. *
  666. * \since This function is available since SDL 3.0.0.
  667. *
  668. * \sa SDL_HasEvents
  669. */
  670. extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
  671. /**
  672. * Check for the existence of certain event types in the event queue.
  673. *
  674. * If you need to check for a single event type, use SDL_HasEvent() instead.
  675. *
  676. * \param minType the low end of event type to be queried, inclusive; see
  677. * SDL_EventType for details
  678. * \param maxType the high end of event type to be queried, inclusive; see
  679. * SDL_EventType for details
  680. * \returns SDL_TRUE if events with type >= `minType` and <= `maxType` are
  681. * present, or SDL_FALSE if not.
  682. *
  683. * \since This function is available since SDL 3.0.0.
  684. *
  685. * \sa SDL_HasEvents
  686. */
  687. extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
  688. /**
  689. * Clear events of a specific type from the event queue.
  690. *
  691. * This will unconditionally remove any events from the queue that match
  692. * `type`. If you need to remove a range of event types, use SDL_FlushEvents()
  693. * instead.
  694. *
  695. * It's also normal to just ignore events you don't care about in your event
  696. * loop without calling this function.
  697. *
  698. * This function only affects currently queued events. If you want to make
  699. * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
  700. * on the main thread immediately before the flush call.
  701. *
  702. * \param type the type of event to be cleared; see SDL_EventType for details
  703. *
  704. * \since This function is available since SDL 3.0.0.
  705. *
  706. * \sa SDL_FlushEvents
  707. */
  708. extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
  709. /**
  710. * Clear events of a range of types from the event queue.
  711. *
  712. * This will unconditionally remove any events from the queue that are in the
  713. * range of `minType` to `maxType`, inclusive. If you need to remove a single
  714. * event type, use SDL_FlushEvent() instead.
  715. *
  716. * It's also normal to just ignore events you don't care about in your event
  717. * loop without calling this function.
  718. *
  719. * This function only affects currently queued events. If you want to make
  720. * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
  721. * on the main thread immediately before the flush call.
  722. *
  723. * \param minType the low end of event type to be cleared, inclusive; see
  724. * SDL_EventType for details
  725. * \param maxType the high end of event type to be cleared, inclusive; see
  726. * SDL_EventType for details
  727. *
  728. * \since This function is available since SDL 3.0.0.
  729. *
  730. * \sa SDL_FlushEvent
  731. */
  732. extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
  733. /**
  734. * Poll for currently pending events.
  735. *
  736. * If `event` is not NULL, the next event is removed from the queue and stored
  737. * in the SDL_Event structure pointed to by `event`. The 1 returned refers to
  738. * this event, immediately stored in the SDL Event structure -- not an event
  739. * to follow.
  740. *
  741. * If `event` is NULL, it simply returns 1 if there is an event in the queue,
  742. * but will not remove it from the queue.
  743. *
  744. * As this function may implicitly call SDL_PumpEvents(), you can only call
  745. * this function in the thread that set the video mode.
  746. *
  747. * SDL_PollEvent() is the favored way of receiving system events since it can
  748. * be done from the main loop and does not suspend the main loop while waiting
  749. * on an event to be posted.
  750. *
  751. * The common practice is to fully process the event queue once every frame,
  752. * usually as a first step before updating the game's state:
  753. *
  754. * ```c
  755. * while (game_is_still_running) {
  756. * SDL_Event event;
  757. * while (SDL_PollEvent(&event)) { // poll until all events are handled!
  758. * // decide what to do with this event.
  759. * }
  760. *
  761. * // update game state, draw the current frame
  762. * }
  763. * ```
  764. *
  765. * \param event the SDL_Event structure to be filled with the next event from
  766. * the queue, or NULL
  767. * \returns SDL_TRUE if this got an event or SDL_FALSE if there are none
  768. * available.
  769. *
  770. * \since This function is available since SDL 3.0.0.
  771. *
  772. * \sa SDL_CleanupEvent
  773. * \sa SDL_PushEvent
  774. * \sa SDL_WaitEvent
  775. * \sa SDL_WaitEventTimeout
  776. */
  777. extern DECLSPEC SDL_bool SDLCALL SDL_PollEvent(SDL_Event *event);
  778. /**
  779. * Wait indefinitely for the next available event.
  780. *
  781. * If `event` is not NULL, the next event is removed from the queue and stored
  782. * in the SDL_Event structure pointed to by `event`.
  783. *
  784. * As this function may implicitly call SDL_PumpEvents(), you can only call
  785. * this function in the thread that initialized the video subsystem.
  786. *
  787. * \param event the SDL_Event structure to be filled in with the next event
  788. * from the queue, or NULL
  789. * \returns SDL_TRUE on success or SDL_FALSE if there was an error while
  790. * waiting for events; call SDL_GetError() for more information.
  791. *
  792. * \since This function is available since SDL 3.0.0.
  793. *
  794. * \sa SDL_CleanupEvent
  795. * \sa SDL_PollEvent
  796. * \sa SDL_PushEvent
  797. * \sa SDL_WaitEventTimeout
  798. */
  799. extern DECLSPEC SDL_bool SDLCALL SDL_WaitEvent(SDL_Event *event);
  800. /**
  801. * Wait until the specified timeout (in milliseconds) for the next available
  802. * event.
  803. *
  804. * If `event` is not NULL, the next event is removed from the queue and stored
  805. * in the SDL_Event structure pointed to by `event`.
  806. *
  807. * As this function may implicitly call SDL_PumpEvents(), you can only call
  808. * this function in the thread that initialized the video subsystem.
  809. *
  810. * The timeout is not guaranteed, the actual wait time could be longer due to
  811. * system scheduling.
  812. *
  813. * \param event the SDL_Event structure to be filled in with the next event
  814. * from the queue, or NULL
  815. * \param timeoutMS the maximum number of milliseconds to wait for the next
  816. * available event
  817. * \returns SDL_TRUE if this got an event or SDL_FALSE if the timeout elapsed
  818. * without any events available.
  819. *
  820. * \since This function is available since SDL 3.0.0.
  821. *
  822. * \sa SDL_CleanupEvent
  823. * \sa SDL_PollEvent
  824. * \sa SDL_PushEvent
  825. * \sa SDL_WaitEvent
  826. */
  827. extern DECLSPEC SDL_bool SDLCALL SDL_WaitEventTimeout(SDL_Event *event, Sint32 timeoutMS);
  828. /**
  829. * Clean up dynamically allocated memory for an event.
  830. *
  831. * Some events have dynamically allocated data that must be cleaned up when the event is processed. If you handle any of these events, you should call SDL_CleanupEvent() after processing them:
  832. * SDL_EVENT_DROP_FILE
  833. * SDL_EVENT_DROP_TEXT
  834. * SDL_EVENT_SYSWM
  835. * SDL_EVENT_TEXT_EDITING
  836. *
  837. * It is safe, but not necessary, to call this function for other event types.
  838. *
  839. * \param event a pointer to the event that should be cleaned up
  840. *
  841. * \since This function is available since SDL 3.0.0.
  842. *
  843. * \sa SDL_PollEvent
  844. * \sa SDL_WaitEvent
  845. * \sa SDL_WaitEventTimeout
  846. */
  847. extern DECLSPEC void SDLCALL SDL_CleanupEvent(SDL_Event *event);
  848. /**
  849. * Add an event to the event queue.
  850. *
  851. * The event queue can actually be used as a two way communication channel.
  852. * Not only can events be read from the queue, but the user can also push
  853. * their own events onto it. `event` is a pointer to the event structure you
  854. * wish to push onto the queue. The event is copied into the queue, and the
  855. * caller may dispose of the memory pointed to after SDL_PushEvent() returns.
  856. *
  857. * Note: Pushing device input events onto the queue doesn't modify the state
  858. * of the device within SDL.
  859. *
  860. * This function is thread-safe, and can be called from other threads safely.
  861. *
  862. * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
  863. * the event filter but events added with SDL_PeepEvents() do not.
  864. *
  865. * For pushing application-specific events, please use SDL_RegisterEvents() to
  866. * get an event type that does not conflict with other code that also wants
  867. * its own custom event types.
  868. *
  869. * \param event the SDL_Event to be added to the queue
  870. * \returns 1 on success, 0 if the event was filtered, or a negative error
  871. * code on failure; call SDL_GetError() for more information. A
  872. * common reason for error is the event queue being full.
  873. *
  874. * \since This function is available since SDL 3.0.0.
  875. *
  876. * \sa SDL_PeepEvents
  877. * \sa SDL_PollEvent
  878. * \sa SDL_RegisterEvents
  879. */
  880. extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event);
  881. /**
  882. * A function pointer used for callbacks that watch the event queue.
  883. *
  884. * \param userdata what was passed as `userdata` to SDL_SetEventFilter()
  885. * or SDL_AddEventWatch, etc
  886. * \param event the event that triggered the callback
  887. * \returns 1 to permit event to be added to the queue, and 0 to disallow
  888. * it. When used with SDL_AddEventWatch, the return value is ignored.
  889. *
  890. * \sa SDL_SetEventFilter
  891. * \sa SDL_AddEventWatch
  892. */
  893. typedef int (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
  894. /**
  895. * Set up a filter to process all events before they change internal state and
  896. * are posted to the internal event queue.
  897. *
  898. * If the filter function returns 1 when called, then the event will be added
  899. * to the internal queue. If it returns 0, then the event will be dropped from
  900. * the queue, but the internal state will still be updated. This allows
  901. * selective filtering of dynamically arriving events.
  902. *
  903. * **WARNING**: Be very careful of what you do in the event filter function,
  904. * as it may run in a different thread!
  905. *
  906. * On platforms that support it, if the quit event is generated by an
  907. * interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the
  908. * application at the next event poll.
  909. *
  910. * There is one caveat when dealing with the ::SDL_QuitEvent event type. The
  911. * event filter is only called when the window manager desires to close the
  912. * application window. If the event filter returns 1, then the window will be
  913. * closed, otherwise the window will remain open if possible.
  914. *
  915. * Note: Disabled events never make it to the event filter function; see
  916. * SDL_SetEventEnabled().
  917. *
  918. * Note: If you just want to inspect events without filtering, you should use
  919. * SDL_AddEventWatch() instead.
  920. *
  921. * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
  922. * the event filter, but events pushed onto the queue with SDL_PeepEvents() do
  923. * not.
  924. *
  925. * \param filter An SDL_EventFilter function to call when an event happens
  926. * \param userdata a pointer that is passed to `filter`
  927. *
  928. * \since This function is available since SDL 3.0.0.
  929. *
  930. * \sa SDL_AddEventWatch
  931. * \sa SDL_SetEventEnabled
  932. * \sa SDL_GetEventFilter
  933. * \sa SDL_PeepEvents
  934. * \sa SDL_PushEvent
  935. */
  936. extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter, void *userdata);
  937. /**
  938. * Query the current event filter.
  939. *
  940. * This function can be used to "chain" filters, by saving the existing filter
  941. * before replacing it with a function that will call that saved filter.
  942. *
  943. * \param filter the current callback function will be stored here
  944. * \param userdata the pointer that is passed to the current event filter will
  945. * be stored here
  946. * \returns SDL_TRUE on success or SDL_FALSE if there is no event filter set.
  947. *
  948. * \since This function is available since SDL 3.0.0.
  949. *
  950. * \sa SDL_SetEventFilter
  951. */
  952. extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata);
  953. /**
  954. * Add a callback to be triggered when an event is added to the event queue.
  955. *
  956. * `filter` will be called when an event happens, and its return value is
  957. * ignored.
  958. *
  959. * **WARNING**: Be very careful of what you do in the event filter function,
  960. * as it may run in a different thread!
  961. *
  962. * If the quit event is generated by a signal (e.g. SIGINT), it will bypass
  963. * the internal queue and be delivered to the watch callback immediately, and
  964. * arrive at the next event poll.
  965. *
  966. * Note: the callback is called for events posted by the user through
  967. * SDL_PushEvent(), but not for disabled events, nor for events by a filter
  968. * callback set with SDL_SetEventFilter(), nor for events posted by the user
  969. * through SDL_PeepEvents().
  970. *
  971. * \param filter an SDL_EventFilter function to call when an event happens.
  972. * \param userdata a pointer that is passed to `filter`
  973. * \returns 0 on success, or a negative error code on failure; call
  974. * SDL_GetError() for more information.
  975. *
  976. * \since This function is available since SDL 3.0.0.
  977. *
  978. * \sa SDL_DelEventWatch
  979. * \sa SDL_SetEventFilter
  980. */
  981. extern DECLSPEC int SDLCALL SDL_AddEventWatch(SDL_EventFilter filter, void *userdata);
  982. /**
  983. * Remove an event watch callback added with SDL_AddEventWatch().
  984. *
  985. * This function takes the same input as SDL_AddEventWatch() to identify and
  986. * delete the corresponding callback.
  987. *
  988. * \param filter the function originally passed to SDL_AddEventWatch()
  989. * \param userdata the pointer originally passed to SDL_AddEventWatch()
  990. *
  991. * \since This function is available since SDL 3.0.0.
  992. *
  993. * \sa SDL_AddEventWatch
  994. */
  995. extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter, void *userdata);
  996. /**
  997. * Run a specific filter function on the current event queue, removing any
  998. * events for which the filter returns 0.
  999. *
  1000. * See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(),
  1001. * this function does not change the filter permanently, it only uses the
  1002. * supplied filter until this function returns.
  1003. *
  1004. * \param filter the SDL_EventFilter function to call when an event happens
  1005. * \param userdata a pointer that is passed to `filter`
  1006. *
  1007. * \since This function is available since SDL 3.0.0.
  1008. *
  1009. * \sa SDL_GetEventFilter
  1010. * \sa SDL_SetEventFilter
  1011. */
  1012. extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter, void *userdata);
  1013. /**
  1014. * Set the state of processing events by type.
  1015. *
  1016. * \param type the type of event; see SDL_EventType for details
  1017. * \param enabled whether to process the event or not
  1018. *
  1019. * \since This function is available since SDL 3.0.0.
  1020. *
  1021. * \sa SDL_IsEventEnabled
  1022. */
  1023. extern DECLSPEC void SDLCALL SDL_SetEventEnabled(Uint32 type, SDL_bool enabled);
  1024. /**
  1025. * Query the state of processing events by type.
  1026. *
  1027. * \param type the type of event; see SDL_EventType for details
  1028. * \returns SDL_TRUE if the event is being processed, SDL_FALSE otherwise.
  1029. *
  1030. * \since This function is available since SDL 3.0.0.
  1031. *
  1032. * \sa SDL_SetEventEnabled
  1033. */
  1034. extern DECLSPEC SDL_bool SDLCALL SDL_EventEnabled(Uint32 type);
  1035. /**
  1036. * Allocate a set of user-defined events, and return the beginning event
  1037. * number for that set of events.
  1038. *
  1039. * Calling this function with `numevents` <= 0 is an error and will return
  1040. * (Uint32)-1.
  1041. *
  1042. * Note, (Uint32)-1 means the maximum unsigned 32-bit integer value (or
  1043. * 0xFFFFFFFF), but is clearer to write.
  1044. *
  1045. * \param numevents the number of events to be allocated
  1046. * \returns the beginning event number, or (Uint32)-1 if there are not enough
  1047. * user-defined events left.
  1048. *
  1049. * \since This function is available since SDL 3.0.0.
  1050. *
  1051. * \sa SDL_PushEvent
  1052. */
  1053. extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
  1054. /* Ends C function definitions when using C++ */
  1055. #ifdef __cplusplus
  1056. }
  1057. #endif
  1058. #include <SDL3/SDL_close_code.h>
  1059. #endif /* SDL_events_h_ */