SDL_events.h 53 KB

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