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