SDL_JoyDeviceEvent(3type)

πŸ’– SDL_JoyDeviceEvent β€” like, the joystick device event struct πŸ’–

okay so bestie, welcome to the SDL3 DATATYPES corner of the manual, page SDL_JoyDeviceEvent(3type). this one is short and sweet and it's giving "tiny struct, big feelings". let's get into it 🫢


✨ NAME ✨

SDL_JoyDeviceEvent β€” the joystick device event structure, aka the whole event.jdevice.* situation πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_events.h>

typedef struct SDL_JoyDeviceEvent
{
    SDL_EventType type; /**< SDL_EVENT_JOYSTICK_ADDED or SDL_EVENT_JOYSTICK_REMOVED or SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_JoystickID which;       /**< The joystick instance id */
} SDL_JoyDeviceEvent;

no cap, that's the whole thing. four fields, zero drama 🌸


🌈 DESCRIPTION 🌈

okay so the vibe here: SDL will send JOYSTICK_ADDED events for devices that are already plugged in during SDL_Init. literally β€” if your controller was already chilling in the USB port before you even called SDL_Init, SDL is NOT gonna pretend it doesn't exist. it sends the event. iconic behaviour tbh πŸ”₯

so if you're sitting there like "why am I getting an added event for something that was already added", that's why. it's intentional. it's the main character move. periodt ✨


πŸ’œ AVAILABILITY πŸ’œ

this struct has been around since SDL 3.2.0. so if you're on anything older, sorry bestie, she's not there 😭


πŸ¦‹ SEE ALSO πŸ¦‹


heads up bestie: the timestamp is in nanoseconds and gets populated using SDL_GetTicksNS(), and which is the joystick instance id β€” don't skip those, they're the whole point πŸ’…

okay that's the page!! this was brought to you by the fine people at Simple Directmedia Layer, and it's from SDL 3.4.18. mwah, go forth and handle your events πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from