SDL_events.h 62 KB

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