sdl3-bindgen-sys
Safe HaskellNone
LanguageGHC2021

SDL3.Sys.Clipboard

Description

SDL provides access to the system clipboard, both for reading information from other processes and publishing information of its own.

This is not just text! SDL apps can access and publish data by mimetype.

Basic use (text)

Obtaining and publishing simple text to the system clipboard is as easy as calling getClipboardText and setClipboardText, respectively. These deal with C strings in UTF-8 encoding. Data transmission and encoding conversion is completely managed by SDL.

Clipboard callbacks (data other than text)

Things get more complicated when the clipboard contains something other than text. Not only can the system clipboard contain data of any type, in some cases it can contain the same data in different formats! For example, an image painting app might let the user copy a graphic to the clipboard, and offers it in .BMP, .JPG, or .PNG format for other apps to consume.

Obtaining clipboard data ("pasting") like this is a matter of calling getClipboardData and telling it the mimetype of the data you want. But how does one know if that format is available? hasClipboardData can report if a specific mimetype is offered, and getClipboardMimeTypes can provide the entire list of mimetypes available, so the app can decide what to do with the data and what formats it can support.

Setting the clipboard ("copying") to arbitrary data is done with setClipboardDataSafe. The app does not provide the data in this call, but rather the mimetypes it is willing to provide and a callback function. During the callback, the app will generate the data. This allows massive data sets to be provided to the clipboard, without any data being copied before it is explicitly requested. More specifically, it allows an app to offer data in multiple formats without providing a copy of all of them upfront. If the app has an image that it could provide in PNG or JPG format, it doesn't have to encode it to either of those unless and until something tries to paste it.

Primary Selection

The X11 and Wayland video targets have a concept of the "primary selection" in addition to the usual clipboard. This is generally highlighted (but not explicitly copied) text from various apps. SDL offers APIs for this through getPrimarySelectionText and setPrimarySelectionText. SDL offers these APIs on platforms without this concept, too, but only so far that it will keep a copy of a string that the app sets for later retrieval; the operating system will not ever attempt to change the string externally if it doesn't support a primary selection. Put UTF-8 text into the clipboard.

text
the text to store in the clipboard.
Returns
true on success or false on failure; call getError for more information.
Thread safety
This function should only be called on the main thread.
See also
getClipboardText
See also
hasClipboardText

FFI conventions

Unsuffixed aliases are unsafe foreign imports; aliases suffixed Safe are safe. Functions whose callbacks fire during the call export only the Safe alias (the genuine unsafe import stays reachable under SDL3.Sys.Bindgen.Clipboard.Unsafe); functions curated unsafe-only export only the unsuffixed one. Each alias's documentation records its flavor and rationale.

Full conventions: SDL3.Sys.

Since: 3.2.0

Synopsis

Documentation

Function aliases

setClipboardText Source #

Arguments

:: PtrConst CChar
C declaration
text
-> IO Bool 

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_SetClipboardText. The safe flavor is setClipboardTextSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_SetClipboardText, defined at SDL3/SDL_clipboard.h 104:34

setClipboardTextSafe Source #

Arguments

:: PtrConst CChar
C declaration
text
-> IO Bool 

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_SetClipboardText. The unsafe flavor is setClipboardText .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_SetClipboardText, defined at SDL3/SDL_clipboard.h 104:34

getClipboardText :: IO (Ptr CChar) Source #

Get UTF-8 text from the clipboard.

This function returns an empty string if there is 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 getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
hasClipboardText, setClipboardText

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetClipboardText. The safe flavor is getClipboardTextSafe : when this app owns the clipboard, its data-provider callback runs synchronously.
C declaration
SDL_GetClipboardText, defined at SDL3/SDL_clipboard.h 123:36

Since: 3.2.0

getClipboardTextSafe :: IO (Ptr CChar) Source #

Get UTF-8 text from the clipboard.

This function returns an empty string if there is 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 getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
hasClipboardText, setClipboardText

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetClipboardText. The unsafe flavor is getClipboardText : when this app owns the clipboard, its data-provider callback runs synchronously.
C declaration
SDL_GetClipboardText, defined at SDL3/SDL_clipboard.h 123:36

Since: 3.2.0

hasClipboardText :: IO Bool Source #

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

Returns
true if the clipboard has text, or false if it does not.
Thread safety
This function should only be called on the main thread.
See also
getClipboardText, setClipboardText

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_HasClipboardText. The safe flavor is hasClipboardTextSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_HasClipboardText, defined at SDL3/SDL_clipboard.h 137:34

Since: 3.2.0

