SDL_events.h 46 KB

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