SDL_events.h 47 KB

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