hasClipboardTextSafe :: IO Bool Source #

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

Returns
true if the clipboard has text, or false if it does not.
Thread safety
This function should only be called on the main thread.
See also
getClipboardText, setClipboardText

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_HasClipboardText. The unsafe flavor is hasClipboardText .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_HasClipboardText, defined at SDL3/SDL_clipboard.h 137:34

Since: 3.2.0

setPrimarySelectionText Source #

Arguments

:: PtrConst CChar
text
the text to store in the primary selection.
-> IO Bool 

Put UTF-8 text into the primary selection.

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function should only be called on the main thread.
See also
getPrimarySelectionText, hasPrimarySelectionText

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_SetPrimarySelectionText. The safe flavor is setPrimarySelectionTextSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_SetPrimarySelectionText, defined at SDL3/SDL_clipboard.h 153:34

Since: 3.2.0

setPrimarySelectionTextSafe Source #

Arguments

:: PtrConst CChar
text
the text to store in the primary selection.
-> IO Bool 

Put UTF-8 text into the primary selection.

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function should only be called on the main thread.
See also
getPrimarySelectionText, hasPrimarySelectionText

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_SetPrimarySelectionText. The unsafe flavor is setPrimarySelectionText .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_SetPrimarySelectionText, defined at SDL3/SDL_clipboard.h 153:34

Since: 3.2.0

getPrimarySelectionText :: IO (Ptr CChar) Source #

Get UTF-8 text from the primary selection.

This function returns an empty string if there is 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 getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
hasPrimarySelectionText, setPrimarySelectionText

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetPrimarySelectionText. The safe flavor is getPrimarySelectionTextSafe .
C declaration
SDL_GetPrimarySelectionText, defined at SDL3/SDL_clipboard.h 172:36

Since: 3.2.0

getPrimarySelectionTextSafe :: IO (Ptr CChar) Source #

Get UTF-8 text from the primary selection.

This function returns an empty string if there is 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 getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
hasPrimarySelectionText, setPrimarySelectionText

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetPrimarySelectionText. The unsafe flavor is getPrimarySelectionText .
C declaration
SDL_GetPrimarySelectionText, defined at SDL3/SDL_clipboard.h 172:36

Since: 3.2.0

hasPrimarySelectionText :: IO Bool Source #

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

Returns
true if the primary selection has text, or false if it does not.
Thread safety
This function should only be called on the main thread.
See also
getPrimarySelectionText, setPrimarySelectionText

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_HasPrimarySelectionText. The safe flavor is hasPrimarySelectionTextSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_HasPrimarySelectionText, defined at SDL3/SDL_clipboard.h 187:34

Since: 3.2.0

hasPrimarySelectionTextSafe :: IO Bool Source #

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

Returns
true if the primary selection has text, or false if it does not.
Thread safety
This function should only be called on the main thread.
See also
getPrimarySelectionText, setPrimarySelectionText

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_HasPrimarySelectionText. The unsafe flavor is hasPrimarySelectionText .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_HasPrimarySelectionText, defined at SDL3/SDL_clipboard.h 187:34

Since: 3.2.0

setClipboardDataSafe Source #

Arguments

:: SDL_ClipboardDataCallback
callback
a function pointer to the function that provides the clipboard data.
-> SDL_ClipboardCleanupCallback
cleanup
a function pointer to the function that cleans up the clipboard data.
-> Ptr Void
userdata
an opaque pointer that will be forwarded to the callbacks.
-> PtrConst (PtrConst CChar)
mime_types
a list of mime-types that are being offered. SDL copies the given list.
-> Word64
num_mime_types
the number of mime-types in the mime_types list.
-> IO Bool 

Offer clipboard data to the OS.

Tell the operating system that the application is offering clipboard data for each of the provided 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 size of text data does not include any terminator, and the text does not need to be null-terminated (e.g., you can directly copy a portion of a document).

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function should only be called on the main thread.
See also
clearClipboardData, getClipboardData, hasClipboardData

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_SetClipboardData. The unsafe import is not exported : may invoke the previous cleanup callback synchronously. If your callback is a non-Haskell function pointer that never re-enters the Haskell runtime, the unsafe import remains available as SDL3.Sys.Bindgen.Clipboard.Unsafe.sDL_SetClipboardData.
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_SetClipboardData, defined at SDL3/SDL_clipboard.h 255:34

Since: 3.2.0

clearClipboardData :: IO Bool Source #

Clear the clipboard data.

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function should only be called on the main thread.
See also
setClipboardDataSafe

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_ClearClipboardData. The safe flavor is clearClipboardDataSafe .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_ClearClipboardData, defined at SDL3/SDL_clipboard.h 269:34

