ClipboardPortal

class ClipboardPortal(connection: DBusConnection)(source)

Wrapper around the org.freedesktop.portal.Clipboard D-Bus interface. Provides access to clipboard content for existing portal sessions.

This portal does not create its own session. It integrates with sessions from other portals, such as com.zugaldia.stargate.sdk.remotedesktop.RemoteDesktopPortal and the Input Capture portal. Call requestClipboard before the session starts to request clipboard access, then use setSelection, selectionWrite, selectionWriteDone, and selectionRead after the session is active.

Constructors

Link copied to clipboard
constructor(connection: DBusConnection)

Properties

Link copied to clipboard

Returns the interface version.

Functions

Link copied to clipboard

Returns a Flow that emits whenever the clipboard selection changes. The emitted signal's Clipboard.SelectionOwnerChanged.getOptions map contains OPTION_MIME_TYPES (as) and RESULT_SESSION_IS_OWNER (b) keys.

Link copied to clipboard
fun observeSelectionTransfer(sessionHandle: DBusPath): Flow<Clipboard.SelectionTransfer>

Returns a Flow that emits whenever another client requests clipboard content from this session. Respond to each event by calling selectionWrite with the signal's serial, then selectionWriteDone when the transfer is complete. If the request is not handled, call selectionWriteDone with success = false.

Link copied to clipboard
fun requestClipboard(sessionHandle: DBusPath): Result<Unit>

Requests clipboard access for the given session. Must be called before the session starts. The session must be started before calling any other method in this interface. Note that other interfaces may place restrictions on when it is possible to interact with the clipboard.

Link copied to clipboard
fun selectionRead(sessionHandle: DBusPath, mimeType: String): Result<FileDescriptor>

Reads clipboard content for the given MIME type via a file descriptor. The creation of the file descriptor is the responsibility of the callee.

Link copied to clipboard
fun selectionWrite(sessionHandle: DBusPath, serial: UInt32): Result<FileDescriptor>

Responds to a observeSelectionTransfer event by providing clipboard content via a file descriptor. It is the callee that creates the file descriptor. Write the clipboard data to it, then call selectionWriteDone once the transfer completes or fails.

Link copied to clipboard
fun selectionWriteDone(sessionHandle: DBusPath, serial: UInt32, success: Boolean): Result<Unit>

Notifies that a clipboard transfer initiated by selectionWrite has completed or failed. Must be called for every observeSelectionTransfer event, even on failure.

Link copied to clipboard
fun setSelection(sessionHandle: DBusPath, mimeTypes: List<String>): Result<Unit>

Sets the session as the owner of the clipboard for the given MIME types. The session will receive observeSelectionTransfer events when another client requests clipboard content in one of the advertised formats.