1 /* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20 */ 21 22 /** 23 * # CategoryEvents 24 * 25 * Include file for SDL event handling. 26 */ 27 28 #ifndef SDL_events_h_ 29 #define SDL_events_h_ 30 31 #include "SDL_stdinc.h" 32 #include "SDL_error.h" 33 #include "SDL_video.h" 34 #include "SDL_keyboard.h" 35 #include "SDL_mouse.h" 36 #include "SDL_joystick.h" 37 #include "SDL_gamecontroller.h" 38 #include "SDL_quit.h" 39 #include "SDL_gesture.h" 40 #include "SDL_touch.h" 41 42 #include "begin_code.h" 43 /* Set up for C function definitions, even when using C++ */ 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /* General keyboard/mouse state definitions */ 49 #define SDL_RELEASED 0 50 #define SDL_PRESSED 1 51 52 /** 53 * The types of events that can be delivered. 54 */ 55 typedef enum SDL_EventType 56 { 57 SDL_FIRSTEVENT = 0, /**< Unused (do not remove) */ 58 59 /* Application events */ 60 SDL_QUIT = 0x100, /**< User-requested quit */ 61 62 /* These application events have special meaning on iOS, see README-ios.md for details */ 63 SDL_APP_TERMINATING, /**< The application is being terminated by the OS 64 Called on iOS in applicationWillTerminate() 65 Called on Android in onDestroy() 66 */ 67 SDL_APP_LOWMEMORY, /**< The application is low on memory, free memory if possible. 68 Called on iOS in applicationDidReceiveMemoryWarning() 69 Called on Android in onLowMemory() 70 */ 71 SDL_APP_WILLENTERBACKGROUND, /**< The application is about to enter the background 72 Called on iOS in applicationWillResignActive() 73 Called on Android in onPause() 74 */ 75 SDL_APP_DIDENTERBACKGROUND, /**< The application did enter the background and may not get CPU for some time 76 Called on iOS in applicationDidEnterBackground() 77 Called on Android in onPause() 78 */ 79 SDL_APP_WILLENTERFOREGROUND, /**< The application is about to enter the foreground 80 Called on iOS in applicationWillEnterForeground() 81 Called on Android in onResume() 82 */ 83 SDL_APP_DIDENTERFOREGROUND, /**< The application is now interactive 84 Called on iOS in applicationDidBecomeActive() 85 Called on Android in onResume() 86 */ 87 88 SDL_LOCALECHANGED, /**< The user's locale preferences have changed. */ 89 90 /* Display events */ 91 SDL_DISPLAYEVENT = 0x150, /**< Display state change */ 92 93 /* Window events */ 94 SDL_WINDOWEVENT = 0x200, /**< Window state change */ 95 SDL_SYSWMEVENT, /**< System specific event */ 96 97 /* Keyboard events */ 98 SDL_KEYDOWN = 0x300, /**< Key pressed */ 99 SDL_KEYUP, /**< Key released */ 100 SDL_TEXTEDITING, /**< Keyboard text editing (composition) */ 101 SDL_TEXTINPUT, /**< Keyboard text input */ 102 SDL_KEYMAPCHANGED, /**< Keymap changed due to a system event such as an 103 input language or keyboard layout change. 104 */ 105 SDL_TEXTEDITING_EXT, /**< Extended keyboard text editing (composition) */ 106 107 /* Mouse events */ 108 SDL_MOUSEMOTION = 0x400, /**< Mouse moved */ 109 SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */ 110 SDL_MOUSEBUTTONUP, /**< Mouse button released */ 111 SDL_MOUSEWHEEL, /**< Mouse wheel motion */ 112 113 /* Joystick events */ 114 SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */ 115 SDL_JOYBALLMOTION, /**< Joystick trackball motion */ 116 SDL_JOYHATMOTION, /**< Joystick hat position change */ 117 SDL_JOYBUTTONDOWN, /**< Joystick button pressed */ 118 SDL_JOYBUTTONUP, /**< Joystick button released */ 119 SDL_JOYDEVICEADDED, /**< A new joystick has been inserted into the system */ 120 SDL_JOYDEVICEREMOVED, /**< An opened joystick has been removed */ 121 SDL_JOYBATTERYUPDATED, /**< Joystick battery level change */ 122 123 /* Game controller events */ 124 SDL_CONTROLLERAXISMOTION = 0x650, /**< Game controller axis motion */ 125 SDL_CONTROLLERBUTTONDOWN, /**< Game controller button pressed */ 126 SDL_CONTROLLERBUTTONUP, /**< Game controller button released */ 127 SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */ 128 SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */ 129 SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */ 130 SDL_CONTROLLERTOUCHPADDOWN, /**< Game controller touchpad was touched */ 131 SDL_CONTROLLERTOUCHPADMOTION, /**< Game controller touchpad finger was moved */ 132 SDL_CONTROLLERTOUCHPADUP, /**< Game controller touchpad finger was lifted */ 133 SDL_CONTROLLERSENSORUPDATE, /**< Game controller sensor was updated */ 134 SDL_CONTROLLERUPDATECOMPLETE_RESERVED_FOR_SDL3, 135 SDL_CONTROLLERSTEAMHANDLEUPDATED, /**< Game controller Steam handle has changed */ 136 137 /* Touch events */ 138 SDL_FINGERDOWN = 0x700, 139 SDL_FINGERUP, 140 SDL_FINGERMOTION, 141 142 /* Gesture events */ 143 SDL_DOLLARGESTURE = 0x800, 144 SDL_DOLLARRECORD, 145 SDL_MULTIGESTURE, 146 147 /* Clipboard events */ 148 SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard or primary selection changed */ 149 150 /* Drag and drop events */ 151 SDL_DROPFILE = 0x1000, /**< The system requests a file open */ 152 SDL_DROPTEXT, /**< text/plain drag-and-drop event */ 153 SDL_DROPBEGIN, /**< A new set of drops is beginning (NULL filename) */ 154 SDL_DROPCOMPLETE, /**< Current set of drops is now complete (NULL filename) */ 155 156 /* Audio hotplug events */ 157 SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */ 158 SDL_AUDIODEVICEREMOVED, /**< An audio device has been removed. */ 159 160 /* Sensor events */ 161 SDL_SENSORUPDATE = 0x1200, /**< A sensor was updated */ 162 163 /* Render events */ 164 SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */ 165 SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */ 166 167 /* Internal events */ 168 SDL_POLLSENTINEL = 0x7F00, /**< Signals the end of an event poll cycle */ 169 170 /** Events SDL_USEREVENT through SDL_LASTEVENT are for your use, 171 * and should be allocated with SDL_RegisterEvents() 172 */ 173 SDL_USEREVENT = 0x8000, 174 175 /** 176 * This last event is only for bounding internal arrays 177 */ 178 SDL_LASTEVENT = 0xFFFF 179 } SDL_EventType; 180 181 /** 182 * Fields shared by every event 183 */ 184 typedef struct SDL_CommonEvent 185 { 186 Uint32 type; 187 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 188 } SDL_CommonEvent; 189 190 /** 191 * Display state change event data (event.display.*) 192 */ 193 typedef struct SDL_DisplayEvent 194 { 195 Uint32 type; /**< SDL_DISPLAYEVENT */ 196 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 197 Uint32 display; /**< The associated display index */ 198 Uint8 event; /**< SDL_DisplayEventID */ 199 Uint8 padding1; 200 Uint8 padding2; 201 Uint8 padding3; 202 Sint32 data1; /**< event dependent data */ 203 } SDL_DisplayEvent; 204 205 /** 206 * Window state change event data (event.window.*) 207 */ 208 typedef struct SDL_WindowEvent 209 { 210 Uint32 type; /**< SDL_WINDOWEVENT */ 211 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 212 Uint32 windowID; /**< The associated window */ 213 Uint8 event; /**< SDL_WindowEventID */ 214 Uint8 padding1; 215 Uint8 padding2; 216 Uint8 padding3; 217 Sint32 data1; /**< event dependent data */ 218 Sint32 data2; /**< event dependent data */ 219 } SDL_WindowEvent; 220 221 /** 222 * Keyboard button event structure (event.key.*) 223 */ 224 typedef struct SDL_KeyboardEvent 225 { 226 Uint32 type; /**< SDL_KEYDOWN or SDL_KEYUP */ 227 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 228 Uint32 windowID; /**< The window with keyboard focus, if any */ 229 Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ 230 Uint8 repeat; /**< Non-zero if this is a key repeat */ 231 Uint8 padding2; 232 Uint8 padding3; 233 SDL_Keysym keysym; /**< The key that was pressed or released */ 234 } SDL_KeyboardEvent; 235 236 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32) 237 238 /** 239 * Keyboard text editing event structure (event.edit.*) 240 */ 241 typedef struct SDL_TextEditingEvent 242 { 243 Uint32 type; /**< SDL_TEXTEDITING */ 244 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 245 Uint32 windowID; /**< The window with keyboard focus, if any */ 246 char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */ 247 Sint32 start; /**< The start cursor of selected editing text */ 248 Sint32 length; /**< The length of selected editing text */ 249 } SDL_TextEditingEvent; 250 251 /** 252 * Extended keyboard text editing event structure (event.editExt.*) when text 253 * would be truncated if stored in the text buffer SDL_TextEditingEvent 254 */ 255 typedef struct SDL_TextEditingExtEvent 256 { 257 Uint32 type; /**< SDL_TEXTEDITING_EXT */ 258 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 259 Uint32 windowID; /**< The window with keyboard focus, if any */ 260 char* text; /**< The editing text, which should be freed with SDL_free(), and will not be NULL */ 261 Sint32 start; /**< The start cursor of selected editing text */ 262 Sint32 length; /**< The length of selected editing text */ 263 } SDL_TextEditingExtEvent; 264 265 /** 266 * The maximum bytes of text that can be supplied in an SDL_TextInputEvent. 267 */ 268 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32) 269 270 /** 271 * Keyboard text input event structure (event.text.*) 272 * 273 * `text` is limited to SDL_TEXTINPUTEVENT_TEXT_SIZE bytes. If the incoming 274 * string is larger than this, SDL will split it and send it in pieces, across 275 * multiple events. The string is in UTF-8 format, and if split, SDL 276 * guarantees that it will not split in the middle of a UTF-8 sequence, so any 277 * event will only contain complete codepoints. However, if there are several 278 * codepoints that go together into a single glyph (like an emoji "thumbs up" 279 * followed by a skin color), they may be split between events. 280 * 281 * This event will never be delivered unless text input is enabled by calling 282 * SDL_StartTextInput(). Text input is enabled by default on desktop 283 * platforms, and disabled by default on mobile platforms! 284 * 285 * \sa SDL_StartTextInput 286 * \sa SDL_StopTextInput 287 */ 288 typedef struct SDL_TextInputEvent 289 { 290 Uint32 type; /**< SDL_TEXTINPUT */ 291 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 292 Uint32 windowID; /**< The window with keyboard focus, if any */ 293 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text; UTF-8 encoded. */ 294 } SDL_TextInputEvent; 295 296 /** 297 * Mouse motion event structure (event.motion.*) 298 */ 299 typedef struct SDL_MouseMotionEvent 300 { 301 Uint32 type; /**< SDL_MOUSEMOTION */ 302 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 303 Uint32 windowID; /**< The window with mouse focus, if any */ 304 Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ 305 Uint32 state; /**< The current button state */ 306 Sint32 x; /**< X coordinate, relative to window */ 307 Sint32 y; /**< Y coordinate, relative to window */ 308 Sint32 xrel; /**< The relative motion in the X direction */ 309 Sint32 yrel; /**< The relative motion in the Y direction */ 310 } SDL_MouseMotionEvent; 311 312 /** 313 * Mouse button event structure (event.button.*) 314 */ 315 typedef struct SDL_MouseButtonEvent 316 { 317 Uint32 type; /**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ 318 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 319 Uint32 windowID; /**< The window with mouse focus, if any */ 320 Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ 321 Uint8 button; /**< The mouse button index */ 322 Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ 323 Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */ 324 Uint8 padding1; 325 Sint32 x; /**< X coordinate, relative to window */ 326 Sint32 y; /**< Y coordinate, relative to window */ 327 } SDL_MouseButtonEvent; 328 329 /** 330 * Mouse wheel event structure (event.wheel.*) 331 */ 332 typedef struct SDL_MouseWheelEvent 333 { 334 Uint32 type; /**< SDL_MOUSEWHEEL */ 335 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 336 Uint32 windowID; /**< The window with mouse focus, if any */ 337 Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */ 338 Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */ 339 Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */ 340 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 */ 341 float preciseX; /**< The amount scrolled horizontally, positive to the right and negative to the left, with float precision (added in 2.0.18) */ 342 float preciseY; /**< The amount scrolled vertically, positive away from the user and negative toward the user, with float precision (added in 2.0.18) */ 343 Sint32 mouseX; /**< X coordinate, relative to window (added in 2.26.0) */ 344 Sint32 mouseY; /**< Y coordinate, relative to window (added in 2.26.0) */ 345 } SDL_MouseWheelEvent; 346 347 /** 348 * Joystick axis motion event structure (event.jaxis.*) 349 */ 350 typedef struct SDL_JoyAxisEvent 351 { 352 Uint32 type; /**< SDL_JOYAXISMOTION */ 353 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 354 SDL_JoystickID which; /**< The joystick instance id */ 355 Uint8 axis; /**< The joystick axis index */ 356 Uint8 padding1; 357 Uint8 padding2; 358 Uint8 padding3; 359 Sint16 value; /**< The axis value (range: -32768 to 32767) */ 360 Uint16 padding4; 361 } SDL_JoyAxisEvent; 362 363 /** 364 * Joystick trackball motion event structure (event.jball.*) 365 */ 366 typedef struct SDL_JoyBallEvent 367 { 368 Uint32 type; /**< SDL_JOYBALLMOTION */ 369 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 370 SDL_JoystickID which; /**< The joystick instance id */ 371 Uint8 ball; /**< The joystick trackball index */ 372 Uint8 padding1; 373 Uint8 padding2; 374 Uint8 padding3; 375 Sint16 xrel; /**< The relative motion in the X direction */ 376 Sint16 yrel; /**< The relative motion in the Y direction */ 377 } SDL_JoyBallEvent; 378 379 /** 380 * Joystick hat position change event structure (event.jhat.*) 381 */ 382 typedef struct SDL_JoyHatEvent 383 { 384 Uint32 type; /**< SDL_JOYHATMOTION */ 385 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 386 SDL_JoystickID which; /**< The joystick instance id */ 387 Uint8 hat; /**< The joystick hat index */ 388 Uint8 value; /**< The hat position value. 389 * \sa SDL_HAT_LEFTUP SDL_HAT_UP SDL_HAT_RIGHTUP 390 * \sa SDL_HAT_LEFT SDL_HAT_CENTERED SDL_HAT_RIGHT 391 * \sa SDL_HAT_LEFTDOWN SDL_HAT_DOWN SDL_HAT_RIGHTDOWN 392 * 393 * Note that zero means the POV is centered. 394 */ 395 Uint8 padding1; 396 Uint8 padding2; 397 } SDL_JoyHatEvent; 398 399 /** 400 * Joystick button event structure (event.jbutton.*) 401 */ 402 typedef struct SDL_JoyButtonEvent 403 { 404 Uint32 type; /**< SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */ 405 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 406 SDL_JoystickID which; /**< The joystick instance id */ 407 Uint8 button; /**< The joystick button index */ 408 Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ 409 Uint8 padding1; 410 Uint8 padding2; 411 } SDL_JoyButtonEvent; 412 413 /** 414 * Joystick device event structure (event.jdevice.*) 415 * 416 * SDL will send JOYSTICK_ADDED events for devices that are already plugged in 417 * during SDL_Init. 418 * 419 * \sa SDL_ControllerDeviceEvent 420 */ 421 typedef struct SDL_JoyDeviceEvent 422 { 423 Uint32 type; /**< SDL_JOYDEVICEADDED or SDL_JOYDEVICEREMOVED */ 424 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 425 Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */ 426 } SDL_JoyDeviceEvent; 427 428 /** 429 * Joysick battery level change event structure (event.jbattery.*) 430 */ 431 typedef struct SDL_JoyBatteryEvent 432 { 433 Uint32 type; /**< SDL_JOYBATTERYUPDATED */ 434 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 435 SDL_JoystickID which; /**< The joystick instance id */ 436 SDL_JoystickPowerLevel level; /**< The joystick battery level */ 437 } SDL_JoyBatteryEvent; 438 439 /** 440 * Game controller axis motion event structure (event.caxis.*) 441 */ 442 typedef struct SDL_ControllerAxisEvent 443 { 444 Uint32 type; /**< SDL_CONTROLLERAXISMOTION */ 445 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 446 SDL_JoystickID which; /**< The joystick instance id */ 447 Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */ 448 Uint8 padding1; 449 Uint8 padding2; 450 Uint8 padding3; 451 Sint16 value; /**< The axis value (range: -32768 to 32767) */ 452 Uint16 padding4; 453 } SDL_ControllerAxisEvent; 454 455 456 /** 457 * Game controller button event structure (event.cbutton.*) 458 */ 459 typedef struct SDL_ControllerButtonEvent 460 { 461 Uint32 type; /**< SDL_CONTROLLERBUTTONDOWN or SDL_CONTROLLERBUTTONUP */ 462 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 463 SDL_JoystickID which; /**< The joystick instance id */ 464 Uint8 button; /**< The controller button (SDL_GameControllerButton) */ 465 Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ 466 Uint8 padding1; 467 Uint8 padding2; 468 } SDL_ControllerButtonEvent; 469 470 471 /** 472 * Controller device event structure (event.cdevice.*) 473 * 474 * Joysticks that are supported game controllers receive both an 475 * SDL_JoyDeviceEvent and an SDL_ControllerDeviceEvent. 476 * 477 * SDL will send CONTROLLERDEVICEADDED events for joysticks that are already 478 * plugged in during SDL_Init() and are recognized as game controllers. 479 */ 480 typedef struct SDL_ControllerDeviceEvent 481 { 482 Uint32 type; /**< SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED, or SDL_CONTROLLERSTEAMHANDLEUPDATED */ 483 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 484 Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */ 485 } SDL_ControllerDeviceEvent; 486 487 /** 488 * Game controller touchpad event structure (event.ctouchpad.*) 489 */ 490 typedef struct SDL_ControllerTouchpadEvent 491 { 492 Uint32 type; /**< SDL_CONTROLLERTOUCHPADDOWN or SDL_CONTROLLERTOUCHPADMOTION or SDL_CONTROLLERTOUCHPADUP */ 493 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 494 SDL_JoystickID which; /**< The joystick instance id */ 495 Sint32 touchpad; /**< The index of the touchpad */ 496 Sint32 finger; /**< The index of the finger on the touchpad */ 497 float x; /**< Normalized in the range 0...1 with 0 being on the left */ 498 float y; /**< Normalized in the range 0...1 with 0 being at the top */ 499 float pressure; /**< Normalized in the range 0...1 */ 500 } SDL_ControllerTouchpadEvent; 501 502 /** 503 * Game controller sensor event structure (event.csensor.*) 504 */ 505 typedef struct SDL_ControllerSensorEvent 506 { 507 Uint32 type; /**< SDL_CONTROLLERSENSORUPDATE */ 508 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 509 SDL_JoystickID which; /**< The joystick instance id */ 510 Sint32 sensor; /**< The type of the sensor, one of the values of SDL_SensorType */ 511 float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */ 512 Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */ 513 } SDL_ControllerSensorEvent; 514 515 /** 516 * Audio device event structure (event.adevice.*) 517 */ 518 typedef struct SDL_AudioDeviceEvent 519 { 520 Uint32 type; /**< SDL_AUDIODEVICEADDED, or SDL_AUDIODEVICEREMOVED */ 521 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 522 Uint32 which; /**< The audio device index for the ADDED event (valid until next SDL_GetNumAudioDevices() call), SDL_AudioDeviceID for the REMOVED event */ 523 Uint8 iscapture; /**< zero if an output device, non-zero if a capture device. */ 524 Uint8 padding1; 525 Uint8 padding2; 526 Uint8 padding3; 527 } SDL_AudioDeviceEvent; 528 529 530 /** 531 * Touch finger event structure (event.tfinger.*) 532 */ 533 typedef struct SDL_TouchFingerEvent 534 { 535 Uint32 type; /**< SDL_FINGERMOTION or SDL_FINGERDOWN or SDL_FINGERUP */ 536 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 537 SDL_TouchID touchId; /**< The touch device id */ 538 SDL_FingerID fingerId; 539 float x; /**< Normalized in the range 0...1 */ 540 float y; /**< Normalized in the range 0...1 */ 541 float dx; /**< Normalized in the range -1...1 */ 542 float dy; /**< Normalized in the range -1...1 */ 543 float pressure; /**< Normalized in the range 0...1 */ 544 Uint32 windowID; /**< The window underneath the finger, if any */ 545 } SDL_TouchFingerEvent; 546 547 548 /** 549 * Multiple Finger Gesture Event (event.mgesture.*) 550 */ 551 typedef struct SDL_MultiGestureEvent 552 { 553 Uint32 type; /**< SDL_MULTIGESTURE */ 554 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 555 SDL_TouchID touchId; /**< The touch device id */ 556 float dTheta; 557 float dDist; 558 float x; 559 float y; 560 Uint16 numFingers; 561 Uint16 padding; 562 } SDL_MultiGestureEvent; 563 564 565 /** 566 * Dollar Gesture Event (event.dgesture.*) 567 */ 568 typedef struct SDL_DollarGestureEvent 569 { 570 Uint32 type; /**< SDL_DOLLARGESTURE or SDL_DOLLARRECORD */ 571 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 572 SDL_TouchID touchId; /**< The touch device id */ 573 SDL_GestureID gestureId; 574 Uint32 numFingers; 575 float error; 576 float x; /**< Normalized center of gesture */ 577 float y; /**< Normalized center of gesture */ 578 } SDL_DollarGestureEvent; 579 580 581 /** 582 * An event used to request a file open by the system (event.drop.*) 583 * 584 * This event is enabled by default, you can disable it with SDL_EventState(). 585 * 586 * If this event is enabled, you must free the filename in the event. 587 */ 588 typedef struct SDL_DropEvent 589 { 590 Uint32 type; /**< SDL_DROPBEGIN or SDL_DROPFILE or SDL_DROPTEXT or SDL_DROPCOMPLETE */ 591 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 592 char *file; /**< The file name, which should be freed with SDL_free(), is NULL on begin/complete */ 593 Uint32 windowID; /**< The window that was dropped on, if any */ 594 } SDL_DropEvent; 595 596 597 /** 598 * Sensor event structure (event.sensor.*) 599 */ 600 typedef struct SDL_SensorEvent 601 { 602 Uint32 type; /**< SDL_SENSORUPDATE */ 603 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 604 Sint32 which; /**< The instance ID of the sensor */ 605 float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */ 606 Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */ 607 } SDL_SensorEvent; 608 609 /** 610 * The "quit requested" event 611 */ 612 typedef struct SDL_QuitEvent 613 { 614 Uint32 type; /**< SDL_QUIT */ 615 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 616 } SDL_QuitEvent; 617 618 /** 619 * A user-defined event type (event.user.*) 620 */ 621 typedef struct SDL_UserEvent 622 { 623 Uint32 type; /**< SDL_USEREVENT through SDL_LASTEVENT-1 */ 624 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 625 Uint32 windowID; /**< The associated window if any */ 626 Sint32 code; /**< User defined event code */ 627 void *data1; /**< User defined data pointer */ 628 void *data2; /**< User defined data pointer */ 629 } SDL_UserEvent; 630 631 632 struct SDL_SysWMmsg; 633 typedef struct SDL_SysWMmsg SDL_SysWMmsg; 634 635 /** 636 * A video driver dependent system event (event.syswm.*) 637 * 638 * This event is disabled by default, you can enable it with SDL_EventState() 639 * 640 * If you want to use this event, you should include SDL_syswm.h. 641 */ 642 typedef struct SDL_SysWMEvent 643 { 644 Uint32 type; /**< SDL_SYSWMEVENT */ 645 Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ 646 SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */ 647 } SDL_SysWMEvent; 648 649 /** 650 * General event structure 651 * 652 * The SDL_Event structure is the core of all event handling in SDL. SDL_Event 653 * is a union of all event structures used in SDL. 654 */ 655 typedef union SDL_Event 656 { 657 Uint32 type; /**< Event type, shared with all events */ 658 SDL_CommonEvent common; /**< Common event data */ 659 SDL_DisplayEvent display; /**< Display event data */ 660 SDL_WindowEvent window; /**< Window event data */ 661 SDL_KeyboardEvent key; /**< Keyboard event data */ 662 SDL_TextEditingEvent edit; /**< Text editing event data */ 663 SDL_TextEditingExtEvent editExt; /**< Extended text editing event data */ 664 SDL_TextInputEvent text; /**< Text input event data */ 665 SDL_MouseMotionEvent motion; /**< Mouse motion event data */ 666 SDL_MouseButtonEvent button; /**< Mouse button event data */ 667 SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */ 668 SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */ 669 SDL_JoyBallEvent jball; /**< Joystick ball event data */ 670 SDL_JoyHatEvent jhat; /**< Joystick hat event data */ 671 SDL_JoyButtonEvent jbutton; /**< Joystick button event data */ 672 SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */ 673 SDL_JoyBatteryEvent jbattery; /**< Joystick battery event data */ 674 SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */ 675 SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */ 676 SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */ 677 SDL_ControllerTouchpadEvent ctouchpad; /**< Game Controller touchpad event data */ 678 SDL_ControllerSensorEvent csensor; /**< Game Controller sensor event data */ 679 SDL_AudioDeviceEvent adevice; /**< Audio device event data */ 680 SDL_SensorEvent sensor; /**< Sensor event data */ 681 SDL_QuitEvent quit; /**< Quit request event data */ 682 SDL_UserEvent user; /**< Custom event data */ 683 SDL_SysWMEvent syswm; /**< System dependent window event data */ 684 SDL_TouchFingerEvent tfinger; /**< Touch finger event data */ 685 SDL_MultiGestureEvent mgesture; /**< Gesture event data */ 686 SDL_DollarGestureEvent dgesture; /**< Gesture event data */ 687 SDL_DropEvent drop; /**< Drag and drop event data */ 688 689 /* This is necessary for ABI compatibility between Visual C++ and GCC. 690 Visual C++ will respect the push pack pragma and use 52 bytes (size of 691 SDL_TextEditingEvent, the largest structure for 32-bit and 64-bit 692 architectures) for this union, and GCC will use the alignment of the 693 largest datatype within the union, which is 8 bytes on 64-bit 694 architectures. 695 696 So... we'll add padding to force the size to be 56 bytes for both. 697 698 On architectures where pointers are 16 bytes, this needs rounding up to 699 the next multiple of 16, 64, and on architectures where pointers are 700 even larger the size of SDL_UserEvent will dominate as being 3 pointers. 701 */ 702 Uint8 padding[sizeof(void *) <= 8 ? 56 : sizeof(void *) == 16 ? 64 : 3 * sizeof(void *)]; 703 } SDL_Event; 704 705 /* Make sure we haven't broken binary compatibility */ 706 SDL_COMPILE_TIME_ASSERT(SDL_Event, sizeof(SDL_Event) == sizeof(((SDL_Event *)NULL)->padding)); 707 708 709 /* Function prototypes */ 710 711 /** 712 * Pump the event loop, gathering events from the input devices. 713 * 714 * This function updates the event queue and internal input device state. 715 * 716 * **WARNING**: This should only be run in the thread that initialized the 717 * video subsystem, and for extra safety, you should consider only doing those 718 * things on the main thread in any case. 719 * 720 * SDL_PumpEvents() gathers all the pending input information from devices and 721 * places it in the event queue. Without calls to SDL_PumpEvents() no events 722 * would ever be placed on the queue. Often the need for calls to 723 * SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and 724 * SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not 725 * polling or waiting for events (e.g. you are filtering them), then you must 726 * call SDL_PumpEvents() to force an event queue update. 727 * 728 * \since This function is available since SDL 2.0.0. 729 * 730 * \sa SDL_PollEvent 731 * \sa SDL_WaitEvent 732 */ 733 extern DECLSPEC void SDLCALL SDL_PumpEvents(void); 734 735 /* @{ */ 736 typedef enum SDL_eventaction 737 { 738 SDL_ADDEVENT, 739 SDL_PEEKEVENT, 740 SDL_GETEVENT 741 } SDL_eventaction; 742 743 /** 744 * Check the event queue for messages and optionally return them. 745 * 746 * `action` may be any of the following: 747 * 748 * - `SDL_ADDEVENT`: up to `numevents` events will be added to the back of the 749 * event queue. 750 * - `SDL_PEEKEVENT`: `numevents` events at the front of the event queue, 751 * within the specified minimum and maximum type, will be returned to the 752 * caller and will _not_ be removed from the queue. 753 * - `SDL_GETEVENT`: up to `numevents` events at the front of the event queue, 754 * within the specified minimum and maximum type, will be returned to the 755 * caller and will be removed from the queue. 756 * 757 * You may have to call SDL_PumpEvents() before calling this function. 758 * Otherwise, the events may not be ready to be filtered when you call 759 * SDL_PeepEvents(). 760 * 761 * This function is thread-safe. 762 * 763 * \param events destination buffer for the retrieved events. 764 * \param numevents if action is SDL_ADDEVENT, the number of events to add 765 * back to the event queue; if action is SDL_PEEKEVENT or 766 * SDL_GETEVENT, the maximum number of events to retrieve. 767 * \param action action to take; see [[#action|Remarks]] for details. 768 * \param minType minimum value of the event type to be considered; 769 * SDL_FIRSTEVENT is a safe choice. 770 * \param maxType maximum value of the event type to be considered; 771 * SDL_LASTEVENT is a safe choice. 772 * \returns the number of events actually stored or a negative error code on 773 * failure; call SDL_GetError() for more information. 774 * 775 * \since This function is available since SDL 2.0.0. 776 * 777 * \sa SDL_PollEvent 778 * \sa SDL_PumpEvents 779 * \sa SDL_PushEvent 780 */ 781 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents, 782 SDL_eventaction action, 783 Uint32 minType, Uint32 maxType); 784 /* @} */ 785 786 /** 787 * Check for the existence of a certain event type in the event queue. 788 * 789 * If you need to check for a range of event types, use SDL_HasEvents() 790 * instead. 791 * 792 * \param type the type of event to be queried; see SDL_EventType for details. 793 * \returns SDL_TRUE if events matching `type` are present, or SDL_FALSE if 794 * events matching `type` are not present. 795 * 796 * \since This function is available since SDL 2.0.0. 797 * 798 * \sa SDL_HasEvents 799 */ 800 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type); 801 802 803 /** 804 * Check for the existence of certain event types in the event queue. 805 * 806 * If you need to check for a single event type, use SDL_HasEvent() instead. 807 * 808 * \param minType the low end of event type to be queried, inclusive; see 809 * SDL_EventType for details. 810 * \param maxType the high end of event type to be queried, inclusive; see 811 * SDL_EventType for details. 812 * \returns SDL_TRUE if events with type >= `minType` and <= `maxType` are 813 * present, or SDL_FALSE if not. 814 * 815 * \since This function is available since SDL 2.0.0. 816 * 817 * \sa SDL_HasEvents 818 */ 819 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType); 820 821 /** 822 * Clear events of a specific type from the event queue. 823 * 824 * This will unconditionally remove any events from the queue that match 825 * `type`. If you need to remove a range of event types, use SDL_FlushEvents() 826 * instead. 827 * 828 * It's also normal to just ignore events you don't care about in your event 829 * loop without calling this function. 830 * 831 * This function only affects currently queued events. If you want to make 832 * sure that all pending OS events are flushed, you can call SDL_PumpEvents() 833 * on the main thread immediately before the flush call. 834 * 835 * \param type the type of event to be cleared; see SDL_EventType for details. 836 * 837 * \since This function is available since SDL 2.0.0. 838 * 839 * \sa SDL_FlushEvents 840 */ 841 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type); 842 843 /** 844 * Clear events of a range of types from the event queue. 845 * 846 * This will unconditionally remove any events from the queue that are in the 847 * range of `minType` to `maxType`, inclusive. If you need to remove a single 848 * event type, use SDL_FlushEvent() instead. 849 * 850 * It's also normal to just ignore events you don't care about in your event 851 * loop without calling this function. 852 * 853 * This function only affects currently queued events. If you want to make 854 * sure that all pending OS events are flushed, you can call SDL_PumpEvents() 855 * on the main thread immediately before the flush call. 856 * 857 * \param minType the low end of event type to be cleared, inclusive; see 858 * SDL_EventType for details. 859 * \param maxType the high end of event type to be cleared, inclusive; see 860 * SDL_EventType for details. 861 * 862 * \since This function is available since SDL 2.0.0. 863 * 864 * \sa SDL_FlushEvent 865 */ 866 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType); 867 868 /** 869 * Poll for currently pending events. 870 * 871 * If `event` is not NULL, the next event is removed from the queue and stored 872 * in the SDL_Event structure pointed to by `event`. The 1 returned refers to 873 * this event, immediately stored in the SDL Event structure -- not an event 874 * to follow. 875 * 876 * If `event` is NULL, it simply returns 1 if there is an event in the queue, 877 * but will not remove it from the queue. 878 * 879 * As this function may implicitly call SDL_PumpEvents(), you can only call 880 * this function in the thread that set the video mode. 881 * 882 * SDL_PollEvent() is the favored way of receiving system events since it can 883 * be done from the main loop and does not suspend the main loop while waiting 884 * on an event to be posted. 885 * 886 * The common practice is to fully process the event queue once every frame, 887 * usually as a first step before updating the game's state: 888 * 889 * ```c 890 * while (game_is_still_running) 891 { 892 * SDL_Event event; 893 * while (SDL_PollEvent(&event)) 894 { // poll until all events are handled! 895 * // decide what to do with this event. 896 * } 897 * 898 * // update game state, draw the current frame 899 * } 900 * ``` 901 * 902 * \param event the SDL_Event structure to be filled with the next event from 903 * the queue, or NULL. 904 * \returns 1 if there is a pending event or 0 if there are none available. 905 * 906 * \since This function is available since SDL 2.0.0. 907 * 908 * \sa SDL_GetEventFilter 909 * \sa SDL_PeepEvents 910 * \sa SDL_PushEvent 911 * \sa SDL_SetEventFilter 912 * \sa SDL_WaitEvent 913 * \sa SDL_WaitEventTimeout 914 */ 915 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event); 916 917 /** 918 * Wait indefinitely for the next available event. 919 * 920 * If `event` is not NULL, the next event is removed from the queue and stored 921 * in the SDL_Event structure pointed to by `event`. 922 * 923 * As this function may implicitly call SDL_PumpEvents(), you can only call 924 * this function in the thread that initialized the video subsystem. 925 * 926 * \param event the SDL_Event structure to be filled in with the next event 927 * from the queue, or NULL. 928 * \returns 1 on success or 0 if there was an error while waiting for events; 929 * call SDL_GetError() for more information. 930 * 931 * \since This function is available since SDL 2.0.0. 932 * 933 * \sa SDL_PollEvent 934 * \sa SDL_PumpEvents 935 * \sa SDL_WaitEventTimeout 936 */ 937 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event); 938 939 /** 940 * Wait until the specified timeout (in milliseconds) for the next available 941 * event. 942 * 943 * If `event` is not NULL, the next event is removed from the queue and stored 944 * in the SDL_Event structure pointed to by `event`. 945 * 946 * As this function may implicitly call SDL_PumpEvents(), you can only call 947 * this function in the thread that initialized the video subsystem. 948 * 949 * \param event the SDL_Event structure to be filled in with the next event 950 * from the queue, or NULL. 951 * \param timeout the maximum number of milliseconds to wait for the next 952 * available event. 953 * \returns 1 on success or 0 if there was an error while waiting for events; 954 * call SDL_GetError() for more information. This also returns 0 if 955 * the timeout elapsed without an event arriving. 956 * 957 * \since This function is available since SDL 2.0.0. 958 * 959 * \sa SDL_PollEvent 960 * \sa SDL_PumpEvents 961 * \sa SDL_WaitEvent 962 */ 963 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event, 964 int timeout); 965 966 /** 967 * Add an event to the event queue. 968 * 969 * The event queue can actually be used as a two way communication channel. 970 * Not only can events be read from the queue, but the user can also push 971 * their own events onto it. `event` is a pointer to the event structure you 972 * wish to push onto the queue. The event is copied into the queue, and the 973 * caller may dispose of the memory pointed to after SDL_PushEvent() returns. 974 * 975 * Note: Pushing device input events onto the queue doesn't modify the state 976 * of the device within SDL. 977 * 978 * This function is thread-safe, and can be called from other threads safely. 979 * 980 * Note: Events pushed onto the queue with SDL_PushEvent() get passed through 981 * the event filter but events added with SDL_PeepEvents() do not. 982 * 983 * For pushing application-specific events, please use SDL_RegisterEvents() to 984 * get an event type that does not conflict with other code that also wants 985 * its own custom event types. 986 * 987 * \param event the SDL_Event to be added to the queue. 988 * \returns 1 on success, 0 if the event was filtered, or a negative error 989 * code on failure; call SDL_GetError() for more information. A 990 * common reason for error is the event queue being full. 991 * 992 * \since This function is available since SDL 2.0.0. 993 * 994 * \sa SDL_PeepEvents 995 * \sa SDL_PollEvent 996 * \sa SDL_RegisterEvents 997 */ 998 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event); 999 1000 /** 1001 * A function pointer used for callbacks that watch the event queue. 1002 * 1003 * \param userdata what was passed as `userdata` to SDL_SetEventFilter() or 1004 * SDL_AddEventWatch, etc. 1005 * \param event the event that triggered the callback. 1006 * \returns 1 to permit event to be added to the queue, and 0 to disallow it. 1007 * When used with SDL_AddEventWatch, the return value is ignored. 1008 * 1009 * \sa SDL_SetEventFilter 1010 * \sa SDL_AddEventWatch 1011 */ 1012 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event); 1013 1014 /** 1015 * Set up a filter to process all events before they change internal state and 1016 * are posted to the internal event queue. 1017 * 1018 * If the filter function returns 1 when called, then the event will be added 1019 * to the internal queue. If it returns 0, then the event will be dropped from 1020 * the queue, but the internal state will still be updated. This allows 1021 * selective filtering of dynamically arriving events. 1022 * 1023 * **WARNING**: Be very careful of what you do in the event filter function, 1024 * as it may run in a different thread! 1025 * 1026 * On platforms that support it, if the quit event is generated by an 1027 * interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the 1028 * application at the next event poll. 1029 * 1030 * There is one caveat when dealing with the SDL_QuitEvent event type. The 1031 * event filter is only called when the window manager desires to close the 1032 * application window. If the event filter returns 1, then the window will be 1033 * closed, otherwise the window will remain open if possible. 1034 * 1035 * Note: Disabled events never make it to the event filter function; see 1036 * SDL_EventState(). 1037 * 1038 * Note: If you just want to inspect events without filtering, you should use 1039 * SDL_AddEventWatch() instead. 1040 * 1041 * Note: Events pushed onto the queue with SDL_PushEvent() get passed through 1042 * the event filter, but events pushed onto the queue with SDL_PeepEvents() do 1043 * not. 1044 * 1045 * \param filter An SDL_EventFilter function to call when an event happens. 1046 * \param userdata a pointer that is passed to `filter`. 1047 * 1048 * \since This function is available since SDL 2.0.0. 1049 * 1050 * \sa SDL_AddEventWatch 1051 * \sa SDL_EventState 1052 * \sa SDL_GetEventFilter 1053 * \sa SDL_PeepEvents 1054 * \sa SDL_PushEvent 1055 */ 1056 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter, 1057 void *userdata); 1058 1059 /** 1060 * Query the current event filter. 1061 * 1062 * This function can be used to "chain" filters, by saving the existing filter 1063 * before replacing it with a function that will call that saved filter. 1064 * 1065 * \param filter the current callback function will be stored here. 1066 * \param userdata the pointer that is passed to the current event filter will 1067 * be stored here. 1068 * \returns SDL_TRUE on success or SDL_FALSE if there is no event filter set. 1069 * 1070 * \since This function is available since SDL 2.0.0. 1071 * 1072 * \sa SDL_SetEventFilter 1073 */ 1074 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter, 1075 void **userdata); 1076 1077 /** 1078 * Add a callback to be triggered when an event is added to the event queue. 1079 * 1080 * `filter` will be called when an event happens, and its return value is 1081 * ignored. 1082 * 1083 * **WARNING**: Be very careful of what you do in the event filter function, 1084 * as it may run in a different thread! 1085 * 1086 * If the quit event is generated by a signal (e.g. SIGINT), it will bypass 1087 * the internal queue and be delivered to the watch callback immediately, and 1088 * arrive at the next event poll. 1089 * 1090 * Note: the callback is called for events posted by the user through 1091 * SDL_PushEvent(), but not for disabled events, nor for events by a filter 1092 * callback set with SDL_SetEventFilter(), nor for events posted by the user 1093 * through SDL_PeepEvents(). 1094 * 1095 * \param filter an SDL_EventFilter function to call when an event happens. 1096 * \param userdata a pointer that is passed to `filter`. 1097 * 1098 * \since This function is available since SDL 2.0.0. 1099 * 1100 * \sa SDL_DelEventWatch 1101 * \sa SDL_SetEventFilter 1102 */ 1103 extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter, 1104 void *userdata); 1105 1106 /** 1107 * Remove an event watch callback added with SDL_AddEventWatch(). 1108 * 1109 * This function takes the same input as SDL_AddEventWatch() to identify and 1110 * delete the corresponding callback. 1111 * 1112 * \param filter the function originally passed to SDL_AddEventWatch(). 1113 * \param userdata the pointer originally passed to SDL_AddEventWatch(). 1114 * 1115 * \since This function is available since SDL 2.0.0. 1116 * 1117 * \sa SDL_AddEventWatch 1118 */ 1119 extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter, 1120 void *userdata); 1121 1122 /** 1123 * Run a specific filter function on the current event queue, removing any 1124 * events for which the filter returns 0. 1125 * 1126 * See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(), 1127 * this function does not change the filter permanently, it only uses the 1128 * supplied filter until this function returns. 1129 * 1130 * \param filter the SDL_EventFilter function to call when an event happens. 1131 * \param userdata a pointer that is passed to `filter`. 1132 * 1133 * \since This function is available since SDL 2.0.0. 1134 * 1135 * \sa SDL_GetEventFilter 1136 * \sa SDL_SetEventFilter 1137 */ 1138 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter, 1139 void *userdata); 1140 1141 /* @{ */ 1142 #define SDL_QUERY -1 1143 #define SDL_IGNORE 0 1144 #define SDL_DISABLE 0 1145 #define SDL_ENABLE 1 1146 1147 /** 1148 * Set the state of processing events by type. 1149 * 1150 * `state` may be any of the following: 1151 * 1152 * - `SDL_QUERY`: returns the current processing state of the specified event 1153 * - `SDL_IGNORE` (aka `SDL_DISABLE`): the event will automatically be dropped 1154 * from the event queue and will not be filtered 1155 * - `SDL_ENABLE`: the event will be processed normally 1156 * 1157 * \param type the type of event; see SDL_EventType for details. 1158 * \param state how to process the event. 1159 * \returns `SDL_DISABLE` or `SDL_ENABLE`, representing the processing state 1160 * of the event before this function makes any changes to it. 1161 * 1162 * \since This function is available since SDL 2.0.0. 1163 * 1164 * \sa SDL_GetEventState 1165 */ 1166 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state); 1167 /* @} */ 1168 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY) 1169 1170 /** 1171 * Allocate a set of user-defined events, and return the beginning event 1172 * number for that set of events. 1173 * 1174 * Calling this function with `numevents` <= 0 is an error and will return 1175 * (Uint32)-1. 1176 * 1177 * Note, (Uint32)-1 means the maximum unsigned 32-bit integer value (or 1178 * 0xFFFFFFFF), but is clearer to write. 1179 * 1180 * \param numevents the number of events to be allocated. 1181 * \returns the beginning event number, or (Uint32)-1 if there are not enough 1182 * user-defined events left. 1183 * 1184 * \since This function is available since SDL 2.0.0. 1185 * 1186 * \sa SDL_PushEvent 1187 */ 1188 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents); 1189 1190 /* Ends C function definitions when using C++ */ 1191 #ifdef __cplusplus 1192 } 1193 #endif 1194 #include "close_code.h" 1195 1196 #endif /* SDL_events_h_ */ 1197 1198 /* vi: set ts=4 sw=4 expandtab: */