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