SDL_UserEvent(3type)

πŸ’– SDL_UserEvent β€” a datatype from the SDL3 crew πŸ’–

okay bestie, pull up a chair, because today we're talking about SDL_UserEvent β€” the little struct that's literally yours to fill, aka the event.user.* of your dreams. πŸŽ€


✨ NAME ✨

SDL_UserEvent β€” a user-defined event type, the one and only event.user.* 🫢


✨ SYNOPSIS ✨

#include <SDL3/SDL_events.h>

typedef struct SDL_UserEvent
{
    Uint32 type;        /**< SDL_EVENT_USER through SDL_EVENT_LAST, Uint32 because these are not in the SDL_EventType enumeration */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_WindowID windowID; /**< The associated window if any */
    Sint32 code;        /**< User defined event code */
    void *data1;        /**< User defined data pointer */
    void *data2;        /**< User defined data pointer */
} SDL_UserEvent;

she's structured, she's typed, she's got void *s so you can put whatever you want in there. main character energy fr. πŸ‘‘


✨ DESCRIPTION ✨

okay so here's the tea: this event is unique. SDL never makes it. not once. it's never created by SDL β€” only by you, the application. it's giving bespoke. it's giving handmade. ✨

you push it onto the event queue with SDL_PushEvent(), and then it's out there living its best life.

and the contents of the struct members? completely up to the programmer. go wild. put a pointer to your cat's medical records in there, idk, it's your world. 🌈

the only requirement β€” and bestie I need you to hear me on this one β€” is that type has to be a value you got from SDL_RegisterEvents(). that's it. that's the vibe check. don't skip it. πŸ’…

✨ AVAILABILITY ✨

this struct has been around since SDL 3.2.0. she's not new new, but she's not ancient either. iconic behavior. πŸ¦‹


and that's the whole page, bestie!! πŸ’– written by the Simple Directmedia Layer girlies, straight outta SDL 3.4.18, and yeah β€” it's still called SDL_UserEvent(3type) if you wanna look her up again. periodt. πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from