SDL_events.h 51 KB

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