SDL_events.h 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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, and can be redrawn directly from event watchers for this event */
  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, /**< A 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_EVENT_WINDOW_* */
  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. * This event will never be delivered unless text input is enabled by calling
  302. * SDL_StartTextInput(). Text input is disabled by default!
  303. *
  304. * \since This struct is available since SDL 3.0.0.
  305. *
  306. * \sa SDL_StartTextInput
  307. * \sa SDL_StopTextInput
  308. */
  309. typedef struct SDL_TextInputEvent
  310. {
  311. SDL_EventType type; /**< SDL_EVENT_TEXT_INPUT */
  312. Uint32 reserved;
  313. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  314. SDL_WindowID windowID; /**< The window with keyboard focus, if any */
  315. char *text; /**< The input text, UTF-8 encoded */
  316. } SDL_TextInputEvent;
  317. /**
  318. * Mouse device event structure (event.mdevice.*)
  319. *
  320. * \since This struct is available since SDL 3.0.0.
  321. */
  322. typedef struct SDL_MouseDeviceEvent
  323. {
  324. SDL_EventType type; /**< SDL_EVENT_MOUSE_ADDED or SDL_EVENT_MOUSE_REMOVED */
  325. Uint32 reserved;
  326. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  327. SDL_MouseID which; /**< The mouse instance id */
  328. } SDL_MouseDeviceEvent;
  329. /**
  330. * Mouse motion event structure (event.motion.*)
  331. *
  332. * \since This struct is available since SDL 3.0.0.
  333. */
  334. typedef struct SDL_MouseMotionEvent
  335. {
  336. SDL_EventType type; /**< SDL_EVENT_MOUSE_MOTION */
  337. Uint32 reserved;
  338. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  339. SDL_WindowID windowID; /**< The window with mouse focus, if any */
  340. SDL_MouseID which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */
  341. SDL_MouseButtonFlags state; /**< The current button state */
  342. float x; /**< X coordinate, relative to window */
  343. float y; /**< Y coordinate, relative to window */
  344. float xrel; /**< The relative motion in the X direction */
  345. float yrel; /**< The relative motion in the Y direction */
  346. } SDL_MouseMotionEvent;
  347. /**
  348. * Mouse button event structure (event.button.*)
  349. *
  350. * \since This struct is available since SDL 3.0.0.
  351. */
  352. typedef struct SDL_MouseButtonEvent
  353. {
  354. SDL_EventType type; /**< SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP */
  355. Uint32 reserved;
  356. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  357. SDL_WindowID windowID; /**< The window with mouse focus, if any */
  358. SDL_MouseID which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */
  359. Uint8 button; /**< The mouse button index */
  360. Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
  361. Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
  362. Uint8 padding;
  363. float x; /**< X coordinate, relative to window */
  364. float y; /**< Y coordinate, relative to window */
  365. } SDL_MouseButtonEvent;
  366. /**
  367. * Mouse wheel event structure (event.wheel.*)
  368. *
  369. * \since This struct is available since SDL 3.0.0.
  370. */
  371. typedef struct SDL_MouseWheelEvent
  372. {
  373. SDL_EventType type; /**< SDL_EVENT_MOUSE_WHEEL */
  374. Uint32 reserved;
  375. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  376. SDL_WindowID windowID; /**< The window with mouse focus, if any */
  377. SDL_MouseID which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */
  378. float x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
  379. float y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
  380. 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 */
  381. float mouse_x; /**< X coordinate, relative to window */
  382. float mouse_y; /**< Y coordinate, relative to window */
  383. } SDL_MouseWheelEvent;
  384. /**
  385. * Joystick axis motion event structure (event.jaxis.*)
  386. *
  387. * \since This struct is available since SDL 3.0.0.
  388. */
  389. typedef struct SDL_JoyAxisEvent
  390. {
  391. SDL_EventType type; /**< SDL_EVENT_JOYSTICK_AXIS_MOTION */
  392. Uint32 reserved;
  393. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  394. SDL_JoystickID which; /**< The joystick instance id */
  395. Uint8 axis; /**< The joystick axis index */
  396. Uint8 padding1;
  397. Uint8 padding2;
  398. Uint8 padding3;
  399. Sint16 value; /**< The axis value (range: -32768 to 32767) */
  400. Uint16 padding4;
  401. } SDL_JoyAxisEvent;
  402. /**
  403. * Joystick trackball motion event structure (event.jball.*)
  404. *
  405. * \since This struct is available since SDL 3.0.0.
  406. */
  407. typedef struct SDL_JoyBallEvent
  408. {
  409. SDL_EventType type; /**< SDL_EVENT_JOYSTICK_BALL_MOTION */
  410. Uint32 reserved;
  411. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  412. SDL_JoystickID which; /**< The joystick instance id */
  413. Uint8 ball; /**< The joystick trackball index */
  414. Uint8 padding1;
  415. Uint8 padding2;
  416. Uint8 padding3;
  417. Sint16 xrel; /**< The relative motion in the X direction */
  418. Sint16 yrel; /**< The relative motion in the Y direction */
  419. } SDL_JoyBallEvent;
  420. /**
  421. * Joystick hat position change event structure (event.jhat.*)
  422. *
  423. * \since This struct is available since SDL 3.0.0.
  424. */
  425. typedef struct SDL_JoyHatEvent
  426. {
  427. SDL_EventType type; /**< SDL_EVENT_JOYSTICK_HAT_MOTION */
  428. Uint32 reserved;
  429. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  430. SDL_JoystickID which; /**< The joystick instance id */
  431. Uint8 hat; /**< The joystick hat index */
  432. Uint8 value; /**< The hat position value.
  433. * \sa SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP
  434. * \sa SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT
  435. * \sa SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN
  436. *
  437. * Note that zero means the POV is centered.
  438. */
  439. Uint8 padding1;
  440. Uint8 padding2;
  441. } SDL_JoyHatEvent;
  442. /**
  443. * Joystick button event structure (event.jbutton.*)
  444. *
  445. * \since This struct is available since SDL 3.0.0.
  446. */
  447. typedef struct SDL_JoyButtonEvent
  448. {
  449. SDL_EventType type; /**< SDL_EVENT_JOYSTICK_BUTTON_DOWN or SDL_EVENT_JOYSTICK_BUTTON_UP */
  450. Uint32 reserved;
  451. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  452. SDL_JoystickID which; /**< The joystick instance id */
  453. Uint8 button; /**< The joystick button index */
  454. Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
  455. Uint8 padding1;
  456. Uint8 padding2;
  457. } SDL_JoyButtonEvent;
  458. /**
  459. * Joystick device event structure (event.jdevice.*)
  460. *
  461. * \since This struct is available since SDL 3.0.0.
  462. */
  463. typedef struct SDL_JoyDeviceEvent
  464. {
  465. SDL_EventType type; /**< SDL_EVENT_JOYSTICK_ADDED or SDL_EVENT_JOYSTICK_REMOVED or SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */
  466. Uint32 reserved;
  467. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  468. SDL_JoystickID which; /**< The joystick instance id */
  469. } SDL_JoyDeviceEvent;
  470. /**
  471. * Joysick battery level change event structure (event.jbattery.*)
  472. *
  473. * \since This struct is available since SDL 3.0.0.
  474. */
  475. typedef struct SDL_JoyBatteryEvent
  476. {
  477. SDL_EventType type; /**< SDL_EVENT_JOYSTICK_BATTERY_UPDATED */
  478. Uint32 reserved;
  479. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  480. SDL_JoystickID which; /**< The joystick instance id */
  481. SDL_PowerState state; /**< The joystick battery state */
  482. int percent; /**< The joystick battery percent charge remaining */
  483. } SDL_JoyBatteryEvent;
  484. /**
  485. * Gamepad axis motion event structure (event.gaxis.*)
  486. *
  487. * \since This struct is available since SDL 3.0.0.
  488. */
  489. typedef struct SDL_GamepadAxisEvent
  490. {
  491. SDL_EventType type; /**< SDL_EVENT_GAMEPAD_AXIS_MOTION */
  492. Uint32 reserved;
  493. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  494. SDL_JoystickID which; /**< The joystick instance id */
  495. Uint8 axis; /**< The gamepad axis (SDL_GamepadAxis) */
  496. Uint8 padding1;
  497. Uint8 padding2;
  498. Uint8 padding3;
  499. Sint16 value; /**< The axis value (range: -32768 to 32767) */
  500. Uint16 padding4;
  501. } SDL_GamepadAxisEvent;
  502. /**
  503. * Gamepad button event structure (event.gbutton.*)
  504. *
  505. * \since This struct is available since SDL 3.0.0.
  506. */
  507. typedef struct SDL_GamepadButtonEvent
  508. {
  509. SDL_EventType type; /**< SDL_EVENT_GAMEPAD_BUTTON_DOWN or SDL_EVENT_GAMEPAD_BUTTON_UP */
  510. Uint32 reserved;
  511. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  512. SDL_JoystickID which; /**< The joystick instance id */
  513. Uint8 button; /**< The gamepad button (SDL_GamepadButton) */
  514. Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
  515. Uint8 padding1;
  516. Uint8 padding2;
  517. } SDL_GamepadButtonEvent;
  518. /**
  519. * Gamepad device event structure (event.gdevice.*)
  520. *
  521. * \since This struct is available since SDL 3.0.0.
  522. */
  523. typedef struct SDL_GamepadDeviceEvent
  524. {
  525. 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 */
  526. Uint32 reserved;
  527. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  528. SDL_JoystickID which; /**< The joystick instance id */
  529. } SDL_GamepadDeviceEvent;
  530. /**
  531. * Gamepad touchpad event structure (event.gtouchpad.*)
  532. *
  533. * \since This struct is available since SDL 3.0.0.
  534. */
  535. typedef struct SDL_GamepadTouchpadEvent
  536. {
  537. SDL_EventType type; /**< SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or SDL_EVENT_GAMEPAD_TOUCHPAD_UP */
  538. Uint32 reserved;
  539. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  540. SDL_JoystickID which; /**< The joystick instance id */
  541. Sint32 touchpad; /**< The index of the touchpad */
  542. Sint32 finger; /**< The index of the finger on the touchpad */
  543. float x; /**< Normalized in the range 0...1 with 0 being on the left */
  544. float y; /**< Normalized in the range 0...1 with 0 being at the top */
  545. float pressure; /**< Normalized in the range 0...1 */
  546. } SDL_GamepadTouchpadEvent;
  547. /**
  548. * Gamepad sensor event structure (event.gsensor.*)
  549. *
  550. * \since This struct is available since SDL 3.0.0.
  551. */
  552. typedef struct SDL_GamepadSensorEvent
  553. {
  554. SDL_EventType type; /**< SDL_EVENT_GAMEPAD_SENSOR_UPDATE */
  555. Uint32 reserved;
  556. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  557. SDL_JoystickID which; /**< The joystick instance id */
  558. Sint32 sensor; /**< The type of the sensor, one of the values of SDL_SensorType */
  559. float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */
  560. Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
  561. } SDL_GamepadSensorEvent;
  562. /**
  563. * Audio device event structure (event.adevice.*)
  564. *
  565. * \since This struct is available since SDL 3.0.0.
  566. */
  567. typedef struct SDL_AudioDeviceEvent
  568. {
  569. SDL_EventType type; /**< SDL_EVENT_AUDIO_DEVICE_ADDED, or SDL_EVENT_AUDIO_DEVICE_REMOVED, or SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED */
  570. Uint32 reserved;
  571. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  572. SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */
  573. Uint8 recording; /**< zero if a playback device, non-zero if a recording device. */
  574. Uint8 padding1;
  575. Uint8 padding2;
  576. Uint8 padding3;
  577. } SDL_AudioDeviceEvent;
  578. /**
  579. * Camera device event structure (event.cdevice.*)
  580. *
  581. * \since This struct is available since SDL 3.0.0.
  582. */
  583. typedef struct SDL_CameraDeviceEvent
  584. {
  585. SDL_EventType type; /**< SDL_EVENT_CAMERA_DEVICE_ADDED, SDL_EVENT_CAMERA_DEVICE_REMOVED, SDL_EVENT_CAMERA_DEVICE_APPROVED, SDL_EVENT_CAMERA_DEVICE_DENIED */
  586. Uint32 reserved;
  587. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  588. SDL_CameraDeviceID which; /**< SDL_CameraDeviceID for the device being added or removed or changing */
  589. } SDL_CameraDeviceEvent;
  590. /**
  591. * Touch finger event structure (event.tfinger.*)
  592. *
  593. * \since This struct is available since SDL 3.0.0.
  594. */
  595. typedef struct SDL_TouchFingerEvent
  596. {
  597. SDL_EventType type; /**< SDL_EVENT_FINGER_MOTION or SDL_EVENT_FINGER_DOWN or SDL_EVENT_FINGER_UP */
  598. Uint32 reserved;
  599. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  600. SDL_TouchID touchID; /**< The touch device id */
  601. SDL_FingerID fingerID;
  602. float x; /**< Normalized in the range 0...1 */
  603. float y; /**< Normalized in the range 0...1 */
  604. float dx; /**< Normalized in the range -1...1 */
  605. float dy; /**< Normalized in the range -1...1 */
  606. float pressure; /**< Normalized in the range 0...1 */
  607. SDL_WindowID windowID; /**< The window underneath the finger, if any */
  608. } SDL_TouchFingerEvent;
  609. /**
  610. * Pressure-sensitive pen touched or stopped touching surface (event.ptip.*)
  611. *
  612. * \since This struct is available since SDL 3.0.0.
  613. */
  614. typedef struct SDL_PenTipEvent
  615. {
  616. SDL_EventType type; /**< SDL_EVENT_PEN_DOWN or SDL_EVENT_PEN_UP */
  617. Uint32 reserved;
  618. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  619. SDL_WindowID windowID; /**< The window with pen focus, if any */
  620. SDL_PenID which; /**< The pen instance id */
  621. 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) */
  622. Uint8 state; /**< SDL_PRESSED on SDL_EVENT_PEN_DOWN and SDL_RELEASED on SDL_EVENT_PEN_UP */
  623. 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. */
  624. float x; /**< X coordinate, relative to window */
  625. float y; /**< Y coordinate, relative to window */
  626. float axes[SDL_PEN_NUM_AXES]; /**< Pen axes such as pressure and tilt (ordered as per SDL_PenAxis) */
  627. } SDL_PenTipEvent;
  628. /**
  629. * Pressure-sensitive pen motion / pressure / angle event structure
  630. * (event.pmotion.*)
  631. *
  632. * \since This struct is available since SDL 3.0.0.
  633. */
  634. typedef struct SDL_PenMotionEvent
  635. {
  636. SDL_EventType type; /**< SDL_EVENT_PEN_MOTION */
  637. Uint32 reserved;
  638. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  639. SDL_WindowID windowID; /**< The window with pen focus, if any */
  640. SDL_PenID which; /**< The pen instance id */
  641. Uint8 padding1;
  642. Uint8 padding2;
  643. 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. */
  644. float x; /**< X coordinate, relative to window */
  645. float y; /**< Y coordinate, relative to window */
  646. float axes[SDL_PEN_NUM_AXES]; /**< Pen axes such as pressure and tilt (ordered as per SDL_PenAxis) */
  647. } SDL_PenMotionEvent;
  648. /**
  649. * Pressure-sensitive pen button event structure (event.pbutton.*)
  650. *
  651. * \since This struct is available since SDL 3.0.0.
  652. */
  653. typedef struct SDL_PenButtonEvent
  654. {
  655. SDL_EventType type; /**< SDL_EVENT_PEN_BUTTON_DOWN or SDL_EVENT_PEN_BUTTON_UP */
  656. Uint32 reserved;
  657. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  658. SDL_WindowID windowID; /**< The window with pen focus, if any */
  659. SDL_PenID which; /**< The pen instance id */
  660. Uint8 button; /**< The pen button index (1 represents the pen tip for compatibility with mouse events) */
  661. Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
  662. 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. */
  663. float x; /**< X coordinate, relative to window */
  664. float y; /**< Y coordinate, relative to window */
  665. float axes[SDL_PEN_NUM_AXES]; /**< Pen axes such as pressure and tilt (ordered as per SDL_PenAxis) */
  666. } SDL_PenButtonEvent;
  667. /**
  668. * An event used to drop text or request a file open by the system
  669. * (event.drop.*)
  670. *
  671. * The `data` is owned by SDL and should be copied if the application wants to
  672. * hold onto it beyond the scope of handling this event. Do not free it!
  673. *
  674. * \since This struct is available since SDL 3.0.0.
  675. */
  676. typedef struct SDL_DropEvent
  677. {
  678. 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 */
  679. Uint32 reserved;
  680. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  681. SDL_WindowID windowID; /**< The window that was dropped on, if any */
  682. float x; /**< X coordinate, relative to window (not on begin) */
  683. float y; /**< Y coordinate, relative to window (not on begin) */
  684. char *source; /**< The source app that sent this drop event, or NULL if that isn't available */
  685. char *data; /**< The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events */
  686. } SDL_DropEvent;
  687. /**
  688. * An event triggered when the clipboard contents have changed
  689. * (event.clipboard.*)
  690. *
  691. * \since This struct is available since SDL 3.0.0.
  692. */
  693. typedef struct SDL_ClipboardEvent
  694. {
  695. SDL_EventType type; /**< SDL_EVENT_CLIPBOARD_UPDATE */
  696. Uint32 reserved;
  697. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  698. } SDL_ClipboardEvent;
  699. /**
  700. * Sensor event structure (event.sensor.*)
  701. *
  702. * \since This struct is available since SDL 3.0.0.
  703. */
  704. typedef struct SDL_SensorEvent
  705. {
  706. SDL_EventType type; /**< SDL_EVENT_SENSOR_UPDATE */
  707. Uint32 reserved;
  708. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  709. SDL_SensorID which; /**< The instance ID of the sensor */
  710. float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_GetSensorData() */
  711. Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
  712. } SDL_SensorEvent;
  713. /**
  714. * The "quit requested" event
  715. *
  716. * \since This struct is available since SDL 3.0.0.
  717. */
  718. typedef struct SDL_QuitEvent
  719. {
  720. SDL_EventType type; /**< SDL_EVENT_QUIT */
  721. Uint32 reserved;
  722. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  723. } SDL_QuitEvent;
  724. /**
  725. * A user-defined event type (event.user.*)
  726. *
  727. * This event is unique; it is never created by SDL, but only by the
  728. * application. The event can be pushed onto the event queue using
  729. * SDL_PushEvent(). The contents of the structure members are completely up to
  730. * the programmer; the only requirement is that '''type''' is a value obtained
  731. * from SDL_RegisterEvents().
  732. *
  733. * \since This struct is available since SDL 3.0.0.
  734. */
  735. typedef struct SDL_UserEvent
  736. {
  737. Uint32 type; /**< SDL_EVENT_USER through SDL_EVENT_LAST-1, Uint32 because these are not in the SDL_EventType enumeration */
  738. Uint32 reserved;
  739. Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
  740. SDL_WindowID windowID; /**< The associated window if any */
  741. Sint32 code; /**< User defined event code */
  742. void *data1; /**< User defined data pointer */
  743. void *data2; /**< User defined data pointer */
  744. } SDL_UserEvent;
  745. /**
  746. * The structure for all events in SDL.
  747. *
  748. * \since This struct is available since SDL 3.0.0.
  749. */
  750. typedef union SDL_Event
  751. {
  752. Uint32 type; /**< Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration */
  753. SDL_CommonEvent common; /**< Common event data */
  754. SDL_DisplayEvent display; /**< Display event data */
  755. SDL_WindowEvent window; /**< Window event data */
  756. SDL_KeyboardDeviceEvent kdevice; /**< Keyboard device change event data */
  757. SDL_KeyboardEvent key; /**< Keyboard event data */
  758. SDL_TextEditingEvent edit; /**< Text editing event data */
  759. SDL_TextInputEvent text; /**< Text input event data */
  760. SDL_MouseDeviceEvent mdevice; /**< Mouse device change event data */
  761. SDL_MouseMotionEvent motion; /**< Mouse motion event data */
  762. SDL_MouseButtonEvent button; /**< Mouse button event data */
  763. SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
  764. SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
  765. SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
  766. SDL_JoyBallEvent jball; /**< Joystick ball event data */
  767. SDL_JoyHatEvent jhat; /**< Joystick hat event data */
  768. SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
  769. SDL_JoyBatteryEvent jbattery; /**< Joystick battery event data */
  770. SDL_GamepadDeviceEvent gdevice; /**< Gamepad device event data */
  771. SDL_GamepadAxisEvent gaxis; /**< Gamepad axis event data */
  772. SDL_GamepadButtonEvent gbutton; /**< Gamepad button event data */
  773. SDL_GamepadTouchpadEvent gtouchpad; /**< Gamepad touchpad event data */
  774. SDL_GamepadSensorEvent gsensor; /**< Gamepad sensor event data */
  775. SDL_AudioDeviceEvent adevice; /**< Audio device event data */
  776. SDL_CameraDeviceEvent cdevice; /**< Camera device event data */
  777. SDL_SensorEvent sensor; /**< Sensor event data */
  778. SDL_QuitEvent quit; /**< Quit request event data */
  779. SDL_UserEvent user; /**< Custom event data */
  780. SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
  781. SDL_PenTipEvent ptip; /**< Pen tip touching or leaving drawing surface */
  782. SDL_PenMotionEvent pmotion; /**< Pen change in position, pressure, or angle */
  783. SDL_PenButtonEvent pbutton; /**< Pen button press */
  784. SDL_DropEvent drop; /**< Drag and drop event data */
  785. SDL_ClipboardEvent clipboard; /**< Clipboard event data */
  786. /* This is necessary for ABI compatibility between Visual C++ and GCC.
  787. Visual C++ will respect the push pack pragma and use 52 bytes (size of
  788. SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit
  789. architectures) for this union, and GCC will use the alignment of the
  790. largest datatype within the union, which is 8 bytes on 64-bit
  791. architectures.
  792. So... we'll add padding to force the size to be the same for both.
  793. On architectures where pointers are 16 bytes, this needs rounding up to
  794. the next multiple of 16, 64, and on architectures where pointers are
  795. even larger the size of SDL_UserEvent will dominate as being 3 pointers.
  796. */
  797. Uint8 padding[128];
  798. } SDL_Event;
  799. /* Make sure we haven't broken binary compatibility */
  800. SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == sizeof(((SDL_Event *)NULL)->padding));
  801. /* Function prototypes */
  802. /**
  803. * Pump the event loop, gathering events from the input devices.
  804. *
  805. * This function updates the event queue and internal input device state.
  806. *
  807. * **WARNING**: This should only be run in the thread that initialized the
  808. * video subsystem, and for extra safety, you should consider only doing those
  809. * things on the main thread in any case.
  810. *
  811. * SDL_PumpEvents() gathers all the pending input information from devices and
  812. * places it in the event queue. Without calls to SDL_PumpEvents() no events
  813. * would ever be placed on the queue. Often the need for calls to
  814. * SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and
  815. * SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not
  816. * polling or waiting for events (e.g. you are filtering them), then you must
  817. * call SDL_PumpEvents() to force an event queue update.
  818. *
  819. * \since This function is available since SDL 3.0.0.
  820. *
  821. * \sa SDL_PollEvent
  822. * \sa SDL_WaitEvent
  823. */
  824. extern SDL_DECLSPEC void SDLCALL SDL_PumpEvents(void);
  825. /* @{ */
  826. typedef enum SDL_EventAction
  827. {
  828. SDL_ADDEVENT,
  829. SDL_PEEKEVENT,
  830. SDL_GETEVENT
  831. } SDL_EventAction;
  832. /**
  833. * Check the event queue for messages and optionally return them.
  834. *
  835. * `action` may be any of the following:
  836. *
  837. * - `SDL_ADDEVENT`: up to `numevents` events will be added to the back of the
  838. * event queue.
  839. * - `SDL_PEEKEVENT`: `numevents` events at the front of the event queue,
  840. * within the specified minimum and maximum type, will be returned to the
  841. * caller and will _not_ be removed from the queue.
  842. * - `SDL_GETEVENT`: up to `numevents` events at the front of the event queue,
  843. * within the specified minimum and maximum type, will be returned to the
  844. * caller and will be removed from the queue.
  845. *
  846. * You may have to call SDL_PumpEvents() before calling this function.
  847. * Otherwise, the events may not be ready to be filtered when you call
  848. * SDL_PeepEvents().
  849. *
  850. * This function is thread-safe.
  851. *
  852. * \param events destination buffer for the retrieved events, may be NULL to
  853. * leave the events in the queue and return the number of events
  854. * that would have been stored.
  855. * \param numevents if action is SDL_ADDEVENT, the number of events to add
  856. * back to the event queue; if action is SDL_PEEKEVENT or
  857. * SDL_GETEVENT, the maximum number of events to retrieve.
  858. * \param action action to take; see [[#action|Remarks]] for details.
  859. * \param minType minimum value of the event type to be considered;
  860. * SDL_EVENT_FIRST is a safe choice.
  861. * \param maxType maximum value of the event type to be considered;
  862. * SDL_EVENT_LAST is a safe choice.
  863. * \returns the number of events actually stored or a negative error code on
  864. * failure; call SDL_GetError() for more information.
  865. *
  866. * \since This function is available since SDL 3.0.0.
  867. *
  868. * \sa SDL_PollEvent
  869. * \sa SDL_PumpEvents
  870. * \sa SDL_PushEvent
  871. */
  872. extern SDL_DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents, SDL_EventAction action, Uint32 minType, Uint32 maxType);
  873. /* @} */
  874. /**
  875. * Check for the existence of a certain event type in the event queue.
  876. *
  877. * If you need to check for a range of event types, use SDL_HasEvents()
  878. * instead.
  879. *
  880. * \param type the type of event to be queried; see SDL_EventType for details.
  881. * \returns SDL_TRUE if events matching `type` are present, or SDL_FALSE if
  882. * events matching `type` are not present.
  883. *
  884. * \since This function is available since SDL 3.0.0.
  885. *
  886. * \sa SDL_HasEvents
  887. */
  888. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
  889. /**
  890. * Check for the existence of certain event types in the event queue.
  891. *
  892. * If you need to check for a single event type, use SDL_HasEvent() instead.
  893. *
  894. * \param minType the low end of event type to be queried, inclusive; see
  895. * SDL_EventType for details.
  896. * \param maxType the high end of event type to be queried, inclusive; see
  897. * SDL_EventType for details.
  898. * \returns SDL_TRUE if events with type >= `minType` and <= `maxType` are
  899. * present, or SDL_FALSE if not.
  900. *
  901. * \since This function is available since SDL 3.0.0.
  902. *
  903. * \sa SDL_HasEvents
  904. */
  905. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
  906. /**
  907. * Clear events of a specific type from the event queue.
  908. *
  909. * This will unconditionally remove any events from the queue that match
  910. * `type`. If you need to remove a range of event types, use SDL_FlushEvents()
  911. * instead.
  912. *
  913. * It's also normal to just ignore events you don't care about in your event
  914. * loop without calling this function.
  915. *
  916. * This function only affects currently queued events. If you want to make
  917. * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
  918. * on the main thread immediately before the flush call.
  919. *
  920. * If you have user events with custom data that needs to be freed, you should
  921. * use SDL_PeepEvents() to remove and clean up those events before calling
  922. * this function.
  923. *
  924. * \param type the type of event to be cleared; see SDL_EventType for details.
  925. *
  926. * \since This function is available since SDL 3.0.0.
  927. *
  928. * \sa SDL_FlushEvents
  929. */
  930. extern SDL_DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
  931. /**
  932. * Clear events of a range of types from the event queue.
  933. *
  934. * This will unconditionally remove any events from the queue that are in the
  935. * range of `minType` to `maxType`, inclusive. If you need to remove a single
  936. * event type, use SDL_FlushEvent() instead.
  937. *
  938. * It's also normal to just ignore events you don't care about in your event
  939. * loop without calling this function.
  940. *
  941. * This function only affects currently queued events. If you want to make
  942. * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
  943. * on the main thread immediately before the flush call.
  944. *
  945. * \param minType the low end of event type to be cleared, inclusive; see
  946. * SDL_EventType for details.
  947. * \param maxType the high end of event type to be cleared, inclusive; see
  948. * SDL_EventType for details.
  949. *
  950. * \since This function is available since SDL 3.0.0.
  951. *
  952. * \sa SDL_FlushEvent
  953. */
  954. extern SDL_DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
  955. /**
  956. * Poll for currently pending events.
  957. *
  958. * If `event` is not NULL, the next event is removed from the queue and stored
  959. * in the SDL_Event structure pointed to by `event`. The 1 returned refers to
  960. * this event, immediately stored in the SDL Event structure -- not an event
  961. * to follow.
  962. *
  963. * If `event` is NULL, it simply returns 1 if there is an event in the queue,
  964. * but will not remove it from the queue.
  965. *
  966. * As this function may implicitly call SDL_PumpEvents(), you can only call
  967. * this function in the thread that set the video mode.
  968. *
  969. * SDL_PollEvent() is the favored way of receiving system events since it can
  970. * be done from the main loop and does not suspend the main loop while waiting
  971. * on an event to be posted.
  972. *
  973. * The common practice is to fully process the event queue once every frame,
  974. * usually as a first step before updating the game's state:
  975. *
  976. * ```c
  977. * while (game_is_still_running) {
  978. * SDL_Event event;
  979. * while (SDL_PollEvent(&event)) { // poll until all events are handled!
  980. * // decide what to do with this event.
  981. * }
  982. *
  983. * // update game state, draw the current frame
  984. * }
  985. * ```
  986. *
  987. * \param event the SDL_Event structure to be filled with the next event from
  988. * the queue, or NULL.
  989. * \returns SDL_TRUE if this got an event or SDL_FALSE if there are none
  990. * available.
  991. *
  992. * \since This function is available since SDL 3.0.0.
  993. *
  994. * \sa SDL_PushEvent
  995. * \sa SDL_WaitEvent
  996. * \sa SDL_WaitEventTimeout
  997. */
  998. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PollEvent(SDL_Event *event);
  999. /**
  1000. * Wait indefinitely for the next available event.
  1001. *
  1002. * If `event` is not NULL, the next event is removed from the queue and stored
  1003. * in the SDL_Event structure pointed to by `event`.
  1004. *
  1005. * As this function may implicitly call SDL_PumpEvents(), you can only call
  1006. * this function in the thread that initialized the video subsystem.
  1007. *
  1008. * \param event the SDL_Event structure to be filled in with the next event
  1009. * from the queue, or NULL.
  1010. * \returns SDL_TRUE on success or SDL_FALSE if there was an error while
  1011. * waiting for events; call SDL_GetError() for more information.
  1012. *
  1013. * \since This function is available since SDL 3.0.0.
  1014. *
  1015. * \sa SDL_PollEvent
  1016. * \sa SDL_PushEvent
  1017. * \sa SDL_WaitEventTimeout
  1018. */
  1019. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitEvent(SDL_Event *event);
  1020. /**
  1021. * Wait until the specified timeout (in milliseconds) for the next available
  1022. * event.
  1023. *
  1024. * If `event` is not NULL, the next event is removed from the queue and stored
  1025. * in the SDL_Event structure pointed to by `event`.
  1026. *
  1027. * As this function may implicitly call SDL_PumpEvents(), you can only call
  1028. * this function in the thread that initialized the video subsystem.
  1029. *
  1030. * The timeout is not guaranteed, the actual wait time could be longer due to
  1031. * system scheduling.
  1032. *
  1033. * \param event the SDL_Event structure to be filled in with the next event
  1034. * from the queue, or NULL.
  1035. * \param timeoutMS the maximum number of milliseconds to wait for the next
  1036. * available event.
  1037. * \returns SDL_TRUE if this got an event or SDL_FALSE if the timeout elapsed
  1038. * without any events available.
  1039. *
  1040. * \since This function is available since SDL 3.0.0.
  1041. *
  1042. * \sa SDL_PollEvent
  1043. * \sa SDL_PushEvent
  1044. * \sa SDL_WaitEvent
  1045. */
  1046. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitEventTimeout(SDL_Event *event, Sint32 timeoutMS);
  1047. /**
  1048. * Add an event to the event queue.
  1049. *
  1050. * The event queue can actually be used as a two way communication channel.
  1051. * Not only can events be read from the queue, but the user can also push
  1052. * their own events onto it. `event` is a pointer to the event structure you
  1053. * wish to push onto the queue. The event is copied into the queue, and the
  1054. * caller may dispose of the memory pointed to after SDL_PushEvent() returns.
  1055. *
  1056. * Note: Pushing device input events onto the queue doesn't modify the state
  1057. * of the device within SDL.
  1058. *
  1059. * This function is thread-safe, and can be called from other threads safely.
  1060. *
  1061. * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
  1062. * the event filter but events added with SDL_PeepEvents() do not.
  1063. *
  1064. * For pushing application-specific events, please use SDL_RegisterEvents() to
  1065. * get an event type that does not conflict with other code that also wants
  1066. * its own custom event types.
  1067. *
  1068. * \param event the SDL_Event to be added to the queue.
  1069. * \returns 1 on success, 0 if the event was filtered, or a negative error
  1070. * code on failure; call SDL_GetError() for more information. A
  1071. * common reason for error is the event queue being full.
  1072. *
  1073. * \since This function is available since SDL 3.0.0.
  1074. *
  1075. * \sa SDL_PeepEvents
  1076. * \sa SDL_PollEvent
  1077. * \sa SDL_RegisterEvents
  1078. */
  1079. extern SDL_DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event);
  1080. /**
  1081. * A function pointer used for callbacks that watch the event queue.
  1082. *
  1083. * \param userdata what was passed as `userdata` to SDL_SetEventFilter() or
  1084. * SDL_AddEventWatch, etc.
  1085. * \param event the event that triggered the callback.
  1086. * \returns 1 to permit event to be added to the queue, and 0 to disallow it.
  1087. * When used with SDL_AddEventWatch, the return value is ignored.
  1088. *
  1089. * \threadsafety SDL may call this callback at any time from any thread; the
  1090. * application is responsible for locking resources the callback
  1091. * touches that need to be protected.
  1092. *
  1093. * \since This datatype is available since SDL 3.0.0.
  1094. *
  1095. * \sa SDL_SetEventFilter
  1096. * \sa SDL_AddEventWatch
  1097. */
  1098. typedef int (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
  1099. /**
  1100. * Set up a filter to process all events before they change internal state and
  1101. * are posted to the internal event queue.
  1102. *
  1103. * If the filter function returns 1 when called, then the event will be added
  1104. * to the internal queue. If it returns 0, then the event will be dropped from
  1105. * the queue, but the internal state will still be updated. This allows
  1106. * selective filtering of dynamically arriving events.
  1107. *
  1108. * **WARNING**: Be very careful of what you do in the event filter function,
  1109. * as it may run in a different thread!
  1110. *
  1111. * On platforms that support it, if the quit event is generated by an
  1112. * interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the
  1113. * application at the next event poll.
  1114. *
  1115. * There is one caveat when dealing with the SDL_QuitEvent event type. The
  1116. * event filter is only called when the window manager desires to close the
  1117. * application window. If the event filter returns 1, then the window will be
  1118. * closed, otherwise the window will remain open if possible.
  1119. *
  1120. * Note: Disabled events never make it to the event filter function; see
  1121. * SDL_SetEventEnabled().
  1122. *
  1123. * Note: If you just want to inspect events without filtering, you should use
  1124. * SDL_AddEventWatch() instead.
  1125. *
  1126. * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
  1127. * the event filter, but events pushed onto the queue with SDL_PeepEvents() do
  1128. * not.
  1129. *
  1130. * \param filter an SDL_EventFilter function to call when an event happens.
  1131. * \param userdata a pointer that is passed to `filter`.
  1132. *
  1133. * \threadsafety SDL may call the filter callback at any time from any thread;
  1134. * the application is responsible for locking resources the
  1135. * callback touches that need to be protected.
  1136. *
  1137. * \since This function is available since SDL 3.0.0.
  1138. *
  1139. * \sa SDL_AddEventWatch
  1140. * \sa SDL_SetEventEnabled
  1141. * \sa SDL_GetEventFilter
  1142. * \sa SDL_PeepEvents
  1143. * \sa SDL_PushEvent
  1144. */
  1145. extern SDL_DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter, void *userdata);
  1146. /**
  1147. * Query the current event filter.
  1148. *
  1149. * This function can be used to "chain" filters, by saving the existing filter
  1150. * before replacing it with a function that will call that saved filter.
  1151. *
  1152. * \param filter the current callback function will be stored here.
  1153. * \param userdata the pointer that is passed to the current event filter will
  1154. * be stored here.
  1155. * \returns SDL_TRUE on success or SDL_FALSE if there is no event filter set.
  1156. *
  1157. * \since This function is available since SDL 3.0.0.
  1158. *
  1159. * \sa SDL_SetEventFilter
  1160. */
  1161. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata);
  1162. /**
  1163. * Add a callback to be triggered when an event is added to the event queue.
  1164. *
  1165. * `filter` will be called when an event happens, and its return value is
  1166. * ignored.
  1167. *
  1168. * **WARNING**: Be very careful of what you do in the event filter function,
  1169. * as it may run in a different thread!
  1170. *
  1171. * If the quit event is generated by a signal (e.g. SIGINT), it will bypass
  1172. * the internal queue and be delivered to the watch callback immediately, and
  1173. * arrive at the next event poll.
  1174. *
  1175. * Note: the callback is called for events posted by the user through
  1176. * SDL_PushEvent(), but not for disabled events, nor for events by a filter
  1177. * callback set with SDL_SetEventFilter(), nor for events posted by the user
  1178. * through SDL_PeepEvents().
  1179. *
  1180. * \param filter an SDL_EventFilter function to call when an event happens.
  1181. * \param userdata a pointer that is passed to `filter`.
  1182. * \returns 0 on success, or a negative error code on failure; call
  1183. * SDL_GetError() for more information.
  1184. *
  1185. * \threadsafety It is safe to call this function from any thread.
  1186. *
  1187. * \since This function is available since SDL 3.0.0.
  1188. *
  1189. * \sa SDL_DelEventWatch
  1190. * \sa SDL_SetEventFilter
  1191. */
  1192. extern SDL_DECLSPEC int SDLCALL SDL_AddEventWatch(SDL_EventFilter filter, void *userdata);
  1193. /**
  1194. * Remove an event watch callback added with SDL_AddEventWatch().
  1195. *
  1196. * This function takes the same input as SDL_AddEventWatch() to identify and
  1197. * delete the corresponding callback.
  1198. *
  1199. * \param filter the function originally passed to SDL_AddEventWatch().
  1200. * \param userdata the pointer originally passed to SDL_AddEventWatch().
  1201. *
  1202. * \since This function is available since SDL 3.0.0.
  1203. *
  1204. * \sa SDL_AddEventWatch
  1205. */
  1206. extern SDL_DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter, void *userdata);
  1207. /**
  1208. * Run a specific filter function on the current event queue, removing any
  1209. * events for which the filter returns 0.
  1210. *
  1211. * See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(),
  1212. * this function does not change the filter permanently, it only uses the
  1213. * supplied filter until this function returns.
  1214. *
  1215. * \param filter the SDL_EventFilter function to call when an event happens.
  1216. * \param userdata a pointer that is passed to `filter`.
  1217. *
  1218. * \since This function is available since SDL 3.0.0.
  1219. *
  1220. * \sa SDL_GetEventFilter
  1221. * \sa SDL_SetEventFilter
  1222. */
  1223. extern SDL_DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter, void *userdata);
  1224. /**
  1225. * Set the state of processing events by type.
  1226. *
  1227. * \param type the type of event; see SDL_EventType for details.
  1228. * \param enabled whether to process the event or not.
  1229. *
  1230. * \since This function is available since SDL 3.0.0.
  1231. *
  1232. * \sa SDL_EventEnabled
  1233. */
  1234. extern SDL_DECLSPEC void SDLCALL SDL_SetEventEnabled(Uint32 type, SDL_bool enabled);
  1235. /**
  1236. * Query the state of processing events by type.
  1237. *
  1238. * \param type the type of event; see SDL_EventType for details.
  1239. * \returns SDL_TRUE if the event is being processed, SDL_FALSE otherwise.
  1240. *
  1241. * \since This function is available since SDL 3.0.0.
  1242. *
  1243. * \sa SDL_SetEventEnabled
  1244. */
  1245. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EventEnabled(Uint32 type);
  1246. /**
  1247. * Allocate a set of user-defined events, and return the beginning event
  1248. * number for that set of events.
  1249. *
  1250. * \param numevents the number of events to be allocated.
  1251. * \returns the beginning event number, or 0 if numevents is invalid or if
  1252. * there are not enough user-defined events left.
  1253. *
  1254. * \since This function is available since SDL 3.0.0.
  1255. *
  1256. * \sa SDL_PushEvent
  1257. */
  1258. extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
  1259. /**
  1260. * Allocate dynamic memory for an SDL event.
  1261. *
  1262. * You can use this to allocate memory for user events that will be
  1263. * automatically freed after the event is processed.
  1264. *
  1265. * \param size the amount of memory to allocate.
  1266. * \returns a pointer to the memory allocated or NULL on failure; call
  1267. * SDL_GetError() for more information.
  1268. *
  1269. * \threadsafety It is safe to call this function from any thread.
  1270. *
  1271. * \since This function is available since SDL 3.0.0.
  1272. */
  1273. extern SDL_DECLSPEC void * SDLCALL SDL_AllocateEventMemory(size_t size);
  1274. /* Ends C function definitions when using C++ */
  1275. #ifdef __cplusplus
  1276. }
  1277. #endif
  1278. #include <SDL3/SDL_close_code.h>
  1279. #endif /* SDL_events_h_ */