SDL_events.h 57 KB

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