SDL_events.h 48 KB

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