Blizarre / superclip

Super shared clipboard
GNU General Public License v3.0
0 stars 0 forks source link

Cli: Paste #1

Open Blizarre opened 4 years ago

Blizarre commented 4 years ago

~- copy stdin into the system clipboard~

Scope:

Blizarre commented 4 years ago

Clipboard management was much more complex than anticipated:

  1. The concept of "clipboard" is an abstraction that does not reflect reality.
  2. Wayland only offer a communication channel between application
  3. Wayland will only forward clipboard events to an application that has a window in focus, which means that the cli app need to create one (1x1 pixel).

Extra protocols (like data-protocol) can be used to get around 3., but there is no guarantee that they will be supported by the wayland implementation.

How it works:

  1. When a application A "copy" something, it merely advertise to wayland an "offer" with a list of available mime types
  2. When a application B want to "paste", it makes a request to wayland. It will then receive one event for each mime type available
  3. The application B then creates a Receive request with a mime type and a file descriptor, and send it to wayland. Wayland will forward it to A
  4. A will write the data to the file descriptor and close it at the end.

As you can see A must be running to transfer the data, which is a problem for short-lived apps like cli. Applications get around that by forking and leaving a process in the background to receive the requests.

Blizarre commented 4 years ago

I will split copy and paste and only focus on paste for the moment.

Blizarre commented 4 years ago

I have a working implementation of paste, I will just need to clean and package it before pushing it