Class: Gdk::Clipboard

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Overview

The GdkClipboard object represents data shared between applications or inside an application.

To get a GdkClipboard object, use [methodGdk.Display.get_clipboard] or [methodGdk.Display.get_primary_clipboard]. You can find out about the data that is currently available in a clipboard using [methodGdk.Clipboard.get_formats].

To make text or image data available in a clipboard, use [methodGdk.Clipboard.set_text] or [methodGdk.Clipboard.set_texture]. For other data, you can use [methodGdk.Clipboard.set_content], which takes a [classGdk.ContentProvider] object.

To read textual or image data from a clipboard, use [methodGdk.Clipboard.read_text_async] or [methodGdk.Clipboard.read_texture_async]. For other data, use [methodGdk.Clipboard.read_async], which provides a GInputStream object.

Instance Method Summary collapse

Instance Method Details

#contentGdk::ContentProvider

The GdkContentProvider or nil if the clipboard is empty or contents are provided otherwise.

Returns:

#content=(content) ⇒ Gdk::ContentProvider

The GdkContentProvider or nil if the clipboard is empty or contents are provided otherwise.

Parameters:

Returns:

#displayGdk::Display

The GdkDisplay that the clipboard belongs to.

Returns:

#display=(display) ⇒ Gdk::Display

The GdkDisplay that the clipboard belongs to.

Parameters:

Returns:

#formatsGdk::ContentFormats

The possible formats that the clipboard can provide its data in.

Returns:

  • (Gdk::ContentFormats)

    formats

#formats=(formats) ⇒ Gdk::ContentFormats

The possible formats that the clipboard can provide its data in.

Parameters:

  • formats (Gdk::ContentFormats)

Returns:

  • (Gdk::ContentFormats)

    formats

  • (Gdk::ContentFormats)

    formats

#is_localBoolean

Returns if the clipboard is local.

A clipboard is considered local if it was last claimed by the running application.

Note that [methodGdk.Clipboard.get_content] may return nil even on a local clipboard. In this case the clipboard is empty.

Returns:

  • (Boolean)

    true if the clipboard is local

#local=(local) ⇒ Boolean

true if the contents of the clipboard are owned by this process.

Parameters:

  • local (Boolean)

Returns:

  • (Boolean)

    local

  • (Boolean)

    local

#local?Boolean

true if the contents of the clipboard are owned by this process.

Returns:

  • (Boolean)

    local

#read_async(mime_types, io_priority, cancellable, callback, user_data) ⇒ nil

Asynchronously requests an input stream to read the clipboard's contents from.

When the operation is finished callback will be called. You must then call [methodGdk.Clipboard.read_finish] to get the result of the operation.

The clipboard will choose the most suitable mime type from the given list to fulfill the request, preferring the ones listed first.

Parameters:

  • mime_types (Array<String>)

    an array of mime types to choose from

  • io_priority (Integer)

    the I/O priority of the request

  • cancellable (Gio::Cancellable)

    optional GCancellable object

  • callback (Gio::AsyncReadyCallback)

    callback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#read_finish(result, out_mime_type) ⇒ Gio::InputStream

Finishes an asynchronous clipboard read.

See [methodGdk.Clipboard.read_async].

Parameters:

  • result (Gio::AsyncResult)

    a GAsyncResult

  • out_mime_type (String)

    location to store the chosen mime type

Returns:

  • (Gio::InputStream)

    a GInputStream

#read_text_async(cancellable, callback, user_data) ⇒ nil

Asynchronously request the clipboard contents converted to a string.

When the operation is finished callback will be called. You must then call [methodGdk.Clipboard.read_text_finish] to get the result.

This is a simple wrapper around [methodGdk.Clipboard.read_value_async]. Use that function or [methodGdk.Clipboard.read_async] directly if you need more control over the operation.

Parameters:

  • cancellable (Gio::Cancellable)

    optional GCancellable object

  • callback (Gio::AsyncReadyCallback)

    callback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#read_text_finish(result) ⇒ String

Finishes an asynchronous clipboard read.

See [methodGdk.Clipboard.read_text_async].

Parameters:

  • result (Gio::AsyncResult)

    a GAsyncResult

