SDL 3.0
SDL_events.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * # CategoryEvents
24 *
25 * Event queue management.
26 *
27 * It's extremely common--often required--that an app deal with SDL's event
28 * queue. Almost all useful information about interactions with the real world
29 * flow through here: the user interacting with the computer and app, hardware
30 * coming and going, the system changing in some way, etc.
31 *
32 * An app generally takes a moment, perhaps at the start of a new frame, to
33 * examine any events that have occurred since the last time and process or
34 * ignore them. This is generally done by calling SDL_PollEvent() in a loop
35 * until it returns false (or, if using the main callbacks, events are
36 * provided one at a time in calls to SDL_AppEvent() before the next call to
37 * SDL_AppIterate(); in this scenario, the app does not call SDL_PollEvent()
38 * at all).
39 *
40 * There is other forms of control, too: SDL_PeepEvents() has more
41 * functionality at the cost of more complexity, and SDL_WaitEvent() can block
42 * the process until something interesting happens, which might be beneficial
43 * for certain types of programs on low-power hardware. One may also call
44 * SDL_AddEventWatch() to set a callback when new events arrive.
45 *
46 * The app is free to generate their own events, too: SDL_PushEvent allows the
47 * app to put events onto the queue for later retrieval; SDL_RegisterEvents
48 * can guarantee that these events have a type that isn't in use by other
49 * parts of the system.
50 */
51
52#ifndef SDL_events_h_
53#define SDL_events_h_
54
55#include <SDL3/SDL_stdinc.h>
56#include <SDL3/SDL_audio.h>
57#include <SDL3/SDL_camera.h>
58#include <SDL3/SDL_error.h>
59#include <SDL3/SDL_gamepad.h>
60#include <SDL3/SDL_joystick.h>
61#include <SDL3/SDL_keyboard.h>
62#include <SDL3/SDL_keycode.h>
63#include <SDL3/SDL_mouse.h>
65#include <SDL3/SDL_pen.h>
66#include <SDL3/SDL_power.h>
67#include <SDL3/SDL_sensor.h>
68#include <SDL3/SDL_scancode.h>
69#include <SDL3/SDL_touch.h>
70#include <SDL3/SDL_video.h>
71
72#include <SDL3/SDL_begin_code.h>
73/* Set up for C function definitions, even when using C++ */
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78/* General keyboard/mouse/pen state definitions */
79
80/**
81 * The types of events that can be delivered.
82 *
83 * \since This enum is available since SDL 3.2.0.
84 */
85typedef enum SDL_EventType
86{
87 SDL_EVENT_FIRST = 0, /**< Unused (do not remove) */
88
89 /* Application events */
90 SDL_EVENT_QUIT = 0x100, /**< User-requested quit */
91
92 /* These application events have special meaning on iOS and Android, see README-ios.md and README-android.md for details */
93 SDL_EVENT_TERMINATING, /**< The application is being terminated by the OS. This event must be handled in a callback set with SDL_AddEventWatch().
94 Called on iOS in applicationWillTerminate()
95 Called on Android in onDestroy()
96 */
97 SDL_EVENT_LOW_MEMORY, /**< The application is low on memory, free memory if possible. This event must be handled in a callback set with SDL_AddEventWatch().
98 Called on iOS in applicationDidReceiveMemoryWarning()
99 Called on Android in onTrimMemory()
100 */
101 SDL_EVENT_WILL_ENTER_BACKGROUND, /**< The application is about to enter the background. This event must be handled in a callback set with SDL_AddEventWatch().
102 Called on iOS in applicationWillResignActive()
103 Called on Android in onPause()
104 */
105 SDL_EVENT_DID_ENTER_BACKGROUND, /**< The application did enter the background and may not get CPU for some time. This event must be handled in a callback set with SDL_AddEventWatch().
106 Called on iOS in applicationDidEnterBackground()
107 Called on Android in onPause()
108 */
109 SDL_EVENT_WILL_ENTER_FOREGROUND, /**< The application is about to enter the foreground. This event must be handled in a callback set with SDL_AddEventWatch().
110 Called on iOS in applicationWillEnterForeground()
111 Called on Android in onResume()
112 */
113 SDL_EVENT_DID_ENTER_FOREGROUND, /**< The application is now interactive. This event must be handled in a callback set with SDL_AddEventWatch().
114 Called on iOS in applicationDidBecomeActive()
115 Called on Android in onResume()
116 */
117
118 SDL_EVENT_LOCALE_CHANGED, /**< The user's locale preferences have changed. */
119
120 SDL_EVENT_SYSTEM_THEME_CHANGED, /**< The system theme changed */
121
122 /* Display events */
123 /* 0x150 was SDL_DISPLAYEVENT, reserve the number for sdl2-compat */
124 SDL_EVENT_DISPLAY_ORIENTATION = 0x151, /**< Display orientation has changed to data1 */
125 SDL_EVENT_DISPLAY_ADDED, /**< Display has been added to the system */
126 SDL_EVENT_DISPLAY_REMOVED, /**< Display has been removed from the system */
127 SDL_EVENT_DISPLAY_MOVED, /**< Display has changed position */
128 SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED, /**< Display has changed desktop mode */
129 SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED, /**< Display has changed current mode */
130 SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, /**< Display has changed content scale */
131 SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED, /**< Display has changed usable bounds */
134
135 /* Window events */
136 /* 0x200 was SDL_WINDOWEVENT, reserve the number for sdl2-compat */
137 /* 0x201 was SDL_SYSWMEVENT, reserve the number for sdl2-compat */
138 SDL_EVENT_WINDOW_SHOWN = 0x202, /**< Window has been shown */
139 SDL_EVENT_WINDOW_HIDDEN, /**< Window has been hidden */
140 SDL_EVENT_WINDOW_EXPOSED, /**< Window has been exposed and should be redrawn, and can be redrawn directly from event watchers for this event.
141 data1 is 1 for live-resize expose events, 0 otherwise. */
142 SDL_EVENT_WINDOW_MOVED, /**< Window has been moved to data1, data2 */
143 SDL_EVENT_WINDOW_RESIZED, /**< Window has been resized to data1xdata2 */
144 SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED,/**< The pixel size of the window has changed to data1xdata2 */
145 SDL_EVENT_WINDOW_METAL_VIEW_RESIZED,/**< The pixel size of a Metal view associated with the window has changed */
146 SDL_EVENT_WINDOW_MINIMIZED, /**< Window has been minimized */
147 SDL_EVENT_WINDOW_MAXIMIZED, /**< Window has been maximized */
148 SDL_EVENT_WINDOW_RESTORED, /**< Window has been restored to normal size and position */
149 SDL_EVENT_WINDOW_MOUSE_ENTER, /**< Window has gained mouse focus */
150 SDL_EVENT_WINDOW_MOUSE_LEAVE, /**< Window has lost mouse focus */
151 SDL_EVENT_WINDOW_FOCUS_GAINED, /**< Window has gained keyboard focus */
152 SDL_EVENT_WINDOW_FOCUS_LOST, /**< Window has lost keyboard focus */
153 SDL_EVENT_WINDOW_CLOSE_REQUESTED, /**< The window manager requests that the window be closed */
154 SDL_EVENT_WINDOW_HIT_TEST, /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL */
155 SDL_EVENT_WINDOW_ICCPROF_CHANGED, /**< The window's ICC profile has changed */
156 SDL_EVENT_WINDOW_DISPLAY_CHANGED, /**< Window has been moved to display data1 */
157 SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED, /**< Window display scale has been changed */
158 SDL_EVENT_WINDOW_SAFE_AREA_CHANGED, /**< The window safe area has been changed */
159 SDL_EVENT_WINDOW_OCCLUDED, /**< The window has been occluded */
160 SDL_EVENT_WINDOW_ENTER_FULLSCREEN, /**< The window has entered fullscreen mode */
161 SDL_EVENT_WINDOW_LEAVE_FULLSCREEN, /**< The window has left fullscreen mode */
162 SDL_EVENT_WINDOW_DESTROYED, /**< The window with the associated ID is being or has been destroyed. If this message is being handled
163 in an event watcher, the window handle is still valid and can still be used to retrieve any properties
164 associated with the window. Otherwise, the handle has already been destroyed and all resources
165 associated with it are invalid */
166 SDL_EVENT_WINDOW_HDR_STATE_CHANGED, /**< Window HDR properties have changed */
167 SDL_EVENT_WINDOW_SETTINGS_CHANGED, /**< Window settings have changed (on visionOS) */
170
171 /* Keyboard events */
172 SDL_EVENT_KEY_DOWN = 0x300, /**< Key pressed */
173 SDL_EVENT_KEY_UP, /**< Key released */
174 SDL_EVENT_TEXT_EDITING, /**< Keyboard text editing (composition) */
175 SDL_EVENT_TEXT_INPUT, /**< Keyboard text input */
176 SDL_EVENT_KEYMAP_CHANGED, /**< Keymap changed due to a system event such as an
177 input language or keyboard layout change. */
178 SDL_EVENT_KEYBOARD_ADDED, /**< A new keyboard has been inserted into the system */
179 SDL_EVENT_KEYBOARD_REMOVED, /**< A keyboard has been removed */
180 SDL_EVENT_TEXT_EDITING_CANDIDATES, /**< Keyboard text editing candidates */
181 SDL_EVENT_SCREEN_KEYBOARD_SHOWN, /**< The on-screen keyboard has been shown */
182 SDL_EVENT_SCREEN_KEYBOARD_HIDDEN, /**< The on-screen keyboard has been hidden */
183
184 /* Mouse events */
185 SDL_EVENT_MOUSE_MOTION = 0x400, /**< Mouse moved */
186 SDL_EVENT_MOUSE_BUTTON_DOWN, /**< Mouse button pressed */
187 SDL_EVENT_MOUSE_BUTTON_UP, /**< Mouse button released */
188 SDL_EVENT_MOUSE_WHEEL, /**< Mouse wheel motion */
189 SDL_EVENT_MOUSE_ADDED, /**< A new mouse has been inserted into the system */
190 SDL_EVENT_MOUSE_REMOVED, /**< A mouse has been removed */
191
192 /* Joystick events */
193 SDL_EVENT_JOYSTICK_AXIS_MOTION = 0x600, /**< Joystick axis motion */
194 SDL_EVENT_JOYSTICK_BALL_MOTION, /**< Joystick trackball motion */
195 SDL_EVENT_JOYSTICK_HAT_MOTION, /**< Joystick hat position change */
196 SDL_EVENT_JOYSTICK_BUTTON_DOWN, /**< Joystick button pressed */
197 SDL_EVENT_JOYSTICK_BUTTON_UP, /**< Joystick button released */
198 SDL_EVENT_JOYSTICK_ADDED, /**< A new joystick has been inserted into the system */
199 SDL_EVENT_JOYSTICK_REMOVED, /**< An opened joystick has been removed */
200 SDL_EVENT_JOYSTICK_BATTERY_UPDATED, /**< Joystick battery level change */
201 SDL_EVENT_JOYSTICK_UPDATE_COMPLETE, /**< Joystick update is complete */
202
203 /* Gamepad events */
204 SDL_EVENT_GAMEPAD_AXIS_MOTION = 0x650, /**< Gamepad axis motion */
205 SDL_EVENT_GAMEPAD_BUTTON_DOWN, /**< Gamepad button pressed */
206 SDL_EVENT_GAMEPAD_BUTTON_UP, /**< Gamepad button released */
207 SDL_EVENT_GAMEPAD_ADDED, /**< A new gamepad has been inserted into the system */
208 SDL_EVENT_GAMEPAD_REMOVED, /**< A gamepad has been removed */
209 SDL_EVENT_GAMEPAD_REMAPPED, /**< The gamepad mapping was updated */
210 SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN, /**< Gamepad touchpad was touched */
211 SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION, /**< Gamepad touchpad finger was moved */
212 SDL_EVENT_GAMEPAD_TOUCHPAD_UP, /**< Gamepad touchpad finger was lifted */
213 SDL_EVENT_GAMEPAD_SENSOR_UPDATE, /**< Gamepad sensor was updated */
214 SDL_EVENT_GAMEPAD_UPDATE_COMPLETE, /**< Gamepad update is complete */
215 SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED, /**< Gamepad Steam handle has changed */
216 SDL_EVENT_GAMEPAD_CAPSENSE_TOUCH, /**< Gamepad capsense was touched */
217 SDL_EVENT_GAMEPAD_CAPSENSE_RELEASE, /**< Gamepad capsense was released */
218
219 /* Touch events */
224
225 /* Pinch events */
226 SDL_EVENT_PINCH_BEGIN = 0x710, /**< Pinch gesture started */
227 SDL_EVENT_PINCH_UPDATE, /**< Pinch gesture updated */
228 SDL_EVENT_PINCH_END, /**< Pinch gesture ended */
229
230 /* 0x800, 0x801, and 0x802 were the Gesture events from SDL2. Do not reuse these values! sdl2-compat needs them! */
231
232 /* Clipboard events */
233 SDL_EVENT_CLIPBOARD_UPDATE = 0x900, /**< The clipboard changed */
234
235 /* Drag and drop events */
236 SDL_EVENT_DROP_FILE = 0x1000, /**< The system requests a file open */
237 SDL_EVENT_DROP_TEXT, /**< text/plain drag-and-drop event */
238 SDL_EVENT_DROP_BEGIN, /**< A new set of drops is beginning (NULL filename) */
239 SDL_EVENT_DROP_COMPLETE, /**< Current set of drops is now complete (NULL filename) */
240 SDL_EVENT_DROP_POSITION, /**< Position while moving over the window */
241
242 /* Audio hotplug events */
243 SDL_EVENT_AUDIO_DEVICE_ADDED = 0x1100, /**< A new audio device is available */
244 SDL_EVENT_AUDIO_DEVICE_REMOVED, /**< An audio device has been removed. */
245 SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED, /**< An audio device's format has been changed by the system. */
246
247 /* Sensor events */
248 SDL_EVENT_SENSOR_UPDATE = 0x1200, /**< A sensor was updated */
249
250 /* Pressure-sensitive pen events */
251 SDL_EVENT_PEN_PROXIMITY_IN = 0x1300, /**< Pressure-sensitive pen has become available */
252 SDL_EVENT_PEN_PROXIMITY_OUT, /**< Pressure-sensitive pen has become unavailable */
253 SDL_EVENT_PEN_DOWN, /**< Pressure-sensitive pen touched drawing surface */
254 SDL_EVENT_PEN_UP, /**< Pressure-sensitive pen stopped touching drawing surface */
255 SDL_EVENT_PEN_BUTTON_DOWN, /**< Pressure-sensitive pen button pressed */
256 SDL_EVENT_PEN_BUTTON_UP, /**< Pressure-sensitive pen button released */
257 SDL_EVENT_PEN_MOTION, /**< Pressure-sensitive pen is moving on the tablet */
258 SDL_EVENT_PEN_AXIS, /**< Pressure-sensitive pen angle/pressure/etc changed */
259
260 /* Camera hotplug events */
261 SDL_EVENT_CAMERA_DEVICE_ADDED = 0x1400, /**< A new camera device is available */
262 SDL_EVENT_CAMERA_DEVICE_REMOVED, /**< A camera device has been removed. */
263 SDL_EVENT_CAMERA_DEVICE_APPROVED, /**< A camera device has been approved for use by the user. */
264 SDL_EVENT_CAMERA_DEVICE_DENIED, /**< A camera device has been denied for use by the user. */
265
266 /* Notification events */
267 SDL_EVENT_NOTIFICATION_ACTION_INVOKED = 0x1500, /**< A user response to a system notification was received. */
268
269 /* Render events */
270 SDL_EVENT_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
271 SDL_EVENT_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
272 SDL_EVENT_RENDER_DEVICE_LOST, /**< The device has been lost and can't be recovered. */
273
274 /* Reserved events for private platforms */
279
280 /* Internal events */
281 SDL_EVENT_POLL_SENTINEL = 0x7F00, /**< Signals the end of an event poll cycle */
282
283 /** Events SDL_EVENT_USER through SDL_EVENT_LAST are for your use,
284 * and should be allocated with SDL_RegisterEvents()
285 */
287
288 /**
289 * This last event is only for bounding internal arrays
290 */
292
293 /* This just makes sure the enum is the size of Uint32 */
295
297
298/**
299 * Fields shared by every event
300 *
301 * \since This struct is available since SDL 3.2.0.
302 */
303typedef struct SDL_CommonEvent
304{
305 Uint32 type; /**< Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration */
307 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
309
310/**
311 * Display state change event data (event.display.*)
312 *
313 * \since This struct is available since SDL 3.2.0.
314 */
315typedef struct SDL_DisplayEvent
316{
317 SDL_EventType type; /**< SDL_EVENT_DISPLAY_* */
319 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
320 SDL_DisplayID displayID;/**< The associated display */
321 Sint32 data1; /**< event dependent data */
322 Sint32 data2; /**< event dependent data */
324
325/**
326 * Window state change event data (event.window.*)
327 *
328 * \since This struct is available since SDL 3.2.0.
329 */
330typedef struct SDL_WindowEvent
331{
332 SDL_EventType type; /**< SDL_EVENT_WINDOW_* */
334 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
335 SDL_WindowID windowID; /**< The associated window */
336 Sint32 data1; /**< event dependent data */
337 Sint32 data2; /**< event dependent data */
339
340/**
341 * Keyboard device event structure (event.kdevice.*)
342 *
343 * \since This struct is available since SDL 3.2.0.
344 */
346{
347 SDL_EventType type; /**< SDL_EVENT_KEYBOARD_ADDED or SDL_EVENT_KEYBOARD_REMOVED */
349 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
350 SDL_KeyboardID which; /**< The keyboard instance id */
352
353/**
354 * Keyboard button event structure (event.key.*)
355 *
356 * The `key` is the base SDL_Keycode generated by pressing the `scancode`
357 * using the current keyboard layout, applying any options specified in
358 * SDL_HINT_KEYCODE_OPTIONS. You can get the SDL_Keycode corresponding to the
359 * event scancode and modifiers directly from the keyboard layout, bypassing
360 * SDL_HINT_KEYCODE_OPTIONS, by calling SDL_GetKeyFromScancode().
361 *
362 * \since This struct is available since SDL 3.2.0.
363 *
364 * \sa SDL_GetKeyFromScancode
365 * \sa SDL_HINT_KEYCODE_OPTIONS
366 */
367typedef struct SDL_KeyboardEvent
368{
369 SDL_EventType type; /**< SDL_EVENT_KEY_DOWN or SDL_EVENT_KEY_UP */
371 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
372 SDL_WindowID windowID; /**< The window with keyboard focus, if any */
373 SDL_KeyboardID which; /**< The keyboard instance id, or 0 if unknown or virtual */
374 SDL_Scancode scancode; /**< SDL physical key code */
375 SDL_Keycode key; /**< SDL virtual key code */
376 SDL_Keymod mod; /**< current key modifiers */
377 Uint16 raw; /**< The platform dependent scancode for this event */
378 bool down; /**< true if the key is pressed */
379 bool repeat; /**< true if this is a key repeat */
381
382/**
383 * Keyboard text editing event structure (event.edit.*)
384 *
385 * The start cursor is the position, in UTF-8 characters, where new typing
386 * will be inserted into the editing text. The length is the number of UTF-8
387 * characters that will be replaced by new typing.
388 *
389 * \since This struct is available since SDL 3.2.0.
390 */
392{
393 SDL_EventType type; /**< SDL_EVENT_TEXT_EDITING */
395 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
396 SDL_WindowID windowID; /**< The window with keyboard focus, if any */
397 const char *text; /**< The editing text */
398 Sint32 start; /**< The start cursor of selected editing text, or -1 if not set */
399 Sint32 length; /**< The length of selected editing text, or -1 if not set */
401
402/**
403 * Keyboard IME candidates event structure (event.edit_candidates.*)
404 *
405 * \since This struct is available since SDL 3.2.0.
406 */
408{
409 SDL_EventType type; /**< SDL_EVENT_TEXT_EDITING_CANDIDATES */
411 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
412 SDL_WindowID windowID; /**< The window with keyboard focus, if any */
413 const char * const *candidates; /**< The list of candidates, or NULL if there are no candidates available */
414 Sint32 num_candidates; /**< The number of strings in `candidates` */
415 Sint32 selected_candidate; /**< The index of the selected candidate, or -1 if no candidate is selected */
416 bool horizontal; /**< true if the list is horizontal, false if it's vertical */
421
422/**
423 * Keyboard text input event structure (event.text.*)
424 *
425 * This event will never be delivered unless text input is enabled by calling
426 * SDL_StartTextInput(). Text input is disabled by default!
427 *
428 * \since This struct is available since SDL 3.2.0.
429 *
430 * \sa SDL_StartTextInput
431 * \sa SDL_StopTextInput
432 */
433typedef struct SDL_TextInputEvent
434{
435 SDL_EventType type; /**< SDL_EVENT_TEXT_INPUT */
437 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
438 SDL_WindowID windowID; /**< The window with keyboard focus, if any */
439 const char *text; /**< The input text, UTF-8 encoded */
441
442/**
443 * Mouse device event structure (event.mdevice.*)
444 *
445 * \since This struct is available since SDL 3.2.0.
446 */
448{
449 SDL_EventType type; /**< SDL_EVENT_MOUSE_ADDED or SDL_EVENT_MOUSE_REMOVED */
451 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
452 SDL_MouseID which; /**< The mouse instance id */
454
455/**
456 * Mouse motion event structure (event.motion.*)
457 *
458 * \since This struct is available since SDL 3.2.0.
459 */
461{
462 SDL_EventType type; /**< SDL_EVENT_MOUSE_MOTION */
464 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
465 SDL_WindowID windowID; /**< The window with mouse focus, if any */
466 SDL_MouseID which; /**< The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, SDL_PEN_MOUSEID for pen events, or 0 */
467 SDL_MouseButtonFlags state; /**< The current button state */
468 float x; /**< X coordinate, relative to window */
469 float y; /**< Y coordinate, relative to window */
470 float xrel; /**< The relative motion in the X direction */
471 float yrel; /**< The relative motion in the Y direction */
473
474/**
475 * Mouse button event structure (event.button.*)
476 *
477 * \since This struct is available since SDL 3.2.0.
478 */
480{
481 SDL_EventType type; /**< SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP */
483 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
484 SDL_WindowID windowID; /**< The window with mouse focus, if any */
485 SDL_MouseID which; /**< The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 */
486 Uint8 button; /**< The mouse button index */
487 bool down; /**< true if the button is pressed */
488 Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
490 float x; /**< X coordinate, relative to window */
491 float y; /**< Y coordinate, relative to window */
493
494/**
495 * Mouse wheel event structure (event.wheel.*)
496 *
497 * \since This struct is available since SDL 3.2.0.
498 */
500{
501 SDL_EventType type; /**< SDL_EVENT_MOUSE_WHEEL */
503 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
504 SDL_WindowID windowID; /**< The window with mouse focus, if any */
505 SDL_MouseID which; /**< The mouse instance id in relative mode or 0 */
506 float x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
507 float y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
508 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 */
509 float mouse_x; /**< X coordinate, relative to window */
510 float mouse_y; /**< Y coordinate, relative to window */
511 Sint32 integer_x; /**< The amount scrolled horizontally, accumulated to whole scroll "ticks" (added in 3.2.12) */
512 Sint32 integer_y; /**< The amount scrolled vertically, accumulated to whole scroll "ticks" (added in 3.2.12) */
514
515/**
516 * Joystick axis motion event structure (event.jaxis.*)
517 *
518 * \since This struct is available since SDL 3.2.0.
519 */
520typedef struct SDL_JoyAxisEvent
521{
522 SDL_EventType type; /**< SDL_EVENT_JOYSTICK_AXIS_MOTION */
524 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
525 SDL_JoystickID which; /**< The joystick instance id */
526 Uint8 axis; /**< The joystick axis index */
530 Sint16 value; /**< The axis value (range: -32768 to 32767) */
533
534/**
535 * Joystick trackball motion event structure (event.jball.*)
536 *
537 * \since This struct is available since SDL 3.2.0.
538 */
539typedef struct SDL_JoyBallEvent
540{
541 SDL_EventType type; /**< SDL_EVENT_JOYSTICK_BALL_MOTION */
543 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
544 SDL_JoystickID which; /**< The joystick instance id */
545 Uint8 ball; /**< The joystick trackball index */
549 Sint16 xrel; /**< The relative motion in the X direction */
550 Sint16 yrel; /**< The relative motion in the Y direction */
552
553/**
554 * Joystick hat position change event structure (event.jhat.*)
555 *
556 * \since This struct is available since SDL 3.2.0.
557 */
558typedef struct SDL_JoyHatEvent
559{
560 SDL_EventType type; /**< SDL_EVENT_JOYSTICK_HAT_MOTION */
562 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
563 SDL_JoystickID which; /**< The joystick instance id */
564 Uint8 hat; /**< The joystick hat index */
565 Uint8 value; /**< The hat position value.
566 * \sa SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP
567 * \sa SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT
568 * \sa SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN
569 *
570 * Note that zero means the POV is centered.
571 */
575
576/**
577 * Joystick button event structure (event.jbutton.*)
578 *
579 * \since This struct is available since SDL 3.2.0.
580 */
581typedef struct SDL_JoyButtonEvent
582{
583 SDL_EventType type; /**< SDL_EVENT_JOYSTICK_BUTTON_DOWN or SDL_EVENT_JOYSTICK_BUTTON_UP */
585 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
586 SDL_JoystickID which; /**< The joystick instance id */
587 Uint8 button; /**< The joystick button index */
588 bool down; /**< true if the button is pressed */
592
593/**
594 * Joystick device event structure (event.jdevice.*)
595 *
596 * SDL will send JOYSTICK_ADDED events for devices that are already plugged in
597 * during SDL_Init.
598 *
599 * \since This struct is available since SDL 3.2.0.
600 *
601 * \sa SDL_GamepadDeviceEvent
602 */
603typedef struct SDL_JoyDeviceEvent
604{
605 SDL_EventType type; /**< SDL_EVENT_JOYSTICK_ADDED or SDL_EVENT_JOYSTICK_REMOVED or SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */
607 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
608 SDL_JoystickID which; /**< The joystick instance id */
610
611/**
612 * Joystick battery level change event structure (event.jbattery.*)
613 *
614 * \since This struct is available since SDL 3.2.0.
615 */
617{
618 SDL_EventType type; /**< SDL_EVENT_JOYSTICK_BATTERY_UPDATED */
620 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
621 SDL_JoystickID which; /**< The joystick instance id */
622 SDL_PowerState state; /**< The joystick battery state */
623 int percent; /**< The joystick battery percent charge remaining */
625
626/**
627 * Gamepad axis motion event structure (event.gaxis.*)
628 *
629 * \since This struct is available since SDL 3.2.0.
630 */
632{
633 SDL_EventType type; /**< SDL_EVENT_GAMEPAD_AXIS_MOTION */
635 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
636 SDL_JoystickID which; /**< The joystick instance id */
637 Uint8 axis; /**< The gamepad axis (SDL_GamepadAxis) */
641 Sint16 value; /**< The axis value (range: -32768 to 32767) */
644
645
646/**
647 * Gamepad button event structure (event.gbutton.*)
648 *
649 * \since This struct is available since SDL 3.2.0.
650 */
652{
653 SDL_EventType type; /**< SDL_EVENT_GAMEPAD_BUTTON_DOWN or SDL_EVENT_GAMEPAD_BUTTON_UP */
655 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
656 SDL_JoystickID which; /**< The joystick instance id */
657 Uint8 button; /**< The gamepad button (SDL_GamepadButton) */
658 bool down; /**< true if the button is pressed */
662
663
664/**
665 * Gamepad device event structure (event.gdevice.*)
666 *
667 * Joysticks that are supported gamepads receive both an SDL_JoyDeviceEvent
668 * and an SDL_GamepadDeviceEvent.
669 *
670 * SDL will send GAMEPAD_ADDED events for joysticks that are already plugged
671 * in during SDL_Init() and are recognized as gamepads. It will also send
672 * events for joysticks that get gamepad mappings at runtime.
673 *
674 * \since This struct is available since SDL 3.2.0.
675 *
676 * \sa SDL_JoyDeviceEvent
677 */
679{
680 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 */
682 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
683 SDL_JoystickID which; /**< The joystick instance id */
685
686/**
687 * Gamepad touchpad event structure (event.gtouchpad.*)
688 *
689 * \since This struct is available since SDL 3.2.0.
690 */
692{
693 SDL_EventType type; /**< SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or SDL_EVENT_GAMEPAD_TOUCHPAD_UP */
695 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
696 SDL_JoystickID which; /**< The joystick instance id */
697 Sint32 touchpad; /**< The index of the touchpad */
698 Sint32 finger; /**< The index of the finger on the touchpad */
699 float x; /**< Normalized in the range 0...1 with 0 being on the left */
700 float y; /**< Normalized in the range 0...1 with 0 being at the top */
701 float pressure; /**< Normalized in the range 0...1 */
703
704/**
705 * Gamepad sensor event structure (event.gsensor.*)
706 *
707 * \since This struct is available since SDL 3.2.0.
708 */
710{
711 SDL_EventType type; /**< SDL_EVENT_GAMEPAD_SENSOR_UPDATE */
713 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
714 SDL_JoystickID which; /**< The joystick instance id */
715 Sint32 sensor; /**< The type of the sensor, one of the values of SDL_SensorType */
716 float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */
717 Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
719
720/**
721 * Gamepad capsense event structure (event.gcapsense.*)
722 *
723 * \since This struct is available since SDL 3.6.0.
724 */
726{
727 SDL_EventType type; /**< SDL_EVENT_GAMEPAD_CAPSENSE_TOUCH or SDL_EVENT_GAMEPAD_CAPSENSE_RELEASE */
729 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
730 SDL_JoystickID which; /**< The joystick instance id */
731 Uint8 capsense; /**< The capsense type (SDL_GamepadCapSenseType) */
732 bool down; /**< true if the capsense is touched */
736
737/**
738 * Audio device event structure (event.adevice.*)
739 *
740 * Note that SDL will send a SDL_EVENT_AUDIO_DEVICE_ADDED event for every
741 * device it discovers during initialization. After that, this event will only
742 * arrive when a device is hotplugged during the program's run.
743 *
744 * \since This struct is available since SDL 3.2.0.
745 */
747{
748 SDL_EventType type; /**< SDL_EVENT_AUDIO_DEVICE_ADDED, or SDL_EVENT_AUDIO_DEVICE_REMOVED, or SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED */
750 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
751 SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */
752 bool recording; /**< false if a playback device, true if a recording device. */
757
758/**
759 * Camera device event structure (event.cdevice.*)
760 *
761 * \since This struct is available since SDL 3.2.0.
762 */
764{
765 SDL_EventType type; /**< SDL_EVENT_CAMERA_DEVICE_ADDED, SDL_EVENT_CAMERA_DEVICE_REMOVED, SDL_EVENT_CAMERA_DEVICE_APPROVED, SDL_EVENT_CAMERA_DEVICE_DENIED */
767 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
768 SDL_CameraID which; /**< SDL_CameraID for the device being added or removed or changing */
770
771/**
772 * Notification dialog event structure (event.notification.*)
773 *
774 * An `action_id` value of 'default' for an
775 * SDL_EVENT_NOTIFICATION_ACTION_INVOKED event indicates that the notification
776 * was interacted with without selecting a specific action (e.g. the body of
777 * the notification was clicked on).
778 *
779 * \since This struct is available since SDL 3.6.0.
780 */
782{
783 SDL_EventType type; /**< SDL_EVENT_NOTIFICATION_ACTION_INVOKED */
785 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
786 SDL_NotificationID which; /**< The ID of the notification that generated this event. */
787 const char *action_id; /**< The identifier string of the action invoked in the notification dialog. */
789
790/**
791 * Renderer event structure (event.render.*)
792 *
793 * \since This struct is available since SDL 3.2.0.
794 */
795typedef struct SDL_RenderEvent
796{
797 SDL_EventType type; /**< SDL_EVENT_RENDER_TARGETS_RESET, SDL_EVENT_RENDER_DEVICE_RESET, SDL_EVENT_RENDER_DEVICE_LOST */
799 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
800 SDL_WindowID windowID; /**< The window containing the renderer in question. */
802
803
804/**
805 * Touch finger event structure (event.tfinger.*)
806 *
807 * Coordinates in this event are normalized. `x` and `y` are normalized to a
808 * range between 0.0f and 1.0f, relative to the window, so (0,0) is the top
809 * left and (1,1) is the bottom right. Delta coordinates `dx` and `dy` are
810 * normalized in the ranges of -1.0f (traversed all the way from the bottom or
811 * right to all the way up or left) to 1.0f (traversed all the way from the
812 * top or left to all the way down or right).
813 *
814 * Note that while the coordinates are _normalized_, they are not _clamped_,
815 * which means in some circumstances you can get a value outside of this
816 * range. For example, a renderer using logical presentation might give a
817 * negative value when the touch is in the letterboxing. Some platforms might
818 * report a touch outside of the window, which will also be outside of the
819 * range.
820 *
821 * \since This struct is available since SDL 3.2.0.
822 */
824{
825 SDL_EventType type; /**< SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_UP, SDL_EVENT_FINGER_MOTION, or SDL_EVENT_FINGER_CANCELED */
827 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
828 SDL_TouchID touchID; /**< The touch device id */
830 float x; /**< Normalized in the range 0...1 */
831 float y; /**< Normalized in the range 0...1 */
832 float dx; /**< Normalized in the range -1...1 */
833 float dy; /**< Normalized in the range -1...1 */
834 float pressure; /**< Normalized in the range 0...1 */
835 SDL_WindowID windowID; /**< The window underneath the finger, if any */
837
838/**
839 * Pinch event structure (event.pinch.*)
840 */
842{
843 SDL_EventType type; /**< ::SDL_EVENT_PINCH_BEGIN or ::SDL_EVENT_PINCH_UPDATE or ::SDL_EVENT_PINCH_END */
845 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
846 float scale; /**< The scale change since the last SDL_EVENT_PINCH_UPDATE. Scale < 1 is "zoom out". Scale > 1 is "zoom in". */
847 SDL_WindowID windowID; /**< The window underneath the finger, if any */
849
850/**
851 * Pressure-sensitive pen proximity event structure (event.pproximity.*)
852 *
853 * When a pen becomes visible to the system (it is close enough to a tablet,
854 * etc), SDL will send an SDL_EVENT_PEN_PROXIMITY_IN event with the new pen's
855 * ID. This ID is valid until the pen leaves proximity again (has been removed
856 * from the tablet's area, the tablet has been unplugged, etc). If the same
857 * pen reenters proximity again, it will be given a new ID.
858 *
859 * Note that "proximity" means "close enough for the tablet to know the tool
860 * is there." The pen touching and lifting off from the tablet while not
861 * leaving the area are handled by SDL_EVENT_PEN_DOWN and SDL_EVENT_PEN_UP.
862 *
863 * Not all platforms have a window associated with the pen during proximity
864 * events. Some wait until motion/button/etc events to offer this info.
865 *
866 * \since This struct is available since SDL 3.2.0.
867 */
869{
870 SDL_EventType type; /**< SDL_EVENT_PEN_PROXIMITY_IN or SDL_EVENT_PEN_PROXIMITY_OUT */
872 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
873 SDL_WindowID windowID; /**< The window with pen focus, if any */
874 SDL_PenID which; /**< The pen instance id */
876
877/**
878 * Pressure-sensitive pen motion event structure (event.pmotion.*)
879 *
880 * Depending on the hardware, you may get motion events when the pen is not
881 * touching a tablet, for tracking a pen even when it isn't drawing. You
882 * should listen for SDL_EVENT_PEN_DOWN and SDL_EVENT_PEN_UP events, or check
883 * `pen_state & SDL_PEN_INPUT_DOWN` to decide if a pen is "drawing" when
884 * dealing with pen motion.
885 *
886 * \since This struct is available since SDL 3.2.0.
887 */
888typedef struct SDL_PenMotionEvent
889{
890 SDL_EventType type; /**< SDL_EVENT_PEN_MOTION */
892 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
893 SDL_WindowID windowID; /**< The window with pen focus, if any */
894 SDL_PenID which; /**< The pen instance id */
895 SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event */
896 float x; /**< X coordinate, relative to window */
897 float y; /**< Y coordinate, relative to window */
899
900/**
901 * Pressure-sensitive pen touched event structure (event.ptouch.*)
902 *
903 * These events come when a pen touches a surface (a tablet, etc), or lifts
904 * off from one.
905 *
906 * \since This struct is available since SDL 3.2.0.
907 */
908typedef struct SDL_PenTouchEvent
909{
910 SDL_EventType type; /**< SDL_EVENT_PEN_DOWN or SDL_EVENT_PEN_UP */
912 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
913 SDL_WindowID windowID; /**< The window with pen focus, if any */
914 SDL_PenID which; /**< The pen instance id */
915 SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event */
916 float x; /**< X coordinate, relative to window */
917 float y; /**< Y coordinate, relative to window */
918 bool eraser; /**< true if eraser end is used (not all pens support this). */
919 bool down; /**< true if the pen is touching or false if the pen is lifted off */
921
922/**
923 * Pressure-sensitive pen button event structure (event.pbutton.*)
924 *
925 * This is for buttons on the pen itself that the user might click. The pen
926 * itself pressing down to draw triggers a SDL_EVENT_PEN_DOWN event instead.
927 *
928 * \since This struct is available since SDL 3.2.0.
929 */
930typedef struct SDL_PenButtonEvent
931{
932 SDL_EventType type; /**< SDL_EVENT_PEN_BUTTON_DOWN or SDL_EVENT_PEN_BUTTON_UP */
934 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
935 SDL_WindowID windowID; /**< The window with mouse focus, if any */
936 SDL_PenID which; /**< The pen instance id */
937 SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event */
938 float x; /**< X coordinate, relative to window */
939 float y; /**< Y coordinate, relative to window */
940 Uint8 button; /**< The pen button index (first button is 1). */
941 bool down; /**< true if the button is pressed */
943
944/**
945 * Pressure-sensitive pen pressure / angle event structure (event.paxis.*)
946 *
947 * You might get some of these events even if the pen isn't touching the
948 * tablet.
949 *
950 * \since This struct is available since SDL 3.2.0.
951 */
952typedef struct SDL_PenAxisEvent
953{
954 SDL_EventType type; /**< SDL_EVENT_PEN_AXIS */
956 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
957 SDL_WindowID windowID; /**< The window with pen focus, if any */
958 SDL_PenID which; /**< The pen instance id */
959 SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event */
960 float x; /**< X coordinate, relative to window */
961 float y; /**< Y coordinate, relative to window */
962 SDL_PenAxis axis; /**< Axis that has changed */
963 float value; /**< New value of axis */
965
966/**
967 * An event used to drop text or request a file open by the system
968 * (event.drop.*)
969 *
970 * \since This struct is available since SDL 3.2.0.
971 */
972typedef struct SDL_DropEvent
973{
974 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 */
976 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
977 SDL_WindowID windowID; /**< The window that was dropped on, if any */
978 float x; /**< X coordinate, relative to window (not on begin) */
979 float y; /**< Y coordinate, relative to window (not on begin) */
980 const char *source; /**< The source app that sent this drop event, or NULL if that isn't available */
981 const char *data; /**< The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events */
983
984/**
985 * An event triggered when the clipboard contents have changed
986 * (event.clipboard.*)
987 *
988 * \since This struct is available since SDL 3.2.0.
989 */
990typedef struct SDL_ClipboardEvent
991{
992 SDL_EventType type; /**< SDL_EVENT_CLIPBOARD_UPDATE */
994 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
995 bool owner; /**< are we owning the clipboard (internal update) */
996 Sint32 num_mime_types; /**< number of mime types */
997 const char **mime_types; /**< current mime types */
999
1000/**
1001 * Sensor event structure (event.sensor.*)
1002 *
1003 * \since This struct is available since SDL 3.2.0.
1004 */
1005typedef struct SDL_SensorEvent
1006{
1007 SDL_EventType type; /**< SDL_EVENT_SENSOR_UPDATE */
1009 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
1010 SDL_SensorID which; /**< The instance ID of the sensor */
1011 float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_GetSensorData() */
1012 Uint64 sensor_timestamp; /**< The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock */
1014
1015/**
1016 * The "quit requested" event
1017 *
1018 * \since This struct is available since SDL 3.2.0.
1019 */
1020typedef struct SDL_QuitEvent
1021{
1022 SDL_EventType type; /**< SDL_EVENT_QUIT */
1024 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
1026
1027/**
1028 * A user-defined event type (event.user.*)
1029 *
1030 * This event is unique; it is never created by SDL, but only by the
1031 * application. The event can be pushed onto the event queue using
1032 * SDL_PushEvent(). The contents of the structure members are completely up to
1033 * the programmer; the only requirement is that '''type''' is a value obtained
1034 * from SDL_RegisterEvents().
1035 *
1036 * \since This struct is available since SDL 3.2.0.
1037 */
1038typedef struct SDL_UserEvent
1039{
1040 Uint32 type; /**< SDL_EVENT_USER through SDL_EVENT_LAST, Uint32 because these are not in the SDL_EventType enumeration */
1042 Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
1043 SDL_WindowID windowID; /**< The associated window if any */
1044 Sint32 code; /**< User defined event code */
1045 void *data1; /**< User defined data pointer */
1046 void *data2; /**< User defined data pointer */
1048
1049
1050/**
1051 * The structure for all events in SDL.
1052 *
1053 * The SDL_Event structure is the core of all event handling in SDL. SDL_Event
1054 * is a union of all event structures used in SDL.
1055 *
1056 * \since This struct is available since SDL 3.2.0.
1057 */
1058typedef union SDL_Event
1059{
1060 Uint32 type; /**< Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration */
1061 SDL_CommonEvent common; /**< Common event data */
1062 SDL_DisplayEvent display; /**< Display event data */
1063 SDL_WindowEvent window; /**< Window event data */
1064 SDL_KeyboardDeviceEvent kdevice; /**< Keyboard device change event data */
1065 SDL_KeyboardEvent key; /**< Keyboard event data */
1066 SDL_TextEditingEvent edit; /**< Text editing event data */
1067 SDL_TextEditingCandidatesEvent edit_candidates; /**< Text editing candidates event data */
1068 SDL_TextInputEvent text; /**< Text input event data */
1069 SDL_MouseDeviceEvent mdevice; /**< Mouse device change event data */
1070 SDL_MouseMotionEvent motion; /**< Mouse motion event data */
1071 SDL_MouseButtonEvent button; /**< Mouse button event data */
1072 SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
1073 SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
1074 SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
1075 SDL_JoyBallEvent jball; /**< Joystick ball event data */
1076 SDL_JoyHatEvent jhat; /**< Joystick hat event data */
1077 SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
1078 SDL_JoyBatteryEvent jbattery; /**< Joystick battery event data */
1079 SDL_GamepadDeviceEvent gdevice; /**< Gamepad device event data */
1080 SDL_GamepadAxisEvent gaxis; /**< Gamepad axis event data */
1081 SDL_GamepadButtonEvent gbutton; /**< Gamepad button event data */
1082 SDL_GamepadTouchpadEvent gtouchpad; /**< Gamepad touchpad event data */
1083 SDL_GamepadSensorEvent gsensor; /**< Gamepad sensor event data */
1084 SDL_GamepadCapSenseEvent gcapsense; /**< Gamepad capsense event data */
1085 SDL_AudioDeviceEvent adevice; /**< Audio device event data */
1086 SDL_CameraDeviceEvent cdevice; /**< Camera device event data */
1087 SDL_SensorEvent sensor; /**< Sensor event data */
1088 SDL_QuitEvent quit; /**< Quit request event data */
1089 SDL_UserEvent user; /**< Custom event data */
1090 SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
1091 SDL_PinchFingerEvent pinch; /**< Pinch event data */
1092 SDL_PenProximityEvent pproximity; /**< Pen proximity event data */
1093 SDL_PenTouchEvent ptouch; /**< Pen tip touching event data */
1094 SDL_PenMotionEvent pmotion; /**< Pen motion event data */
1095 SDL_PenButtonEvent pbutton; /**< Pen button event data */
1096 SDL_PenAxisEvent paxis; /**< Pen axis event data */
1097 SDL_RenderEvent render; /**< Render event data */
1098 SDL_DropEvent drop; /**< Drag and drop event data */
1099 SDL_ClipboardEvent clipboard; /**< Clipboard event data */
1100 SDL_NotificationEvent notification; /**< Notification event data */
1101
1102 /* This is necessary for ABI compatibility between Visual C++ and GCC.
1103 Visual C++ will respect the push pack pragma and use 52 bytes (size of
1104 SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit
1105 architectures) for this union, and GCC will use the alignment of the
1106 largest datatype within the union, which is 8 bytes on 64-bit
1107 architectures.
1108
1109 So... we'll add padding to force the size to be the same for both.
1110
1111 On architectures where pointers are 16 bytes, this needs rounding up to
1112 the next multiple of 16, 64, and on architectures where pointers are
1113 even larger the size of SDL_UserEvent will dominate as being 3 pointers.
1114 */
1116} SDL_Event;
1117
1118/* Make sure we haven't broken binary compatibility */
1120
1121
1122/* Function prototypes */
1123
1124/**
1125 * Pump the event loop, gathering events from the input devices.
1126 *
1127 * This function updates the event queue and internal input device state.
1128 *
1129 * SDL_PumpEvents() gathers all the pending input information from devices and
1130 * places it in the event queue. Without calls to SDL_PumpEvents() no events
1131 * would ever be placed on the queue. Often the need for calls to
1132 * SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and
1133 * SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not
1134 * polling or waiting for events (e.g. you are filtering them), then you must
1135 * call SDL_PumpEvents() to force an event queue update.
1136 *
1137 * \threadsafety This function should only be called on the main thread.
1138 *
1139 * \since This function is available since SDL 3.2.0.
1140 *
1141 * \sa SDL_PollEvent
1142 * \sa SDL_WaitEvent
1143 */
1144extern SDL_DECLSPEC void SDLCALL SDL_PumpEvents(void);
1145
1146/* @{ */
1147
1148/**
1149 * The type of action to request from SDL_PeepEvents().
1150 *
1151 * \since This enum is available since SDL 3.2.0.
1152 */
1154{
1155 SDL_ADDEVENT, /**< Add events to the back of the queue. */
1156 SDL_PEEKEVENT, /**< Check but don't remove events from the queue front. */
1157 SDL_GETEVENT /**< Retrieve/remove events from the front of the queue. */
1159
1160/**
1161 * Check the event queue for messages and optionally return them.
1162 *
1163 * `action` may be any of the following:
1164 *
1165 * - `SDL_ADDEVENT`: up to `numevents` events will be added to the back of the
1166 * event queue.
1167 * - `SDL_PEEKEVENT`: `numevents` events at the front of the event queue,
1168 * within the specified minimum and maximum type, will be returned to the
1169 * caller and will _not_ be removed from the queue. If you pass NULL for
1170 * `events`, then `numevents` is ignored and the total number of matching
1171 * events will be returned.
1172 * - `SDL_GETEVENT`: up to `numevents` events at the front of the event queue,
1173 * within the specified minimum and maximum type, will be returned to the
1174 * caller and will be removed from the queue.
1175 *
1176 * You may have to call SDL_PumpEvents() before calling this function.
1177 * Otherwise, the events may not be ready to be filtered when you call
1178 * SDL_PeepEvents().
1179 *
1180 * \param events destination buffer for the retrieved events, may be NULL to
1181 * leave the events in the queue and return the number of events
1182 * that would have been stored.
1183 * \param numevents if action is SDL_ADDEVENT, the number of events to add
1184 * back to the event queue; if action is SDL_PEEKEVENT or
1185 * SDL_GETEVENT, the maximum number of events to retrieve.
1186 * \param action action to take; see [Remarks](#remarks) for details.
1187 * \param minType minimum value of the event type to be considered;
1188 * SDL_EVENT_FIRST is a safe choice.
1189 * \param maxType maximum value of the event type to be considered;
1190 * SDL_EVENT_LAST is a safe choice.
1191 * \returns the number of events actually stored or -1 on failure; call
1192 * SDL_GetError() for more information.
1193 *
1194 * \threadsafety It is safe to call this function from any thread.
1195 *
1196 * \since This function is available since SDL 3.2.0.
1197 *
1198 * \sa SDL_PollEvent
1199 * \sa SDL_PumpEvents
1200 * \sa SDL_PushEvent
1201 */
1202extern SDL_DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents, SDL_EventAction action, Uint32 minType, Uint32 maxType);
1203/* @} */
1204
1205/**
1206 * Check for the existence of a certain event type in the event queue.
1207 *
1208 * If you need to check for a range of event types, use SDL_HasEvents()
1209 * instead.
1210 *
1211 * \param type the type of event to be queried; see SDL_EventType for details.
1212 * \returns true if events matching `type` are present, or false if events
1213 * matching `type` are not present.
1214 *
1215 * \threadsafety It is safe to call this function from any thread.
1216 *
1217 * \since This function is available since SDL 3.2.0.
1218 *
1219 * \sa SDL_HasEvents
1220 */
1221extern SDL_DECLSPEC bool SDLCALL SDL_HasEvent(Uint32 type);
1222
1223
1224/**
1225 * Check for the existence of certain event types in the event queue.
1226 *
1227 * If you need to check for a single event type, use SDL_HasEvent() instead.
1228 *
1229 * \param minType the low end of event type to be queried, inclusive; see
1230 * SDL_EventType for details.
1231 * \param maxType the high end of event type to be queried, inclusive; see
1232 * SDL_EventType for details.
1233 * \returns true if events with type >= `minType` and <= `maxType` are
1234 * present, or false if not.
1235 *
1236 * \threadsafety It is safe to call this function from any thread.
1237 *
1238 * \since This function is available since SDL 3.2.0.
1239 *
1240 * \sa SDL_HasEvents
1241 */
1242extern SDL_DECLSPEC bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
1243
1244/**
1245 * Clear events of a specific type from the event queue.
1246 *
1247 * This will unconditionally remove any events from the queue that match
1248 * `type`. If you need to remove a range of event types, use SDL_FlushEvents()
1249 * instead.
1250 *
1251 * It's also normal to just ignore events you don't care about in your event
1252 * loop without calling this function.
1253 *
1254 * This function only affects currently queued events. If you want to make
1255 * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
1256 * on the main thread immediately before the flush call.
1257 *
1258 * If you have user events with custom data that needs to be freed, you should
1259 * use SDL_PeepEvents() to remove and clean up those events before calling
1260 * this function.
1261 *
1262 * \param type the type of event to be cleared; see SDL_EventType for details.
1263 *
1264 * \threadsafety It is safe to call this function from any thread.
1265 *
1266 * \since This function is available since SDL 3.2.0.
1267 *
1268 * \sa SDL_FlushEvents
1269 */
1270extern SDL_DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
1271
1272/**
1273 * Clear events of a range of types from the event queue.
1274 *
1275 * This will unconditionally remove any events from the queue that are in the
1276 * range of `minType` to `maxType`, inclusive. If you need to remove a single
1277 * event type, use SDL_FlushEvent() instead.
1278 *
1279 * It's also normal to just ignore events you don't care about in your event
1280 * loop without calling this function.
1281 *
1282 * This function only affects currently queued events. If you want to make
1283 * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
1284 * on the main thread immediately before the flush call.
1285 *
1286 * \param minType the low end of event type to be cleared, inclusive; see
1287 * SDL_EventType for details.
1288 * \param maxType the high end of event type to be cleared, inclusive; see
1289 * SDL_EventType for details.
1290 *
1291 * \threadsafety It is safe to call this function from any thread.
1292 *
1293 * \since This function is available since SDL 3.2.0.
1294 *
1295 * \sa SDL_FlushEvent
1296 */
1297extern SDL_DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
1298
1299/**
1300 * Poll for currently pending events.
1301 *
1302 * If `event` is not NULL, the next event is removed from the queue and stored
1303 * in the SDL_Event structure pointed to by `event`.
1304 *
1305 * If `event` is NULL, it simply returns true if there is an event in the
1306 * queue, but will not remove it from the queue.
1307 *
1308 * As this function may implicitly call SDL_PumpEvents(), you can only call
1309 * this function in the thread that initialized the video subsystem.
1310 *
1311 * SDL_PollEvent() is the favored way of receiving system events since it can
1312 * be done from the main loop and does not suspend the main loop while waiting
1313 * on an event to be posted.
1314 *
1315 * The common practice is to fully process the event queue once every frame,
1316 * usually as a first step before updating the game's state:
1317 *
1318 * ```c
1319 * while (game_is_still_running) {
1320 * SDL_Event event;
1321 * while (SDL_PollEvent(&event)) { // poll until all events are handled!
1322 * // decide what to do with this event.
1323 * }
1324 *
1325 * // update game state, draw the current frame
1326 * }
1327 * ```
1328 *
1329 * Note that Windows (and possibly other platforms) has a quirk about how it
1330 * handles events while dragging/resizing a window, which can cause this
1331 * function to block for significant amounts of time. Technical explanations
1332 * and solutions are discussed on the wiki:
1333 *
1334 * https://wiki.libsdl.org/SDL3/AppFreezeDuringDrag
1335 *
1336 * \param event the SDL_Event structure to be filled with the next event from
1337 * the queue, or NULL.
1338 * \returns true if this got an event or false if there are none available.
1339 *
1340 * \threadsafety This function should only be called on the main thread.
1341 *
1342 * \since This function is available since SDL 3.2.0.
1343 *
1344 * \sa SDL_PushEvent
1345 * \sa SDL_WaitEvent
1346 * \sa SDL_WaitEventTimeout
1347 */
1348extern SDL_DECLSPEC bool SDLCALL SDL_PollEvent(SDL_Event *event);
1349
1350/**
1351 * Wait indefinitely for the next available event.
1352 *
1353 * If `event` is not NULL, the next event is removed from the queue and stored
1354 * in the SDL_Event structure pointed to by `event`.
1355 *
1356 * As this function may implicitly call SDL_PumpEvents(), you can only call
1357 * this function in the thread that initialized the video subsystem.
1358 *
1359 * \param event the SDL_Event structure to be filled in with the next event
1360 * from the queue, or NULL.
1361 * \returns true on success or false if there was an error while waiting for
1362 * events; call SDL_GetError() for more information.
1363 *
1364 * \threadsafety This function should only be called on the main thread.
1365 *
1366 * \since This function is available since SDL 3.2.0.
1367 *
1368 * \sa SDL_PollEvent
1369 * \sa SDL_PushEvent
1370 * \sa SDL_WaitEventTimeout
1371 */
1372extern SDL_DECLSPEC bool SDLCALL SDL_WaitEvent(SDL_Event *event);
1373
1374/**
1375 * Wait until the specified timeout (in milliseconds) for the next available
1376 * event.
1377 *
1378 * If `event` is not NULL, the next event is removed from the queue and stored
1379 * in the SDL_Event structure pointed to by `event`.
1380 *
1381 * As this function may implicitly call SDL_PumpEvents(), you can only call
1382 * this function in the thread that initialized the video subsystem.
1383 *
1384 * The timeout is not guaranteed, the actual wait time could be longer due to
1385 * system scheduling.
1386 *
1387 * \param event the SDL_Event structure to be filled in with the next event
1388 * from the queue, or NULL.
1389 * \param timeoutMS the maximum number of milliseconds to wait for the next
1390 * available event, or -1 to wait indefinitely.
1391 * \returns true if this got an event or false if the timeout elapsed without
1392 * any events available.
1393 *
1394 * \threadsafety This function should only be called on the main thread.
1395 *
1396 * \since This function is available since SDL 3.2.0.
1397 *
1398 * \sa SDL_PollEvent
1399 * \sa SDL_PushEvent
1400 * \sa SDL_WaitEvent
1401 */
1402extern SDL_DECLSPEC bool SDLCALL SDL_WaitEventTimeout(SDL_Event *event, Sint32 timeoutMS);
1403
1404/**
1405 * Add an event to the event queue.
1406 *
1407 * The event queue can actually be used as a two way communication channel.
1408 * Not only can events be read from the queue, but the user can also push
1409 * their own events onto it. `event` is a pointer to the event structure you
1410 * wish to push onto the queue. The event is copied into the queue, and the
1411 * caller may dispose of the memory pointed to after SDL_PushEvent() returns.
1412 *
1413 * Note: Pushing device input events onto the queue doesn't modify the state
1414 * of the device within SDL.
1415 *
1416 * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
1417 * the event filter but events added with SDL_PeepEvents() do not.
1418 *
1419 * For pushing application-specific events, please use SDL_RegisterEvents() to
1420 * get an event type that does not conflict with other code that also wants
1421 * its own custom event types.
1422 *
1423 * \param event the SDL_Event to be added to the queue.
1424 * \returns true on success, false if the event was filtered or on failure;
1425 * call SDL_GetError() for more information. A common reason for
1426 * error is the event queue being full.
1427 *
1428 * \threadsafety It is safe to call this function from any thread.
1429 *
1430 * \since This function is available since SDL 3.2.0.
1431 *
1432 * \sa SDL_PeepEvents
1433 * \sa SDL_PollEvent
1434 * \sa SDL_RegisterEvents
1435 */
1436extern SDL_DECLSPEC bool SDLCALL SDL_PushEvent(SDL_Event *event);
1437
1438/**
1439 * A function pointer used for callbacks that watch the event queue.
1440 *
1441 * \param userdata what was passed as `userdata` to SDL_SetEventFilter() or
1442 * SDL_AddEventWatch, etc.
1443 * \param event the event that triggered the callback.
1444 * \returns true to permit event to be added to the queue, and false to
1445 * disallow it. When used with SDL_AddEventWatch, the return value is
1446 * ignored.
1447 *
1448 * \threadsafety SDL may call this callback at any time from any thread; the
1449 * application is responsible for locking resources the callback
1450 * touches that need to be protected.
1451 *
1452 * \since This datatype is available since SDL 3.2.0.
1453 *
1454 * \sa SDL_SetEventFilter
1455 * \sa SDL_AddEventWatch
1456 */
1457typedef bool (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
1458
1459/**
1460 * Set up a filter to process all events before they are added to the internal
1461 * event queue.
1462 *
1463 * If you just want to see events without modifying them or preventing them
1464 * from being queued, you should use SDL_AddEventWatch() instead.
1465 *
1466 * If the filter function returns true when called, then the event will be
1467 * added to the internal queue. If it returns false, then the event will be
1468 * dropped from the queue, but the internal state will still be updated. This
1469 * allows selective filtering of dynamically arriving events.
1470 *
1471 * **WARNING**: Be very careful of what you do in the event filter function,
1472 * as it may run in a different thread! The exception is handling of
1473 * SDL_EVENT_WINDOW_EXPOSED, which is guaranteed to be sent from the OS on the
1474 * main thread and you are expected to redraw your window in response to this
1475 * event.
1476 *
1477 * On platforms that support it, if the quit event is generated by an
1478 * interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the
1479 * application at the next event poll.
1480 *
1481 * Note: Disabled events never make it to the event filter function; see
1482 * SDL_SetEventEnabled().
1483 *
1484 * Note: Events pushed onto the queue with SDL_PushEvent() get passed through
1485 * the event filter, but events pushed onto the queue with SDL_PeepEvents() do
1486 * not.
1487 *
1488 * \param filter a function to call when an event happens.
1489 * \param userdata a pointer that is passed to `filter`.
1490 *
1491 * \threadsafety It is safe to call this function from any thread.
1492 *
1493 * \since This function is available since SDL 3.2.0.
1494 *
1495 * \sa SDL_AddEventWatch
1496 * \sa SDL_SetEventEnabled
1497 * \sa SDL_GetEventFilter
1498 * \sa SDL_PeepEvents
1499 * \sa SDL_PushEvent
1500 */
1501extern SDL_DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter, void *userdata);
1502
1503/**
1504 * Query the current event filter.
1505 *
1506 * This function can be used to "chain" filters, by saving the existing filter
1507 * before replacing it with a function that will call that saved filter.
1508 *
1509 * \param filter the current callback function will be stored here.
1510 * \param userdata the pointer that is passed to the current event filter will
1511 * be stored here.
1512 * \returns true on success or false if there is no event filter set.
1513 *
1514 * \threadsafety It is safe to call this function from any thread.
1515 *
1516 * \since This function is available since SDL 3.2.0.
1517 *
1518 * \sa SDL_SetEventFilter
1519 */
1520extern SDL_DECLSPEC bool SDLCALL SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata);
1521
1522/**
1523 * Add a callback to be triggered when an event is added to the event queue.
1524 *
1525 * `filter` will be called when an event happens, and its return value is
1526 * ignored.
1527 *
1528 * **WARNING**: Be very careful of what you do in the event filter function,
1529 * as it may run in a different thread!
1530 *
1531 * If the quit event is generated by a signal (e.g. SIGINT), it will bypass
1532 * the internal queue and be delivered to the watch callback immediately, and
1533 * arrive at the next event poll.
1534 *
1535 * Note: the callback is called for events posted by the user through
1536 * SDL_PushEvent(), but not for disabled events, nor for events by a filter
1537 * callback set with SDL_SetEventFilter(), nor for events posted by the user
1538 * through SDL_PeepEvents().
1539 *
1540 * \param filter an SDL_EventFilter function to call when an event happens.
1541 * \param userdata a pointer that is passed to `filter`.
1542 * \returns true on success or false on failure; call SDL_GetError() for more
1543 * information.
1544 *
1545 * \threadsafety It is safe to call this function from any thread.
1546 *
1547 * \since This function is available since SDL 3.2.0.
1548 *
1549 * \sa SDL_RemoveEventWatch
1550 * \sa SDL_SetEventFilter
1551 */
1552extern SDL_DECLSPEC bool SDLCALL SDL_AddEventWatch(SDL_EventFilter filter, void *userdata);
1553
1554/**
1555 * Remove an event watch callback added with SDL_AddEventWatch().
1556 *
1557 * This function takes the same input as SDL_AddEventWatch() to identify and
1558 * delete the corresponding callback.
1559 *
1560 * \param filter the function originally passed to SDL_AddEventWatch().
1561 * \param userdata the pointer originally passed to SDL_AddEventWatch().
1562 *
1563 * \threadsafety It is safe to call this function from any thread.
1564 *
1565 * \since This function is available since SDL 3.2.0.
1566 *
1567 * \sa SDL_AddEventWatch
1568 */
1569extern SDL_DECLSPEC void SDLCALL SDL_RemoveEventWatch(SDL_EventFilter filter, void *userdata);
1570
1571/**
1572 * Run a specific filter function on the current event queue, removing any
1573 * events for which the filter returns false.
1574 *
1575 * See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(),
1576 * this function does not change the filter permanently, it only uses the
1577 * supplied filter until this function returns.
1578 *
1579 * \param filter the SDL_EventFilter function to call when an event happens.
1580 * \param userdata a pointer that is passed to `filter`.
1581 *
1582 * \threadsafety It is safe to call this function from any thread.
1583 *
1584 * \since This function is available since SDL 3.2.0.
1585 *
1586 * \sa SDL_GetEventFilter
1587 * \sa SDL_SetEventFilter
1588 */
1589extern SDL_DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter, void *userdata);
1590
1591/**
1592 * Set the state of processing events by type.
1593 *
1594 * \param type the type of event; see SDL_EventType for details.
1595 * \param enabled whether to process the event or not.
1596 *
1597 * \threadsafety It is safe to call this function from any thread.
1598 *
1599 * \since This function is available since SDL 3.2.0.
1600 *
1601 * \sa SDL_EventEnabled
1602 */
1603extern SDL_DECLSPEC void SDLCALL SDL_SetEventEnabled(Uint32 type, bool enabled);
1604
1605/**
1606 * Query the state of processing events by type.
1607 *
1608 * \param type the type of event; see SDL_EventType for details.
1609 * \returns true if the event is being processed, false otherwise.
1610 *
1611 * \threadsafety It is safe to call this function from any thread.
1612 *
1613 * \since This function is available since SDL 3.2.0.
1614 *
1615 * \sa SDL_SetEventEnabled
1616 */
1617extern SDL_DECLSPEC bool SDLCALL SDL_EventEnabled(Uint32 type);
1618
1619/**
1620 * Allocate a set of user-defined events, and return the beginning event
1621 * number for that set of events.
1622 *
1623 * \param numevents the number of events to be allocated.
1624 * \returns the beginning event number, or 0 if numevents is invalid or if
1625 * there are not enough user-defined events left.
1626 *
1627 * \threadsafety It is safe to call this function from any thread.
1628 *
1629 * \since This function is available since SDL 3.2.0.
1630 *
1631 * \sa SDL_PushEvent
1632 */
1633extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
1634
1635/**
1636 * Get window associated with an event.
1637 *
1638 * \param event an event containing a `windowID`.
1639 * \returns the associated window on success or NULL if there is none.
1640 *
1641 * \threadsafety It is safe to call this function from any thread.
1642 *
1643 * \since This function is available since SDL 3.2.0.
1644 *
1645 * \sa SDL_PollEvent
1646 * \sa SDL_WaitEvent
1647 * \sa SDL_WaitEventTimeout
1648 */
1649extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetWindowFromEvent(const SDL_Event *event);
1650
1651/**
1652 * Generate an English description of an event.
1653 *
1654 * This will fill `buf` with a null-terminated string that might look
1655 * something like this:
1656 *
1657 * ```
1658 * SDL_EVENT_MOUSE_MOTION (timestamp=1140256324 windowid=2 which=0 state=0 x=492.99 y=139.09 xrel=52 yrel=6)
1659 * ```
1660 *
1661 * The exact format of the string is not guaranteed; it is intended for
1662 * logging purposes, to be read by a human, and not parsed by a computer.
1663 *
1664 * The returned value follows the same rules as SDL_snprintf(): `buf` will
1665 * always be NULL-terminated (unless `buflen` is zero), and will be truncated
1666 * if `buflen` is too small. The return code is the number of bytes needed for
1667 * the complete string, not counting the NULL-terminator, whether the string
1668 * was truncated or not. Unlike SDL_snprintf(), though, this function never
1669 * returns -1.
1670 *
1671 * \param event an event to describe. May be NULL.
1672 * \param buf the buffer to fill with the description string. May be NULL.
1673 * \param buflen the maximum bytes that can be written to `buf`.
1674 * \returns number of bytes needed for the full string, not counting the
1675 * null-terminator byte.
1676 *
1677 * \threadsafety It is safe to call this function from any thread.
1678 *
1679 * \since This function is available since SDL 3.4.0.
1680 */
1681extern SDL_DECLSPEC int SDLCALL SDL_GetEventDescription(const SDL_Event *event, char *buf, int buflen);
1682
1683/* Ends C function definitions when using C++ */
1684#ifdef __cplusplus
1685}
1686#endif
1687#include <SDL3/SDL_close_code.h>
1688
1689#endif /* SDL_events_h_ */
Uint32 SDL_AudioDeviceID
Definition SDL_audio.h:374
#define NULL
Uint32 SDL_CameraID
Definition SDL_camera.h:95
void SDL_RemoveEventWatch(SDL_EventFilter filter, void *userdata)
bool SDL_PollEvent(SDL_Event *event)
void SDL_SetEventEnabled(Uint32 type, bool enabled)
int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_EventAction action, Uint32 minType, Uint32 maxType)
bool SDL_HasEvents(Uint32 minType, Uint32 maxType)
void SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
bool(* SDL_EventFilter)(void *userdata, SDL_Event *event)
bool SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata)
SDL_Window * SDL_GetWindowFromEvent(const SDL_Event *event)
Uint32 SDL_RegisterEvents(int numevents)
SDL_EventType
Definition SDL_events.h:86
@ SDL_EVENT_KEYMAP_CHANGED
Definition SDL_events.h:176
@ SDL_EVENT_SCREEN_KEYBOARD_HIDDEN
Definition SDL_events.h:182
@ SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED
Definition SDL_events.h:130
@ SDL_EVENT_PRIVATE0
Definition SDL_events.h:275
@ SDL_EVENT_PEN_PROXIMITY_OUT
Definition SDL_events.h:252
@ SDL_EVENT_WINDOW_HIT_TEST
Definition SDL_events.h:154
@ SDL_EVENT_GAMEPAD_ADDED
Definition SDL_events.h:207
@ SDL_EVENT_GAMEPAD_TOUCHPAD_UP
Definition SDL_events.h:212
@ SDL_EVENT_WINDOW_RESTORED
Definition SDL_events.h:148
@ SDL_EVENT_GAMEPAD_AXIS_MOTION
Definition SDL_events.h:204
@ SDL_EVENT_WINDOW_LAST
Definition SDL_events.h:169
@ SDL_EVENT_DROP_BEGIN
Definition SDL_events.h:238
@ SDL_EVENT_MOUSE_MOTION
Definition SDL_events.h:185
@ SDL_EVENT_WINDOW_FOCUS_GAINED
Definition SDL_events.h:151
@ SDL_EVENT_WINDOW_SAFE_AREA_CHANGED
Definition SDL_events.h:158
@ SDL_EVENT_MOUSE_WHEEL
Definition SDL_events.h:188
@ SDL_EVENT_JOYSTICK_REMOVED
Definition SDL_events.h:199
@ SDL_EVENT_NOTIFICATION_ACTION_INVOKED
Definition SDL_events.h:267
@ SDL_EVENT_WINDOW_ENTER_FULLSCREEN
Definition SDL_events.h:160
@ SDL_EVENT_PEN_DOWN
Definition SDL_events.h:253
@ SDL_EVENT_CLIPBOARD_UPDATE
Definition SDL_events.h:233
@ SDL_EVENT_DID_ENTER_FOREGROUND
Definition SDL_events.h:113
@ SDL_EVENT_JOYSTICK_BUTTON_UP
Definition SDL_events.h:197
@ SDL_EVENT_JOYSTICK_BATTERY_UPDATED
Definition SDL_events.h:200
@ SDL_EVENT_WILL_ENTER_FOREGROUND
Definition SDL_events.h:109
@ SDL_EVENT_PEN_MOTION
Definition SDL_events.h:257
@ SDL_EVENT_POLL_SENTINEL
Definition SDL_events.h:281
@ SDL_EVENT_CAMERA_DEVICE_REMOVED
Definition SDL_events.h:262
@ SDL_EVENT_JOYSTICK_UPDATE_COMPLETE
Definition SDL_events.h:201
@ SDL_EVENT_FINGER_UP
Definition SDL_events.h:221
@ SDL_EVENT_DISPLAY_REMOVED
Definition SDL_events.h:126
@ SDL_EVENT_JOYSTICK_ADDED
Definition SDL_events.h:198
@ SDL_EVENT_MOUSE_ADDED
Definition SDL_events.h:189
@ SDL_EVENT_DROP_POSITION
Definition SDL_events.h:240
@ SDL_EVENT_WINDOW_EXPOSED
Definition SDL_events.h:140
@ SDL_EVENT_WINDOW_DISPLAY_CHANGED
Definition SDL_events.h:156
@ SDL_EVENT_WINDOW_RESIZED
Definition SDL_events.h:143
@ SDL_EVENT_ENUM_PADDING
Definition SDL_events.h:294
@ SDL_EVENT_PINCH_END
Definition SDL_events.h:228
@ SDL_EVENT_GAMEPAD_REMAPPED
Definition SDL_events.h:209
@ SDL_EVENT_GAMEPAD_REMOVED
Definition SDL_events.h:208
@ SDL_EVENT_WINDOW_HDR_STATE_CHANGED
Definition SDL_events.h:166
@ SDL_EVENT_FINGER_MOTION
Definition SDL_events.h:222
@ SDL_EVENT_WINDOW_MOUSE_ENTER
Definition SDL_events.h:149
@ SDL_EVENT_WINDOW_HIDDEN
Definition SDL_events.h:139
@ SDL_EVENT_WINDOW_SETTINGS_CHANGED
Definition SDL_events.h:167
@ SDL_EVENT_RENDER_TARGETS_RESET
Definition SDL_events.h:270
@ SDL_EVENT_MOUSE_REMOVED
Definition SDL_events.h:190
@ SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED
Definition SDL_events.h:131
@ SDL_EVENT_SCREEN_KEYBOARD_SHOWN
Definition SDL_events.h:181
@ SDL_EVENT_DID_ENTER_BACKGROUND
Definition SDL_events.h:105
@ SDL_EVENT_CAMERA_DEVICE_APPROVED
Definition SDL_events.h:263
@ SDL_EVENT_GAMEPAD_CAPSENSE_RELEASE
Definition SDL_events.h:217
@ SDL_EVENT_AUDIO_DEVICE_ADDED
Definition SDL_events.h:243
@ SDL_EVENT_RENDER_DEVICE_RESET
Definition SDL_events.h:271
@ SDL_EVENT_LOW_MEMORY
Definition SDL_events.h:97
@ SDL_EVENT_GAMEPAD_UPDATE_COMPLETE
Definition SDL_events.h:214
@ SDL_EVENT_WINDOW_DESTROYED
Definition SDL_events.h:162
@ SDL_EVENT_PEN_UP
Definition SDL_events.h:254
@ SDL_EVENT_GAMEPAD_BUTTON_DOWN
Definition SDL_events.h:205
@ SDL_EVENT_DISPLAY_ADDED
Definition SDL_events.h:125
@ SDL_EVENT_JOYSTICK_AXIS_MOTION
Definition SDL_events.h:193
@ SDL_EVENT_KEY_UP
Definition SDL_events.h:173
@ SDL_EVENT_WINDOW_CLOSE_REQUESTED
Definition SDL_events.h:153
@ SDL_EVENT_TEXT_INPUT
Definition SDL_events.h:175
@ SDL_EVENT_LOCALE_CHANGED
Definition SDL_events.h:118
@ SDL_EVENT_WINDOW_OCCLUDED
Definition SDL_events.h:159
@ SDL_EVENT_GAMEPAD_CAPSENSE_TOUCH
Definition SDL_events.h:216
@ SDL_EVENT_DISPLAY_LAST
Definition SDL_events.h:133
@ SDL_EVENT_WILL_ENTER_BACKGROUND
Definition SDL_events.h:101
@ SDL_EVENT_MOUSE_BUTTON_DOWN
Definition SDL_events.h:186
@ SDL_EVENT_USER
Definition SDL_events.h:286
@ SDL_EVENT_WINDOW_FIRST
Definition SDL_events.h:168
@ SDL_EVENT_SENSOR_UPDATE
Definition SDL_events.h:248
@ SDL_EVENT_PEN_BUTTON_DOWN
Definition SDL_events.h:255
@ SDL_EVENT_FIRST
Definition SDL_events.h:87
@ SDL_EVENT_PEN_PROXIMITY_IN
Definition SDL_events.h:251
@ SDL_EVENT_FINGER_CANCELED
Definition SDL_events.h:223
@ SDL_EVENT_DISPLAY_MOVED
Definition SDL_events.h:127
@ SDL_EVENT_JOYSTICK_BUTTON_DOWN
Definition SDL_events.h:196
@ SDL_EVENT_PEN_BUTTON_UP
Definition SDL_events.h:256
@ SDL_EVENT_MOUSE_BUTTON_UP
Definition SDL_events.h:187
@ SDL_EVENT_PRIVATE1
Definition SDL_events.h:276
@ SDL_EVENT_DROP_TEXT
Definition SDL_events.h:237
@ SDL_EVENT_DROP_FILE
Definition SDL_events.h:236
@ SDL_EVENT_KEYBOARD_REMOVED
Definition SDL_events.h:179
@ SDL_EVENT_WINDOW_FOCUS_LOST
Definition SDL_events.h:152
@ SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED
Definition SDL_events.h:215
@ SDL_EVENT_GAMEPAD_BUTTON_UP
Definition SDL_events.h:206
@ SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED
Definition SDL_events.h:129
@ SDL_EVENT_WINDOW_MAXIMIZED
Definition SDL_events.h:147
@ SDL_EVENT_PINCH_UPDATE
Definition SDL_events.h:227
@ SDL_EVENT_PINCH_BEGIN
Definition SDL_events.h:226
@ SDL_EVENT_PEN_AXIS
Definition SDL_events.h:258
@ SDL_EVENT_TERMINATING
Definition SDL_events.h:93
@ SDL_EVENT_RENDER_DEVICE_LOST
Definition SDL_events.h:272
@ SDL_EVENT_WINDOW_ICCPROF_CHANGED
Definition SDL_events.h:155
@ SDL_EVENT_SYSTEM_THEME_CHANGED
Definition SDL_events.h:120
@ SDL_EVENT_WINDOW_LEAVE_FULLSCREEN
Definition SDL_events.h:161
@ SDL_EVENT_CAMERA_DEVICE_ADDED
Definition SDL_events.h:261
@ SDL_EVENT_KEYBOARD_ADDED
Definition SDL_events.h:178
@ SDL_EVENT_GAMEPAD_SENSOR_UPDATE
Definition SDL_events.h:213
@ SDL_EVENT_JOYSTICK_HAT_MOTION
Definition SDL_events.h:195
@ SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED
Definition SDL_events.h:245
@ SDL_EVENT_JOYSTICK_BALL_MOTION
Definition SDL_events.h:194
@ SDL_EVENT_PRIVATE3
Definition SDL_events.h:278
@ SDL_EVENT_WINDOW_SHOWN
Definition SDL_events.h:138
@ SDL_EVENT_KEY_DOWN
Definition SDL_events.h:172
@ SDL_EVENT_CAMERA_DEVICE_DENIED
Definition SDL_events.h:264
@ SDL_EVENT_TEXT_EDITING_CANDIDATES
Definition SDL_events.h:180
@ SDL_EVENT_WINDOW_MOVED
Definition SDL_events.h:142
@ SDL_EVENT_DISPLAY_FIRST
Definition SDL_events.h:132
@ SDL_EVENT_WINDOW_MINIMIZED
Definition SDL_events.h:146
@ SDL_EVENT_WINDOW_METAL_VIEW_RESIZED
Definition SDL_events.h:145
@ SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED
Definition SDL_events.h:144
@ SDL_EVENT_DISPLAY_ORIENTATION
Definition SDL_events.h:124
@ SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED
Definition SDL_events.h:157
@ SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION
Definition SDL_events.h:211
@ SDL_EVENT_LAST
Definition SDL_events.h:291
@ SDL_EVENT_AUDIO_DEVICE_REMOVED
Definition SDL_events.h:244
@ SDL_EVENT_DROP_COMPLETE
Definition SDL_events.h:239
@ SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN
Definition SDL_events.h:210
@ SDL_EVENT_TEXT_EDITING
Definition SDL_events.h:174
@ SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED
Definition SDL_events.h:128
@ SDL_EVENT_WINDOW_MOUSE_LEAVE
Definition SDL_events.h:150
@ SDL_EVENT_QUIT
Definition SDL_events.h:90
@ SDL_EVENT_PRIVATE2
Definition SDL_events.h:277
@ SDL_EVENT_FINGER_DOWN
Definition SDL_events.h:220
bool SDL_WaitEvent(SDL_Event *event)
bool SDL_EventEnabled(Uint32 type)
void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
bool SDL_HasEvent(Uint32 type)
bool SDL_PushEvent(SDL_Event *event)
int SDL_GetEventDescription(const SDL_Event *event, char *buf, int buflen)
void SDL_FlushEvents(Uint32 minType, Uint32 maxType)
SDL_EventAction
@ SDL_ADDEVENT
@ SDL_PEEKEVENT
@ SDL_GETEVENT
void SDL_FlushEvent(Uint32 type)
bool SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
void SDL_PumpEvents(void)
bool SDL_WaitEventTimeout(SDL_Event *event, Sint32 timeoutMS)
Uint32 SDL_JoystickID
Uint32 SDL_KeyboardID
Uint16 SDL_Keymod
Uint32 SDL_Keycode
Definition SDL_keycode.h:59
Uint32 SDL_MouseID
Definition SDL_mouse.h:81
Uint32 SDL_MouseButtonFlags
Definition SDL_mouse.h:173
SDL_MouseWheelDirection
Definition SDL_mouse.h:142
Uint32 SDL_NotificationID
Uint32 SDL_PenID
Definition SDL_pen.h:93
SDL_PenAxis
Definition SDL_pen.h:141
Uint32 SDL_PenInputFlags
Definition SDL_pen.h:114
SDL_PowerState
Definition SDL_power.h:57
SDL_Scancode
Uint32 SDL_SensorID
Definition SDL_sensor.h:64
uint8_t Uint8
Definition SDL_stdinc.h:459
uint16_t Uint16
Definition SDL_stdinc.h:477
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:358
int32_t Sint32
Definition SDL_stdinc.h:486
int16_t Sint16
Definition SDL_stdinc.h:468
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:238
#define bool
Definition SDL_stdinc.h:101
uint64_t Uint64
Definition SDL_stdinc.h:517
uint32_t Uint32
Definition SDL_stdinc.h:495
Uint64 SDL_TouchID
Definition SDL_touch.h:62
Uint64 SDL_FingerID
Definition SDL_touch.h:76
Uint32 SDL_DisplayID
Definition SDL_video.h:75
struct SDL_Window SDL_Window
Definition SDL_video.h:175
Uint32 SDL_WindowID
Definition SDL_video.h:84
SDL_AudioDeviceID which
Definition SDL_events.h:751
SDL_EventType type
Definition SDL_events.h:748
SDL_EventType type
Definition SDL_events.h:765
const char ** mime_types
Definition SDL_events.h:997
SDL_EventType type
Definition SDL_events.h:992
SDL_DisplayID displayID
Definition SDL_events.h:320
SDL_EventType type
Definition SDL_events.h:317
SDL_EventType type
Definition SDL_events.h:974
SDL_WindowID windowID
Definition SDL_events.h:977
Uint64 timestamp
Definition SDL_events.h:976
const char * data
Definition SDL_events.h:981
Uint32 reserved
Definition SDL_events.h:975
const char * source
Definition SDL_events.h:980
SDL_JoystickID which
Definition SDL_events.h:636
SDL_EventType type
Definition SDL_events.h:633
SDL_JoystickID which
Definition SDL_events.h:656
SDL_JoystickID which
Definition SDL_events.h:683
SDL_JoystickID which
Definition SDL_events.h:714
SDL_EventType type
Definition SDL_events.h:522
SDL_JoystickID which
Definition SDL_events.h:525
SDL_EventType type
Definition SDL_events.h:541
SDL_JoystickID which
Definition SDL_events.h:544
SDL_JoystickID which
Definition SDL_events.h:621
SDL_PowerState state
Definition SDL_events.h:622
SDL_EventType type
Definition SDL_events.h:618
SDL_JoystickID which
Definition SDL_events.h:586
SDL_EventType type
Definition SDL_events.h:583
SDL_EventType type
Definition SDL_events.h:605
SDL_JoystickID which
Definition SDL_events.h:608
SDL_JoystickID which
Definition SDL_events.h:563
SDL_EventType type
Definition SDL_events.h:560
SDL_KeyboardID which
Definition SDL_events.h:350
SDL_EventType type
Definition SDL_events.h:369
SDL_Keycode key
Definition SDL_events.h:375
SDL_KeyboardID which
Definition SDL_events.h:373
SDL_WindowID windowID
Definition SDL_events.h:372
SDL_Scancode scancode
Definition SDL_events.h:374
SDL_WindowID windowID
Definition SDL_events.h:484
SDL_EventType type
Definition SDL_events.h:481
SDL_EventType type
Definition SDL_events.h:449
SDL_WindowID windowID
Definition SDL_events.h:465
SDL_EventType type
Definition SDL_events.h:462
SDL_MouseButtonFlags state
Definition SDL_events.h:467
SDL_MouseWheelDirection direction
Definition SDL_events.h:508
SDL_EventType type
Definition SDL_events.h:501
SDL_MouseID which
Definition SDL_events.h:505
SDL_WindowID windowID
Definition SDL_events.h:504
SDL_EventType type
Definition SDL_events.h:783
SDL_NotificationID which
Definition SDL_events.h:786
const char * action_id
Definition SDL_events.h:787
SDL_PenAxis axis
Definition SDL_events.h:962
SDL_PenID which
Definition SDL_events.h:958
SDL_WindowID windowID
Definition SDL_events.h:957
SDL_PenInputFlags pen_state
Definition SDL_events.h:959
SDL_EventType type
Definition SDL_events.h:954
SDL_WindowID windowID
Definition SDL_events.h:935
SDL_EventType type
Definition SDL_events.h:932
SDL_PenInputFlags pen_state
Definition SDL_events.h:937
SDL_WindowID windowID
Definition SDL_events.h:893
SDL_EventType type
Definition SDL_events.h:890
SDL_PenInputFlags pen_state
Definition SDL_events.h:895
SDL_EventType type
Definition SDL_events.h:870
SDL_WindowID windowID
Definition SDL_events.h:873
SDL_EventType type
Definition SDL_events.h:910
SDL_WindowID windowID
Definition SDL_events.h:913
SDL_PenInputFlags pen_state
Definition SDL_events.h:915
SDL_EventType type
Definition SDL_events.h:843
SDL_WindowID windowID
Definition SDL_events.h:847
SDL_EventType type
SDL_EventType type
Definition SDL_events.h:797
SDL_WindowID windowID
Definition SDL_events.h:800
Uint64 sensor_timestamp
SDL_EventType type
SDL_SensorID which
const char *const * candidates
Definition SDL_events.h:413
SDL_EventType type
Definition SDL_events.h:393
const char * text
Definition SDL_events.h:397
SDL_WindowID windowID
Definition SDL_events.h:396
const char * text
Definition SDL_events.h:439
SDL_WindowID windowID
Definition SDL_events.h:438
SDL_EventType type
Definition SDL_events.h:435
SDL_FingerID fingerID
Definition SDL_events.h:829
SDL_TouchID touchID
Definition SDL_events.h:828
SDL_EventType type
Definition SDL_events.h:825
SDL_WindowID windowID
Definition SDL_events.h:835
SDL_WindowID windowID
SDL_EventType type
Definition SDL_events.h:332
SDL_WindowID windowID
Definition SDL_events.h:335
SDL_QuitEvent quit
SDL_AudioDeviceEvent adevice
SDL_PenProximityEvent pproximity
Uint8 padding[128]
SDL_JoyDeviceEvent jdevice
Uint32 type
SDL_MouseWheelEvent wheel
SDL_PenTouchEvent ptouch
SDL_PenMotionEvent pmotion
SDL_JoyHatEvent jhat
SDL_ClipboardEvent clipboard
SDL_RenderEvent render
SDL_JoyButtonEvent jbutton
SDL_GamepadDeviceEvent gdevice
SDL_GamepadCapSenseEvent gcapsense
SDL_GamepadAxisEvent gaxis
SDL_PenAxisEvent paxis
SDL_WindowEvent window
SDL_CameraDeviceEvent cdevice
SDL_PinchFingerEvent pinch
SDL_GamepadTouchpadEvent gtouchpad
SDL_KeyboardDeviceEvent kdevice
SDL_TextEditingEvent edit
SDL_TextInputEvent text
SDL_PenButtonEvent pbutton
SDL_GamepadSensorEvent gsensor
SDL_TouchFingerEvent tfinger
SDL_MouseButtonEvent button
SDL_UserEvent user
SDL_KeyboardEvent key
SDL_CommonEvent common
SDL_MouseMotionEvent motion
SDL_JoyAxisEvent jaxis
SDL_MouseDeviceEvent mdevice
SDL_DropEvent drop
SDL_JoyBallEvent jball
SDL_JoyBatteryEvent jbattery
SDL_SensorEvent sensor
SDL_GamepadButtonEvent gbutton
SDL_TextEditingCandidatesEvent edit_candidates
SDL_NotificationEvent notification
SDL_DisplayEvent display