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