Returns:

  • (String)

    a new string

#read_texture_async(cancellable, callback, user_data) ⇒ nil

Asynchronously request the clipboard contents converted to a GdkPixbuf.

When the operation is finished callback will be called. You must then call [methodGdk.Clipboard.read_texture_finish] to get the result.

This is a simple wrapper around [methodGdk.Clipboard.read_value_async]. Use that function or [methodGdk.Clipboard.read_async] directly if you need more control over the operation.

Parameters:

  • cancellable (Gio::Cancellable)

    optional GCancellable object, nil to ignore.

  • callback (Gio::AsyncReadyCallback)

    callback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#read_texture_finish(result) ⇒ Gdk::Texture

Finishes an asynchronous clipboard read.

See [methodGdk.Clipboard.read_texture_async].

Parameters:

  • result (Gio::AsyncResult)

    a GAsyncResult

Returns:

#read_value_async(type, io_priority, cancellable, callback, user_data) ⇒ nil

Asynchronously request the clipboard contents converted to the given type.

When the operation is finished callback will be called. You must then call [methodGdk.Clipboard.read_value_finish] to get the resulting GValue.

For local clipboard contents that are available in the given GType, the value will be copied directly. Otherwise, GDK will try to use [funccontent_deserialize_async] to convert the clipboard's data.

Parameters:

  • type (GLib::Type)

    a GType to read

  • io_priority (Integer)

    the I/O priority of the request

  • cancellable (Gio::Cancellable)

    optional GCancellable object

  • callback (Gio::AsyncReadyCallback)

    callback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#read_value_finish(result) ⇒ GObject::Value

Finishes an asynchronous clipboard read.

See [methodGdk.Clipboard.read_value_async].

Parameters:

  • result (Gio::AsyncResult)

    a GAsyncResult

Returns:

  • (GObject::Value)

    a GValue containing the result.

#set(type, array) ⇒ nil

Sets the clipboard to contain the value collected from the given varargs.

Values should be passed the same way they are passed to other value collecting APIs, such as [methodGObject.Object.set] or [funcGObject.signal_emit].

gdk_clipboard_set (clipboard, GTK_TYPE_STRING, "Hello World");

gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture);

Parameters:

  • type (GLib::Type)

    type of value to set

  • array (Array)

    value contents conforming to type

Returns:

  • (nil)

#set_valist(type, args) ⇒ nil

Sets the clipboard to contain the value collected from the given args.

Parameters:

  • type (GLib::Type)

    type of value to set

  • args (Gdk::va_list)

    varargs containing the value of type

Returns:

  • (nil)

#store_async(io_priority, cancellable, callback, user_data) ⇒ nil

Asynchronously instructs the clipboard to store its contents remotely.

If the clipboard is not local, this function does nothing but report success.

The callback must call [methodGdk.Clipboard.store_finish].

The purpose of this call is to preserve clipboard contents beyond the lifetime of an application, so this function is typically called on exit. Depending on the platform, the functionality may not be available unless a "clipboard manager" is running.

This function is called automatically when a GtkApplication is shut down, so you likely don't need to call it.

Parameters:

  • io_priority (Integer)

    the I/O priority of the request

  • cancellable (Gio::Cancellable)

    optional GCancellable object

  • callback (Gio::AsyncReadyCallback)

    callback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#store_finish(result) ⇒ Boolean

Finishes an asynchronous clipboard store.

See [methodGdk.Clipboard.store_async].

Parameters:

  • result (Gio::AsyncResult)

    a GAsyncResult

Returns:

  • (Boolean)

    true if storing was successful.

#text=(text) ⇒ nil

Puts the given text into the clipboard.

Parameters:

  • text (String)

    Text to put into the clipboard

Returns:

  • (nil)

#texture=(texture) ⇒ nil

Puts the given texture into the clipboard.

Parameters:

  • texture (Gdk::Texture)

    a GdkTexture to put into the clipboard

Returns:

  • (nil)

#value=(value) ⇒ nil

Sets the clipboard to contain the given value.

Parameters:

  • value (GObject::Value)

    a GValue to set

Returns:

  • (nil)