class Gdk::Clipboard

Overview

The Gdk::Clipboard object represents data shared between applications or inside an application.

To get a Gdk::Clipboard object, use Gdk::Display#clipboard or Gdk::Display#primary_clipboard. You can find out about the data that is currently available in a clipboard using Gdk::Clipboard#formats.

To make text or image data available in a clipboard, use Gdk::Clipboard#text= or Gdk::Clipboard#texture=. For other data, you can use Gdk::Clipboard#content=, which takes a Gdk::ContentProvider object.

To read textual or image data from a clipboard, use Gdk::Clipboard#read_text_async or Gdk::Clipboard#read_texture_async. For other data, use Gdk::Clipboard#read_async, which provides a GInputStream object.

Defined in:

lib/gi-crystal/src/auto/gdk-4.0/clipboard.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new #

Initialize a new Clipboard.


[View source]
def self.new(*, content : Gdk::ContentProvider | Nil = nil, display : Gdk::Display | Nil = nil, formats : Gdk::ContentFormats | Nil = nil, local : Bool | Nil = nil) #

[View source]

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def changed_signal #

[View source]
def content : Gdk::ContentProvider | Nil #

Returns the Gdk::ContentProvider currently set on clipboard.

If the clipboard is empty or its contents are not owned by the current process, nil will be returned.


[View source]
def content=(provider : Gdk::ContentProvider | Nil) : Bool #

Sets a new content provider on clipboard.

The clipboard will claim the Gdk::Display's resources and advertise these new contents to other applications.

In the rare case of a failure, this function will return false. The clipboard will then continue reporting its old contents and ignore provider.

If the contents are read by either an external application or the clipboard's read functions, clipboard will select the best format to transfer the contents and then request that format from provider.


[View source]
def display : Gdk::Display #

Gets the Gdk::Display that the clipboard was created for.


[View source]
def display=(value : Gdk::Display | Nil) : Gdk::Display | Nil #

[View source]
def formats : Gdk::ContentFormats #

Gets the formats that the clipboard can provide its current contents in.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def is_local : Bool #

Returns if the clipboard is local.

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

Note that Gdk::Clipboard#content may return nil even on a local clipboard. In this case the clipboard is empty.


[View source]
def local? : Bool #

[View source]
def read_async(mime_types : Enumerable(String), io_priority : Int32, cancellable : Gio::Cancellable | Nil, callback : Gio::AsyncReadyCallback | Nil, user_data : Pointer(Void) | Nil) : 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 Gdk::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.


[View source]
def read_finish(result : Gio::AsyncResult) : Gio::InputStream | Nil #

Finishes an asynchronous clipboard read.

See Gdk::Clipboard#read_async.


[View source]
def read_text_async(cancellable : Gio::Cancellable | Nil, callback : Gio::AsyncReadyCallback | Nil, user_data : Pointer(Void) | Nil) : Nil #

Asynchronously request the clipboard contents converted to a string.

When the operation is finished callback will be called. You must then call Gdk::Clipboard#read_text_finish to get the result.

This is a simple wrapper around Gdk::Clipboard#read_value_async. Use that function or Gdk::Clipboard#read_async directly if you need more control over the operation.


[View source]
def read_text_finish(result : Gio::AsyncResult) : String | Nil #

Finishes an asynchronous clipboard read.

See Gdk::Clipboard#read_text_async.


[View source]
def read_texture_async(cancellable : Gio::Cancellable | Nil, callback : Gio::AsyncReadyCallback | Nil, user_data : Pointer(Void) | Nil) : Nil #

Asynchronously request the clipboard contents converted to a Gdk::Pixbuf.

When the operation is finished callback will be called. You must then call Gdk::Clipboard#read_texture_finish to get the result.

This is a simple wrapper around Gdk::Clipboard#read_value_async. Use that function or Gdk::Clipboard#read_async directly if you need more control over the operation.


[View source]
def read_texture_finish(result : Gio::AsyncResult) : Gdk::Texture | Nil #

Finishes an asynchronous clipboard read.

See Gdk::Clipboard#read_texture_async.


[View source]
def read_value_async(type : UInt64, io_priority : Int32, cancellable : Gio::Cancellable | Nil, callback : Gio::AsyncReadyCallback | Nil, user_data : Pointer(Void) | Nil) : Nil #

Asynchronously request the clipboard contents converted to the given type.

When the operation is finished callback will be called. You must then call Gdk::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 #content_deserialize_async to convert the clipboard's data.


[View source]
def read_value_finish(result : Gio::AsyncResult) : GObject::Value #

Finishes an asynchronous clipboard read.

See Gdk::Clipboard#read_value_async.


[View source]
def set(value : _) : 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 [method@GObject.Object.set] or [func@GObject.signal_emit].

WARNING ⚠️ The following code is in c ⚠️

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

gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture);

[View source]
def store_async(io_priority : Int32, cancellable : Gio::Cancellable | Nil, callback : Gio::AsyncReadyCallback | Nil, user_data : Pointer(Void) | Nil) : 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 Gdk::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 Gtk::Application is shut down, so you likely don't need to call it.


[View source]
def store_finish(result : Gio::AsyncResult) : Bool #

Finishes an asynchronous clipboard store.

See Gdk::Clipboard#store_async.


[View source]