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 themime_typeslist. 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms