Class Clipboard

All Implemented Interfaces:
PointerInterface

public class Clipboard extends Object
The `GdkClipboard` object represents data shared between applications or
inside an application.

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

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

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

https://docs.gtk.org/gdk4/class.Clipboard.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getContent

      public ContentProvider getContent()
      Returns the `GdkContentProvider` currently set on @clipboard.

      If the @clipboard is empty or its contents are not owned by the
      current process, %NULL will be returned.
      Returns:
      The content of a clipboard if the clipboard does not maintain any content
    • getDisplay

      public Display getDisplay()
      Gets the `GdkDisplay` that the clipboard was created for.
      Returns:
      a `GdkDisplay`
    • getFormats

      public ContentFormats getFormats()
      Gets the formats that the clipboard can provide its current contents in.
      Returns:
      The formats of the clipboard
    • isLocal

      public boolean isLocal()
      Returns if the clipboard is local.

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

      Note that [method@Gdk.Clipboard.get_content] may return %NULL
      even on a local clipboard. In this case the clipboard is empty.
      Returns:
      %TRUE if the clipboard is local
    • readAsync

      public void readAsync(@Nonnull Strs mime_types, int io_priority, @Nullable Cancellable cancellable, Clipboard.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      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 [method@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.
      Parameters:
      mime_types - a %NULL-terminated array of mime types to choose from
      io_priority - the I/O priority of the request
      cancellable - optional `GCancellable` object
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • readFinish

      public InputStream readFinish(@Nonnull AsyncResult result, @Nullable Strs out_mime_type) throws AllocationError
      Finishes an asynchronous clipboard read.

      See [method@Gdk.Clipboard.read_async].
      Parameters:
      result - a `GAsyncResult`
      out_mime_type - location to store the chosen mime type
      Returns:
      a `GInputStream`
      Throws:
      AllocationError
    • readTextAsync

      public void readTextAsync(@Nullable Cancellable cancellable, Clipboard.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously request the @clipboard contents converted to a string.

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

      This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
      Use that function or [method@Gdk.Clipboard.read_async] directly if you
      need more control over the operation.
      Parameters:
      cancellable - optional `GCancellable` object
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • readTextFinish

      public Str readTextFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an asynchronous clipboard read.

      See [method@Gdk.Clipboard.read_text_async].
      Parameters:
      result - a `GAsyncResult`
      Returns:
      a new string
      Throws:
      AllocationError
    • readTextureAsync

      public void readTextureAsync(@Nullable Cancellable cancellable, Clipboard.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously request the @clipboard contents converted to a `GdkPixbuf`.

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

      This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
      Use that function or [method@Gdk.Clipboard.read_async] directly if you
      need more control over the operation.
      Parameters:
      cancellable - optional `GCancellable` object, %NULL to ignore.
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • readTextureFinish

      public Texture readTextureFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an asynchronous clipboard read.

      See [method@Gdk.Clipboard.read_texture_async].
      Parameters:
      result - a `GAsyncResult`
      Returns:
      a new `GdkTexture`
      Throws:
      AllocationError
    • readValueAsync

      public void readValueAsync(long type, int io_priority, @Nullable Cancellable cancellable, Clipboard.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      Asynchronously request the @clipboard contents converted to the given
      @type.

      When the operation is finished @callback will be called. You must then call
      [method@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
      [func@content_deserialize_async] to convert the clipboard's data.
      Parameters:
      type - a `GType` to read
      io_priority - the I/O priority of the request
      cancellable - optional `GCancellable` object
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • readValueFinish

      public Value readValueFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an asynchronous clipboard read.

      See [method@Gdk.Clipboard.read_value_async].
      Parameters:
      result - a `GAsyncResult`
      Returns:
      a `GValue` containing the result.
      Throws:
      AllocationError
    • set

      public void set(long type, Object... _elipse)
      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`].

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

      gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture);
      ```
      Parameters:
      type - type of value to set
      _elipse - value contents conforming to @type
    • setContent

      public boolean setContent(@Nullable ContentProvider provider)
      Sets a new content provider on @clipboard.

      The clipboard will claim the `GdkDisplay`'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.
      Parameters:
      provider - the new contents of @clipboard or %NULL to clear the clipboard
      Returns:
      %TRUE if setting the clipboard succeeded
    • setText

      public void setText(@Nonnull Str text)
      Puts the given @text into the clipboard.
      Parameters:
      text - Text to put into the clipboard
    • setText

      public void setText(String text)
      Puts the given @text into the clipboard.
      Parameters:
      text - Text to put into the clipboard
    • setTexture

      public void setTexture(@Nonnull Texture texture)
      Puts the given @texture into the clipboard.
      Parameters:
      texture - a `GdkTexture` to put into the clipboard
    • setValue

      public void setValue(@Nonnull Value value)
      Sets the @clipboard to contain the given @value.
      Parameters:
      value - a `GValue` to set
    • storeAsync

      public void storeAsync(int io_priority, @Nullable Cancellable cancellable, Clipboard.OnAsyncReadyCallback callback, @Nullable Pointer user_data)
      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 [method@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 [class@Gtk.Application] is
      shut down, so you likely don't need to call it.
      Parameters:
      io_priority - the I/O priority of the request
      cancellable - optional `GCancellable` object
      callback - callback to call when the request is satisfied
      user_data - the data to pass to callback function
    • storeFinish

      public boolean storeFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes an asynchronous clipboard store.

      See [method@Gdk.Clipboard.store_async].
      Parameters:
      result - a `GAsyncResult`
      Returns:
      %TRUE if storing was successful.
      Throws:
      AllocationError
    • onChanged

      public SignalHandler onChanged(Clipboard.OnChanged signal)
      Connect to signal "changed".
      See Clipboard.OnChanged.onChanged() for signal description.
      Field SIGNAL_ON_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()