SDL_CLIPBOARDDATACALLBACK(3type)

πŸ’– SDL_ClipboardDataCallback(3type) πŸ’–

okay bestie, welcome to the SDL3 DATATYPES corner of the manual, where we meet a lil function-pointer diva called SDL_ClipboardDataCallback. she's the callback the OS hits up when somebody wants data for a specific mime-type. she serves. πŸ’…


✨ NAME ✨

SDL_ClipboardDataCallback β€” the callback function that gets called when the OS asks for the data of a specific mime-type. it's giving "on-demand snack delivery." πŸ“


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_clipboard.h>

typedef const void *(SDLCALL *SDL_ClipboardDataCallback)(void *userdata, const char *mime_type, size_t *size);

look at that signature. gorgeous. no notes. 🌸


πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea, bestie: this callback gets called with NULL as the mime_type when the clipboard is cleared or when new data is set. yes, NULL β€” that's the "hey nothing to see here, we're resetting" signal, don't panic.

also, plot twist: the clipboard gets cleared automatically in SDL_Quit(). she cleans up after herself. main character behavior, fr fr. ✨


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • userdata β€” a pointer to the provided user data. your lil bag of stuff you handed over earlier. 🫢
  • mime_type β€” the requested mime-type. the vibe being asked for.
  • size β€” a pointer that you fill in with the length of the returned data. don't forget her, she matters. πŸ’œ

🌈 RETURN VALUE 🌈

you return a pointer to the data for the provided mime-type. simple. iconic.

but here's the important part, no cap: if you return NULL, or if you set the length to 0, that causes zero length data to be sent to the "receiver" β€” and that receiver should be able to handle this. so like, don't be weird about it, it's a valid thing to do. πŸ’€

and listen closely: the returned data will not be freed. like, at all. so it needs to be retained and dealt with internally. that's your problem now, bestie. keep it alive, manage it yourself, she's not doing it for you. πŸ™ˆ


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if you're on something older, that's a vibe check failure, sorry. 😭


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, bestie!! written up by the lovely folks at Simple Directmedia Layer, straight from SDL 3.4.18 β€” mwah, sending you kisses, go slay some clipboard code πŸ§šπŸ’–πŸŽ€

πŸ“¦ where this page comes from