SDL 3.0
SDL_clipboard.h File Reference

Include file for SDL clipboard handling. More...

+ Include dependency graph for SDL_clipboard.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

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

Functions

int SDL_SetClipboardText (const char *text)
 
char * SDL_GetClipboardText (void)
 
SDL_bool SDL_HasClipboardText (void)
 
int SDL_SetPrimarySelectionText (const char *text)
 
char * SDL_GetPrimarySelectionText (void)
 
SDL_bool SDL_HasPrimarySelectionText (void)
 
int SDL_SetClipboardData (SDL_ClipboardDataCallback callback, size_t mime_count, const char **mime_types, void *userdata)
 
void * SDL_GetClipboardUserdata (void)
 
void * SDL_GetClipboardData (size_t *length, const char *mime_type)
 
SDL_bool SDL_HasClipboardData (const char *mime_type)
 

Detailed Description

Include file for SDL clipboard handling.

Definition in file SDL_clipboard.h.

Typedef Documentation

◆ SDL_ClipboardDataCallback

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

Callback function that will be called when data for the specified mime-type is requested by the OS.

Parameters
sizeThe length of the returned data
mime_typeThe requested mime-type
userdataA pointer to provided user data
Returns
a pointer to the data for the provided mime-type. Returning NULL or setting length to 0 will cause no data to be sent to the "receiver". It is up to the receiver to handle this. Essentially returning no data is more or less undefined behavior and may cause breakage in receiving applications. The returned data will not be freed so it needs to be retained and dealt with internally.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetClipboardData

Definition at line 150 of file SDL_clipboard.h.

Function Documentation

◆ SDL_GetClipboardData()

void * SDL_GetClipboardData ( size_t *  length,
const char *  mime_type 
)

Get the data from clipboard for a given mime type

Parameters
mime_typeThe mime type to read from the clipboard
Returns
the retrieved data buffer or NULL on failure; call SDL_GetError() for more information. Caller must call SDL_free() on the returned pointer when done with it.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetClipboardData

◆ SDL_GetClipboardText()

char * SDL_GetClipboardText ( void  )

Get UTF-8 text from the clipboard, which must be freed with SDL_free().

This functions returns empty string if there was not enough memory left for a copy of the clipboard's content.

Returns
the clipboard text on success or an empty string on failure; call SDL_GetError() for more information. Caller must call SDL_free() on the returned pointer when done with it (even if there was an error).
Since
This function is available since SDL 3.0.0.
See also
SDL_HasClipboardText
SDL_SetClipboardText

◆ SDL_GetClipboardUserdata()

void * SDL_GetClipboardUserdata ( void  )

Retrieve previously set userdata if any.

Returns
a pointer to the data or NULL if no data exists
Since
This function is available since SDL 3.0.0.

◆ SDL_GetPrimarySelectionText()

char * SDL_GetPrimarySelectionText ( void  )

Get UTF-8 text from the primary selection, which must be freed with SDL_free().

This functions returns empty string if there was not enough memory left for a copy of the primary selection's content.

Returns
the primary selection text on success or an empty string on failure; call SDL_GetError() for more information. Caller must call SDL_free() on the returned pointer when done with it (even if there was an error).
Since
This function is available since SDL 3.0.0.
See also
SDL_HasPrimarySelectionText
SDL_SetPrimarySelectionText

◆ SDL_HasClipboardData()

SDL_bool SDL_HasClipboardData ( const char *  mime_type)

Query whether there is data in the clipboard for the provided mime type

Parameters
mime_typeThe mime type to check for data for
Returns
SDL_TRUE if there exists data in clipboard for the provided mime type, SDL_FALSE if it does not.
Since
This function is available since SDL 3.0.0.
See also
SDL_SetClipboardData
SDL_GetClipboardData

◆ SDL_HasClipboardText()

SDL_bool SDL_HasClipboardText ( void  )

Query whether the clipboard exists and contains a non-empty text string.

Returns
SDL_TRUE if the clipboard has text, or SDL_FALSE if it does not.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetClipboardText
SDL_SetClipboardText

◆ SDL_HasPrimarySelectionText()

SDL_bool SDL_HasPrimarySelectionText ( void  )

Query whether the primary selection exists and contains a non-empty text string.

Returns
SDL_TRUE if the primary selection has text, or SDL_FALSE if it does not.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetPrimarySelectionText
SDL_SetPrimarySelectionText

◆ SDL_SetClipboardData()

int SDL_SetClipboardData ( SDL_ClipboardDataCallback  callback,
size_t  mime_count,
const char **  mime_types,
void *  userdata 
)

Offer clipboard data to the OS

Tell the operating system that the application is offering clipboard data for each of the proivded mime-types. Once another application requests the data the callback function will be called allowing it to generate and respond with the data for the requested mime-type.

The userdata submitted to this function needs to be freed manually. The following scenarios need to be handled:

  • When the programs clipboard is replaced (cancelled) SDL_EVENT_CLIPBOARD_CANCELLED
  • Before calling SDL_Quit()
Parameters
callbackA function pointer to the function that provides the clipboard data
mime_countThe number of mime-types in the mime_types list
mime_typesA list of mime-types that are being offered
userdataAn opaque pointer that will be forwarded to the callback
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_ClipboardDataCallback
SDL_GetClipboardUserdata
SDL_SetClipboardData
SDL_GetClipboardData
SDL_HasClipboardData

◆ SDL_SetClipboardText()

int SDL_SetClipboardText ( const char *  text)

Put UTF-8 text into the clipboard.

Parameters
textthe text to store in the clipboard
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetClipboardText
SDL_HasClipboardText

◆ SDL_SetPrimarySelectionText()

int SDL_SetPrimarySelectionText ( const char *  text)

Put UTF-8 text into the primary selection.

Parameters
textthe text to store in the primary selection
Returns
0 on success or a negative error code on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetPrimarySelectionText
SDL_HasPrimarySelectionText