| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
SDL3.Sys.Clipboard
Contents
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 and getClipboardText, respectively. These deal with C strings in UTF-8 encoding. Data transmission and encoding conversion is completely managed by SDL.setClipboardText
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 and telling it the mimetype of the data you want. But how does one know if that format is available? getClipboardData can report if a specific mimetype is offered, and hasClipboardData 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.getClipboardMimeTypes
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 and getPrimarySelectionText. 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.setPrimarySelectionText
text- the text to store in the clipboard.
- Returns
- true on success or false on failure; call
getErrorfor 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
- module SDL3.Sys.Bindgen.Clipboard
- setClipboardText :: PtrConst CChar -> IO Bool
- setClipboardTextSafe :: PtrConst CChar -> IO Bool
- getClipboardText :: IO (Ptr CChar)
- getClipboardTextSafe :: IO (Ptr CChar)
- hasClipboardText :: IO Bool
- hasClipboardTextSafe :: IO Bool
- setPrimarySelectionText :: PtrConst CChar -> IO Bool
- setPrimarySelectionTextSafe :: PtrConst CChar -> IO Bool
- getPrimarySelectionText :: IO (Ptr CChar)
- getPrimarySelectionTextSafe :: IO (Ptr CChar)
- hasPrimarySelectionText :: IO Bool
- hasPrimarySelectionTextSafe :: IO Bool
- setClipboardDataSafe :: SDL_ClipboardDataCallback -> SDL_ClipboardCleanupCallback -> Ptr Void -> PtrConst (PtrConst CChar) -> Word64 -> IO Bool
- clearClipboardData :: IO Bool
- clearClipboardDataSafe :: IO Bool
- getClipboardData :: PtrConst CChar -> Ptr CSize -> IO (Ptr Void)
- getClipboardDataSafe :: PtrConst CChar -> Ptr CSize -> IO (Ptr Void)
- hasClipboardData :: PtrConst CChar -> IO Bool
- hasClipboardDataSafe :: PtrConst CChar -> IO Bool
- getClipboardMimeTypes :: Ptr CSize -> IO (Ptr (Ptr CChar))
- getClipboardMimeTypesSafe :: Ptr CSize -> IO (Ptr (Ptr CChar))
Documentation
module SDL3.Sys.Bindgen.Clipboard
Function aliases
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_SetClipboardText. The safe flavor issetClipboardTextSafe. - 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 atSDL3/SDL_clipboard.h 104:34
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_SetClipboardText. The unsafe flavor issetClipboardText. - 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 atSDL3/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
getErrorfor more information. This should be freed withfreewhen 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
- FFI safety
- Unsafe foreign import of
SDL_GetClipboardText. The safe flavor isgetClipboardTextSafe: when this app owns the clipboard, its data-provider callback runs synchronously. - C declaration
SDL_GetClipboardText, defined atSDL3/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
getErrorfor more information. This should be freed withfreewhen 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
- FFI safety
- Safe foreign import of
SDL_GetClipboardText. The unsafe flavor isgetClipboardText: when this app owns the clipboard, its data-provider callback runs synchronously. - C declaration
SDL_GetClipboardText, defined atSDL3/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
- FFI safety
- Unsafe foreign import of
SDL_HasClipboardText. The safe flavor ishasClipboardTextSafe. - 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 atSDL3/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
- FFI safety
- Safe foreign import of
SDL_HasClipboardText. The unsafe flavor ishasClipboardText. - 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 atSDL3/SDL_clipboard.h 137:34
Since: 3.2.0
setPrimarySelectionText Source #
Put UTF-8 text into the primary selection.
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
getPrimarySelectionText,hasPrimarySelectionText
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_SetPrimarySelectionText. The safe flavor issetPrimarySelectionTextSafe. - 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 atSDL3/SDL_clipboard.h 153:34
Since: 3.2.0
setPrimarySelectionTextSafe Source #
Put UTF-8 text into the primary selection.
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
getPrimarySelectionText,hasPrimarySelectionText
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_SetPrimarySelectionText. The unsafe flavor issetPrimarySelectionText. - 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 atSDL3/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
getErrorfor more information. This should be freed withfreewhen 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
- FFI safety
- Unsafe foreign import of
SDL_GetPrimarySelectionText. The safe flavor isgetPrimarySelectionTextSafe. - C declaration
SDL_GetPrimarySelectionText, defined atSDL3/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
getErrorfor more information. This should be freed withfreewhen 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
- FFI safety
- Safe foreign import of
SDL_GetPrimarySelectionText. The unsafe flavor isgetPrimarySelectionText. - C declaration
SDL_GetPrimarySelectionText, defined atSDL3/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
- FFI safety
- Unsafe foreign import of
SDL_HasPrimarySelectionText. The safe flavor ishasPrimarySelectionTextSafe. - 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 atSDL3/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
- FFI safety
- Safe foreign import of
SDL_HasPrimarySelectionText. The unsafe flavor ishasPrimarySelectionText. - 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 atSDL3/SDL_clipboard.h 187:34
Since: 3.2.0
Arguments
| :: SDL_ClipboardDataCallback |
|
| -> SDL_ClipboardCleanupCallback |
|
| -> Ptr Void |
|
| -> PtrConst (PtrConst CChar) |
|
| -> Word64 |
|
| -> 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
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
clearClipboardData,getClipboardData,hasClipboardData
sdl3-bindgen-sys notes
- 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 asSDL3.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 atSDL3/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
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
setClipboardDataSafe
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_ClearClipboardData. The safe flavor isclearClipboardDataSafe. - 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 atSDL3/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
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
setClipboardDataSafe
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_ClearClipboardData. The unsafe flavor isclearClipboardData. - 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 atSDL3/SDL_clipboard.h 269:34
Since: 3.2.0
Arguments
| :: PtrConst CChar |
|
| -> Ptr CSize |
|
| -> 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
getErrorfor more information. This should be freed withfreewhen 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
- FFI safety
- Unsafe foreign import of
SDL_GetClipboardData. The safe flavor isgetClipboardDataSafe: when this app owns the clipboard, its data-provider callback runs synchronously. - C declaration
SDL_GetClipboardData, defined atSDL3/SDL_clipboard.h 290:36
Since: 3.2.0
Arguments
| :: PtrConst CChar |
|
| -> Ptr CSize |
|
| -> 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
getErrorfor more information. This should be freed withfreewhen 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
- FFI safety
- Safe foreign import of
SDL_GetClipboardData. The unsafe flavor isgetClipboardData: when this app owns the clipboard, its data-provider callback runs synchronously. - C declaration
SDL_GetClipboardData, defined atSDL3/SDL_clipboard.h 290:36
Since: 3.2.0
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
- FFI safety
- Unsafe foreign import of
SDL_HasClipboardData. The safe flavor ishasClipboardDataSafe: 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 atSDL3/SDL_clipboard.h 306:34
Since: 3.2.0
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
- FFI safety
- Safe foreign import of
SDL_HasClipboardData. The unsafe flavor ishasClipboardData: 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 atSDL3/SDL_clipboard.h 306:34
Since: 3.2.0
getClipboardMimeTypes Source #
Arguments
| :: Ptr CSize |
|
| -> 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
getErrorfor more information. This should be freed withfreewhen it is no longer needed. - Thread safety
- This function should only be called on the main thread.
- See also
setClipboardDataSafe
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetClipboardMimeTypes. The safe flavor isgetClipboardMimeTypesSafe. - C declaration
SDL_GetClipboardMimeTypes, defined atSDL3/SDL_clipboard.h 323:37
Since: 3.2.0
getClipboardMimeTypesSafe Source #
Arguments
| :: Ptr CSize |
|
| -> 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
getErrorfor more information. This should be freed withfreewhen it is no longer needed. - Thread safety
- This function should only be called on the main thread.
- See also
setClipboardDataSafe
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetClipboardMimeTypes. The unsafe flavor isgetClipboardMimeTypes. - C declaration
SDL_GetClipboardMimeTypes, defined atSDL3/SDL_clipboard.h 323:37
Since: 3.2.0