Class WaylandClipboard

java.lang.Object
limn.backend.lwjgl.transfer.WaylandClipboard
All Implemented Interfaces:
NativeClipboard

public final class WaylandClipboard extends Object implements NativeClipboard
The Wayland clipboard: a wl_data_device of our own on the display GLFW opened.

GLFW has one too and keeps it; a client may have several, and each is told of the selection. Ours needs three things GLFW does not give away. A wl_seat bound again from a registry of ours, since GLFW's proxy is private. The serial of the last key or button, which set_selection must quote and GLFW does not expose: a wl_keyboard and a wl_pointer of ours hear the same input for that number alone. And an event queue of our own, dispatched by a thread of ours: GLFW reads what another client offers with a blocking read() on the UI thread, so when this process is the one offering, the request to send can only be served from another thread. On the default queue that is a deadlock, measured on KWin on 2026-10-08, and with the queue it is not.

Bytes cross through pipes, read and written on short-lived threads so that neither the UI thread nor the dispatch thread ever waits on another program. A file descriptor is opened as a stream through /proc/self/fd, which is what spares this class a binding of read and write.

  • Constructor Details

    • WaylandClipboard

      public WaylandClipboard(long display)
      Parameters:
      display - GLFW's wl_display
      Throws:
      RuntimeException - when the library is absent or the compositor has no seat or no data device manager; the caller then keeps GLFW's text clipboard
  • Method Details

    • canActivate

      public boolean canActivate()
      Returns:
      whether this compositor can be shown a token
    • activate

      public boolean activate(String token, long surface)
      Asks the compositor to bring a surface in front, with a token that says the user asked. Any thread.
      Parameters:
      token - the token, from a panel or from requestToken(long)
      surface - the window's wl_surface
      Returns:
      whether the request was sent; what the compositor does with it is its own
    • requestToken

      public CompletableFuture<String> requestToken(long surface)
      Asks the compositor for a token that says the user is acting in a surface of ours now: the last key or button it was given, and the surface. A program handed the token may come in front of that surface. Any thread.
      Parameters:
      surface - the wl_surface the user is acting in
      Returns:
      the token, or an empty string where the compositor gives none; completed on the thread that hears the compositor, or at once
    • filesOfADrop

      public void filesOfADrop(List<Path> files)
      The files the window library read of a drop on one of this program's windows. It keeps a data device of its own and takes a drop of files itself, after which the source gives the offer made to this one nothing: these are then what a read of that drop's files answers.
      Parameters:
      files - the files it read
    • register

      public WindowDrag register(long surface, Supplier<WindowInput> input, DoubleUnaryOperator toLogical, UiRuntime ui)
      Makes a window a source and a destination of the system's drags. UI thread.
      Parameters:
      surface - the window's wl_surface
      input - the window's input, as it is at the time of each call; may answer null
      toLogical - from the surface's coordinates to the window's logical points
      ui - the UI runtime
      Returns:
      the window's drag
    • isOwner

      public boolean isOwner()
      Specified by:
      isOwner in interface NativeClipboard
      Returns:
      whether what the clipboard holds was put there by the last NativeClipboard.offer(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, byte[]>) of this process and has not been replaced since
    • types

      public List<String> types()
      Description copied from interface: NativeClipboard
      The types on the clipboard as the system last reported them, without asking it again.
      Specified by:
      types in interface NativeClipboard
      Returns:
      canonical type names, best first; empty when the clipboard is empty or unknown
    • read

      public CompletableFuture<byte[]> read(String type)
      Description copied from interface: NativeClipboard
      Asks for the bytes of one type.
      Specified by:
      read in interface NativeClipboard
      Parameters:
      type - one of NativeClipboard.types()
      Returns:
      the bytes, completed on whatever thread the implementation reads on; completed exceptionally when the type is not, or no longer, there
    • offer

      public void offer(List<String> types, Function<String,byte[]> bytes)
      Description copied from interface: NativeClipboard
      Makes this process the clipboard's owner.
      Specified by:
      offer in interface NativeClipboard
      Parameters:
      types - what is offered, best first; empty empties the clipboard
      bytes - the bytes of one of those types, asked for when a program wants them; it may be called on any thread and may block, and answers null for what it cannot make
    • setChangeListener

      public void setChangeListener(Runnable listener)
      Specified by:
      setChangeListener in interface NativeClipboard
      Parameters:
      listener - called, on any thread, after the clipboard's types or its owner change, an NativeClipboard.offer(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, byte[]>) of this process included; replaces the one before
    • close

      public void close()
      Description copied from interface: NativeClipboard
      Lets go of the system's resources. The clipboard is not used afterwards.
      Specified by:
      close in interface NativeClipboard