Since: 3.2.0

clearClipboardDataSafe :: IO Bool Source #

Clear the clipboard data.

Returns
true on success or false on failure; call getError for more information.
Thread safety
This function should only be called on the main thread.
See also
setClipboardDataSafe

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_ClearClipboardData. The unsafe flavor is clearClipboardData .
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_ClearClipboardData, defined at SDL3/SDL_clipboard.h 269:34

Since: 3.2.0

getClipboardData Source #

Arguments

:: PtrConst CChar
mime_type
the mime type to read from the clipboard.
-> Ptr CSize
size
a pointer filled in with the length of the returned data.
-> IO (Ptr Void) 

Get the data from the clipboard for a given mime type.

The size of text data does not include the terminator, but the text is guaranteed to be null-terminated.

Returns
the retrieved data buffer or NULL on failure; call getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
hasClipboardData, setClipboardDataSafe

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetClipboardData. The safe flavor is getClipboardDataSafe : when this app owns the clipboard, its data-provider callback runs synchronously.
C declaration
SDL_GetClipboardData, defined at SDL3/SDL_clipboard.h 290:36

Since: 3.2.0

getClipboardDataSafe Source #

Arguments

:: PtrConst CChar
mime_type
the mime type to read from the clipboard.
-> Ptr CSize
size
a pointer filled in with the length of the returned data.
-> IO (Ptr Void) 

Get the data from the clipboard for a given mime type.

The size of text data does not include the terminator, but the text is guaranteed to be null-terminated.

Returns
the retrieved data buffer or NULL on failure; call getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
hasClipboardData, setClipboardDataSafe

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetClipboardData. The unsafe flavor is getClipboardData : when this app owns the clipboard, its data-provider callback runs synchronously.
C declaration
SDL_GetClipboardData, defined at SDL3/SDL_clipboard.h 290:36

Since: 3.2.0

hasClipboardData Source #

Arguments

:: PtrConst CChar
mime_type
the mime type to check for data.
-> IO Bool 

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

Returns
true if data exists in the clipboard for the provided mime type, false if it does not.
Thread safety
This function should only be called on the main thread.
See also
setClipboardDataSafe, getClipboardData

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_HasClipboardData. The safe flavor is hasClipboardDataSafe : when this app owns the clipboard, its data-provider callback runs synchronously.
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_HasClipboardData, defined at SDL3/SDL_clipboard.h 306:34

Since: 3.2.0

hasClipboardDataSafe Source #

Arguments

:: PtrConst CChar
mime_type
the mime type to check for data.
-> IO Bool 

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

Returns
true if data exists in the clipboard for the provided mime type, false if it does not.
Thread safety
This function should only be called on the main thread.
See also
setClipboardDataSafe, getClipboardData

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_HasClipboardData. The unsafe flavor is hasClipboardData : when this app owns the clipboard, its data-provider callback runs synchronously.
Scalars
The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
C declaration
SDL_HasClipboardData, defined at SDL3/SDL_clipboard.h 306:34

Since: 3.2.0

getClipboardMimeTypes Source #

Arguments

:: Ptr CSize
num_mime_types
a pointer filled with the number of mime types, may be NULL.
-> IO (Ptr (Ptr CChar)) 

Retrieve the list of mime types available in the clipboard.

Returns
a null-terminated array of strings with mime types, or NULL on failure; call getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
setClipboardDataSafe

sdl3-bindgen-sys notes

Expand
FFI safety
Unsafe foreign import of SDL_GetClipboardMimeTypes. The safe flavor is getClipboardMimeTypesSafe .
C declaration
SDL_GetClipboardMimeTypes, defined at SDL3/SDL_clipboard.h 323:37

Since: 3.2.0

getClipboardMimeTypesSafe Source #

Arguments

:: Ptr CSize
num_mime_types
a pointer filled with the number of mime types, may be NULL.
-> IO (Ptr (Ptr CChar)) 

Retrieve the list of mime types available in the clipboard.

Returns
a null-terminated array of strings with mime types, or NULL on failure; call getError for more information. This should be freed with free when it is no longer needed.
Thread safety
This function should only be called on the main thread.
See also
setClipboardDataSafe

sdl3-bindgen-sys notes

Expand
FFI safety
Safe foreign import of SDL_GetClipboardMimeTypes. The unsafe flavor is getClipboardMimeTypes .
C declaration
SDL_GetClipboardMimeTypes, defined at SDL3/SDL_clipboard.h 323:37

Since: 3.2.0