Class Clipboard

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Clipboard extends GObject

Represents data shared between applications or inside an application.

To get a GdkClipboard object, use Display.getClipboard() or Display.getPrimaryClipboard(). You can find out about the data that is currently available in a clipboard using getFormats().

To make text or image data available in a clipboard, use setText(String) or setTexture(Texture). For other data, you can use setContent(ContentProvider), which takes a ContentProvider object.

To read textual or image data from a clipboard, use readTextAsync(Cancellable, AsyncReadyCallback) or readTextureAsync(Cancellable, AsyncReadyCallback). For other data, use readAsync(String[], int, Cancellable, AsyncReadyCallback), which provides a GInputStream object.

  • Constructor Details

    • Clipboard

      public Clipboard(MemorySegment address)
      Create a Clipboard instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Clipboard

      public Clipboard()
      Create a new Clipboard.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Clipboard class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Clipboard asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getContent

      public @Nullable ContentProvider getContent()

      Returns the GdkContentProvider currently set on clipboard.

      If the this 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 getContent() 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(@Nullable String @Nullable [] mimeTypes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

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

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

      Parameters:
      mimeTypes - a null-terminated array of mime types to choose from
      ioPriority - the I/O priority of the request
      cancellable - optional GCancellable object
      callback - callback to call when the request is satisfied
    • readFinish

      public @Nullable InputStream readFinish(AsyncResult result, @Nullable Out<String> outMimeType) throws GErrorException

      Finishes an asynchronous clipboard read.

      See readAsync(String[], int, Cancellable, AsyncReadyCallback).

      Parameters:
      result - a GAsyncResult
      outMimeType - location to store the chosen mime type
      Returns:
      a GInputStream
      Throws:
      GErrorException - see GError
    • readTextAsync

      public void readTextAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously request the this Clipboard contents converted to a string.

      This is a simple wrapper around readValueAsync(Type, int, Cancellable, AsyncReadyCallback). Use that function or readAsync(String[], int, Cancellable, AsyncReadyCallback) directly if you need more control over the operation.

      Parameters:
      cancellable - optional GCancellable object
      callback - callback to call when the request is satisfied
    • readTextFinish

      public @Nullable String readTextFinish(AsyncResult result) throws GErrorException

      Finishes an asynchronous clipboard read.

      See readTextAsync(Cancellable, AsyncReadyCallback).

      Parameters:
      result - a GAsyncResult
      Returns:
      a new string
      Throws:
      GErrorException - see GError
    • readTextureAsync

      public void readTextureAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously request the this Clipboard contents converted to a GdkPixbuf.

      This is a simple wrapper around readValueAsync(Type, int, Cancellable, AsyncReadyCallback). Use that function or readAsync(String[], int, Cancellable, AsyncReadyCallback) 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
    • readTextureFinish

      public @Nullable Texture readTextureFinish(AsyncResult result) throws GErrorException

      Finishes an asynchronous clipboard read.

      See readTextureAsync(Cancellable, AsyncReadyCallback).

      Parameters:
      result - a GAsyncResult
      Returns:
      a new GdkTexture
      Throws:
      GErrorException - see GError
    • readValueAsync

      public void readValueAsync(Type type, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously request the this Clipboard contents converted to the given type.

      For local clipboard contents that are available in the given GType, the value will be copied directly. Otherwise, GDK will try to use Gdk.contentDeserializeAsync(InputStream, String, Type, int, Cancellable, AsyncReadyCallback) to convert the clipboard's data.

      Parameters:
      type - a GType to read
      ioPriority - the I/O priority of the request
      cancellable - optional GCancellable object
      callback - callback to call when the request is satisfied
    • readValueFinish

      public Value readValueFinish(AsyncResult result) throws GErrorException

      Finishes an asynchronous clipboard read.

      See readValueAsync(Type, int, Cancellable, AsyncReadyCallback).

      Parameters:
      result - a GAsyncResult
      Returns:
      a GValue containing the result.
      Throws:
      GErrorException - see GError
    • 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, this Clipboard will select the best format to transfer the contents and then request that format from provider.

      Parameters:
      provider - the new contents of this Clipboard or null to clear the clipboard
      Returns:
      true if setting the clipboard succeeded
    • 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(Texture texture)
      Puts the given texture into the clipboard.
      Parameters:
      texture - a GdkTexture to put into the clipboard
    • set

      public void set(Value value)
      Sets the this Clipboard to contain the given value.
      Parameters:
      value - a GValue to set
    • storeAsync

      public void storeAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously instructs the this Clipboard to store its contents remotely.

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

      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:
      ioPriority - the I/O priority of the request
      cancellable - optional GCancellable object
      callback - callback to call when the request is satisfied
    • storeFinish

      public boolean storeFinish(AsyncResult result) throws GErrorException

      Finishes an asynchronous clipboard store.

      See storeAsync(int, Cancellable, AsyncReadyCallback).

      Parameters:
      result - a GAsyncResult
      Returns:
      true if storing was successful.
      Throws:
      GErrorException - see GError
    • onChanged

      Emitted when the clipboard changes ownership.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged()
      Emits the "changed" signal. See onChanged(Clipboard.ChangedCallback).
    • builder

      public static Clipboard.Builder<? extends Clipboard.Builder> builder()
      A Clipboard.Builder object constructs a Clipboard with the specified properties. Use the various set...() methods to set properties, and finish construction with Clipboard.Builder.build().
      Returns:
      the builder object