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