SDL_events.h 46 KB

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