1. 24
  1. 2

    This program is a very simple and easy-to-read implementation of clipboard tools on wayland, which is like this blog post but with actual code: https://git.sr.ht/~noocsharp/wayclip

    1. 2

      re: closing the application

      I almost feel like this is something the compositor ought to solve in an integrated manner. Attempt to do the “clipboard manager” trick if the user clicks the X button, or else give Notification: “Clipboard data lost” “The application [crashed|was closed].”

      1. 2

        I just put this in another comment, but what Windows does is it tells you to finish the copy to the system when there’s something pending, see https://learn.microsoft.com/en-us/windows/win32/dataxchg/wm-renderallformats it works pretty well over there.

        On X, you’d probably be best doing it on the application side, like the link said.

        I don’t know about about Wayland to comment there.

      2. 1

        Recently I went down the same path, trying to understand how the clipboard works on Linux. In my case I looked at X (since it was what I was running at the time), which is also based on selections “owned” by the apps themselves. The main reason was to understand if some security features could easily be introduced or not.

        I ended up writing 2 small blog posts about it:

        In the end, I agree with that this design provides a great deal of flexibility as the article mentions, but it is not immediately obvious for people looking at it for the first time.

        1. 1

          One interesting thing about the peer to peer model too is your own application could choose to provide different data to different applications… so say you copied a password and only want to paste it in a certain application, it could paste the real thing when the permitted app asks and give back fake data to other unauthorized clients. Though just denying the request likely works just as well too.

          I like a lot about the X model though, it is pretty elegant.

          If you are curious how it works on Windows, there’s two options. It also has an on-demand thing, quite similar to the X model, though if your window is closing, it asks you to copy it to the system at that point 1, or you can copy certain generic types to system memory and the OS will convert it on-demand to related formats. Quite similar in some ways, but with the central OS being aware of various formats it does make some kinds of interop easier. Though since it goes through the middle man of the OS, this both limits the info you can gleen about the peer, and gives the system an opportunity to be that security watchdog on your behalf. Overall, I like the Windows model too… it is probably better, but I’m partial to X anyway.

          edit: btw that PR you got is from someone I know in the D community! feels like a small world. and i actually didn’t know that extension was there so learned something new today.

          1. 1

            Very interesting, thanks.

            Though since it goes through the middle man of the OS, this both limits the info you can gleen about the peer, and gives the system an opportunity to be that security watchdog on your behalf.

            In this case MS would have to provide these features themselves or APIs that would allow an external app to do it.