SDL_SetClipboardData(3)

πŸ’– SDL_SetClipboardData(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_SetClipboardData β€” the one that lets your app offer clipboard data to the OS. yes. clipboard. the thing you abuse daily. let's go 🫢


✨ NAME ✨

SDL_SetClipboardData β€” offer clipboard data to the OS. that's it. that's the whole job. πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_clipboard.h>

bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char *const *mime_types, size_t num_mime_types);

look at her. five params. absolutely iconic. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, you're telling the operating system: hey, my application is offering clipboard data for each of these mime-types you see here. that's the vibe. you're not shoving bytes at anyone right now, you're just putting it out there, offering, manifesting 🧚

then once another application requests the data, your callback function gets called β€” and that's when you actually generate the data and respond with it for whatever mime-type was requested. so it's like, lazy but make it elegant. you produce on demand. very demure, very mindful πŸ’…

✨ important detail bestie: the size of text data does not include any terminator, and the text does not need to be null-terminated. so yeah, you can literally just copy a portion of a document straight in. no null byte required, no cap. 😭

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • callback β€” a function pointer to the function that provides the clipboard data. your little data-delivery bestie πŸ“¦
  • cleanup β€” a function pointer to the function that cleans up the clipboard data. somebody has to do the tidying πŸ’–
  • userdata β€” an opaque pointer that will be forwarded to the callbacks. it's giving "you don't need to know what's inside, just pass it along" πŸ™ˆ
  • mime_types β€” a list of mime-types that are being offered. SDL copies the given list, so don't stress about it, she keeps her own copy πŸŽ€
  • num_mime_types β€” the number of mime-types in the mime_types list. count them. yes, all of them πŸ”’

⭐ RETURN VALUE ⭐

returns true on success or false on failure. and if it fails? call SDL_GetError() for more information, because she will tell you exactly what went wrong. always check, bestie. always. πŸ’€


🌈 THREAD SAFETY 🌈

🚨 this function should only be called on the main thread. do not try it anywhere else. i'm so serious. main thread only. periodt. πŸ‘‘

πŸ‘‘ AVAILABILITY πŸ‘‘

this function is available since SDL 3.2.0. so if you're on something older, she's not there yet, sorry babe 😭


πŸ’œ SEE ALSO πŸ’œ

go read those next, they're all part of the clipboard friend group 🫢


and that's the whole page, bestie!! this iconic little number comes to you from the legends at Simple Directmedia Layer, living in SDL 3.4.18. mwah, go slay your clipboard πŸ’…βœ¨πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from