SDL_events.h 51 KB

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