11 ms·
How the clipboard works
- sam-s 4y agoWhy can't the server inherit the clipboard from the program being shut down? (unless the program crashes, it should go through the "official motions" and one of them should be notifying the server which then can request the clipboard. this should be done early in the shutdown process, of course)
- texaslonghorn5 4y agoGood refresher, nice share. I wish there was a little more transparency in the clipboard. When I press WinKey+V, Windows 10 only shows me one format but often pastes a different one (obviously) -- would be nice to have the option to allow me to look into the possible formats I can get out.
- bobthepanda 4y agoI know in Word and maybe other MS products you usually get an option of * keep source formatting * match destination formatting * text only
- ghusbands 4y agoNone of which quite do what they say, in my experience. For actual text-only pasting, I often end up pasting into a fresh notepad, then copying that and pasting into Word. Otherwise, newlines at least sometimes get altered. Similarly "match destination formatting" often gets confused by formatting changes within the pasted text. I often end up pasting even formatted text via notepad and then recreating the formatting by hand.
- texaslonghorn5 4y agoExactly, but the implementation is nontrivial/nonobvious if I'm copying from the web for example.
- justsomehnguy 4y ago> would be nice to have the option to allow me to look into the possible formats I can get out. That would only confuse an average Joe so don't have high hopes. IMMSMW there was a program what would show which formats are available for the current content, but hell if I remember how it was called and was it a regular program or just an exercise in Win32 API. Maybe it was in Raymond Chen's blog. But if you are interested you can probably write it yourself.[0] ADD: there is such a program on codeproject [1] but it requires a registration to download the binary, so I can't vouch for it. [0] https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats https://learn.microsoft.com/en-us/windows/win32/dataxchg/cli... [1] https://www.codeproject.com/Articles/886711/Drag-Drop-Images-and-Drop-Descriptions-for-MFC-App https://www.codeproject.com/Articles/886711/Drag-Drop-Images...
- texaslonghorn5 4y agoAgree on confuse, the option would have to be something hidden in settings. Anyway, I will look into links, thanks.
- jmkd 4y agoWould love to see an analysis on mobile. Android clipboard is broken. I paste out of date content into WhatsApp all the time (while other apps receive the updated 'copy' perfectly fine).
- alkonaut 4y agoWhat's the reason for this unusual no-actual-clipboard design? The user's mental model of a clipboard is that things are copied to the clipboard, so breaking that mental model has to have a reason? Obviously this is more elegant for several reasons (performance, security/privacy) etc. But still: the fact that it doesn't survive a shutdown sounds problematic. Can a clipboard manager fill that gap completely, i.e. copy and persist data so that apps don't have to take care of it themselves? One huge benefit of the no-actual-clipboard design that I can immediately see is the fact that probably 99% of all cut/copy/paste operations are within the same application, and this design allows a shortcut where the data can be cloned as the application sees fit. For example, an immutable data structure can just be added as another reference. If I have two copies of an image resource in my document, I can just use the same image in both locations. With a serializing copy the cost of serialization for the copy must be paid up front because we can't know whether the same application will be the receiver.
- xtiansimon 4y ago“… the fact that probably 99% of all cut/copy/paste operations are within the same application…” Depends. If you’re working, say, in an application writing or a drawing/graphic app then you’re likely doing a lot of copy and paste. In which case the total number of CnP operations is very high. However, this measure is misleading to the utility of CnP between applications. Not having to save to a compatible format and then importing from the other app is a great productivity improvement. Just saying.
- db48x 4y agoThis design dates back to X Windows (and probably before). It does indeed allow for various optimizations of that sort. A clipboard manager is simply a program that initiates a paste into it’s own window as soon as any other window announces that it has the selection. It then advertises itself as having the selection, so that the the user can ultimately paste the data wherever it should go. The clipboard manager can persist the clipboard state, maintain a history of recently copied items, etc.
- account42 4y ago
- tantalor 4y agoIf the copy-side app is supposed to serve the selection whenever requested, then what happens if the user interaction causes the selection to change or be removed? e.g., editing text or navigating to another page Does the copy-side app have to keep that selection around in memory forever? That seems like a big downside. > A big upside of this design is that no data is copied around unnecessarily. That's only true as long as the copy-side app still needs the data, otherwise it needs to save a local copy it doesn't need.
- kevincox 4y agoI think you are right but it is still an optimization in the common case. 1. If the owning app doesn't need it anymore it does need to keep it around until the clipboard is replaced, but this is likely still cheaper than copying. (For example if you are copying images you just need to reference-count the image, or if you are copying a table in an app with an undo history you are holding that data anyways, you just need to know how to rebuild the old version for the copy). 2. If the owning app is offering to do conversions (for example text/csv or text/html for a table) it only needs to hold one version in memory. Of course this does add a lot of complexity to do it "well". However the app can always start with a simple implementation (just make a copy/reference count internally) then migrate to a better implementation when it makes sense. It does seem to me that a hybrid implementation may have been the best. Apps can send data to the compositor (maybe via a sealed memfd) or just tell the compositor to ask for the data when it wants it. Maybe this could even be done per-content-type so that for example the app can send the `text/csv` to the compositor but if someone asks for `text/html` it can read the `text/csv` from the compositor then send back the `text/html`. But that would be an edge case, and still has a problem with closing applications. I guess when the application closes it can either 1. Upload the other content-types proactively before shutting down or the compositor just drops those types off of the clipboard leaving only the types that it holds itself.
- effnorwood 4y ago
- UI_at_80x24 4y agoI'm surprised there was no mention of copy/paste that existed BEFORE ctrl+c/ctrl+v ctrl + INS (copy) shift + INS (paste) IIRC this is a hardware interrupt in much the same way as ctrl+alt+del is. My memory is damn hazy about this (I've used DOS since MS-DOSv3.3) but I think I used that combination back in the DOS days. {instead of using the mouse to select things, shift+CURSOR would do the trick} This might even be a C=64 trick. I can't remember 100%. BUT Windows/Linux/BSD _STILL_ honour it's usage. (It's also a handy way to bypass some websites that block right-click & copy/paste.) I know there are more greybeards on here, so somebody help me nail down from whence CTRL+INS & SHIFT+INS originated.
- Arrath 4y agoWell I'll be. You learn a new hotkey every day. Certainly feels like it predates the mouse, considering the innate right-handedness of the key combo.
- Timwi 4y agoI've always thought of Ctrl+Ins/Shift+Del/Shift+Ins as an accessibility feature for left-handed people like me.
- Arrath 4y agoYou use the mouse left handed, then? I'm left handed myself and briefly tried that back as a youngster in computer lab but never really adjusted to it well enough to continue doing so.
- aidenn0 4y agoI definitely saw some of that keybinding in old DOS programs, but when I started using a microcomputer, the WordStar shortcuts (Control-K based scheme for copy/paste) were the most common.
- pvg 4y agohttps://en.wikipedia.org/wiki/IBM_Common_User_Access https://en.wikipedia.org/wiki/IBM_Common_User_Access It doesn't pre-date the C/V/X/Z shortcuts, it's just that those conflicted with things like CTRL-C to interrupt. I don't think hardware interrupts are involved here. It's not a particularly early DOS convention either, Wordstar-style shortcuts were popular before it.
- mdmglr 4y agoThis contradicts how I as a user think of the clipboard. The clipboard is the most important feature of end user computing that is ignored by OS designers. I should be able to open a window and see all things in my clipboard. Also with password managers like 1Password using the clipboard as a means to xmit sensitive data it seems to me like the API needs to be updated. An interesting solution to the problem discussed in the post would be how macOS implements Quick Look in Finder. Apps can serialize a data structure to clipboard and plugins can be responsible for deserialize on paste. This would solve the issue of apps being closed. Clipboard API should have the concept of sensitive data.
- Timwi 4y ago> I should be able to open a window and see all things in my clipboard. In Windows, pressing Win+V does exactly that.
- shmerl 4y agoIs there any good solution for remote clipboard sync with Wayland session? Use case is like this: * A - local computer with Wayland session. * B - remote computer with terminal neovim running. I can ssh from A to B and use neovim with clipboard and with X forwarding in ssh that clipboard is synced to local session. But for that I need a terminal that runs in XWayland mode locally when doing ssh and working with remote neovim. Is there a way to get the same result without X?
- TuringTest 4y ago> The majority of the implementations out there are broken and only handle text. Copy/paste are the biggest neglected operations in computing, considering that they are the only universal mechanism for transferring data between applications that is accessible to end users. Mobile intents do help somehow, but they are not universal or available on desktop or web environments.
- wongarsu 4y agoIn Windows-land I'm more annoyed that lots of applications default to pasting rich-text, when in 95% of cases I only want the text and not the formatting. Otoh, copy-pasting images or entire files works great, as does drag-and-drop all over the place (dragging things from Firefox's download popup, or from E-Mail attachments).
- TuringTest 4y agoThere are several clipboard apps that let you clean format and keep just the text by pasting with a hotkey like CTRL+SHIFT+V.
- punitg7 4y agoGood read. Also checkout https://punit-g7.medium.com/demystifying-clipboard-f96452a495fb https://punit-g7.medium.com/demystifying-clipboard-f96452a49... for a few more detailed cases.
- lmz 4y agoYours is for MacOS while the article is for Wayland.
- Daub 4y agoMy life was significantly improved when I discovered control shift paste, which pastes just text without format. But un-desired formatting of text remain the bane of my life.
- jimmytidey 4y agoSo essential - how often would I want the formatting in the obviously completely different context? I used to paste things into the URL bar to remove formatting. I've discovered a colleague does the same.
- dns_snek 4y agoYou might want to be careful about pasting anything remotely sensitive into the URL bar as most browser automatically send your query to the search engine for auto-complete functionality.
- TeMPOraL 4y agoMy habit on Windows, entirely in the muscle memory after two decades of doing it, is: - If the text to sanitize is a single line: Win+R, paste, select all, cut, Esc (to close "Run" window) - If it's multiple lines: Win+R, notepad, Enter, paste, select all, cut, Alt+F4 (to close notepad) On Linux, I usually switch to Emacs, switch to a scratch buffer, then do the paste-and-cut-again dance in it.
- wizzwizz4 4y agoI never changed my habits from Windows; I use the Run box, or type leafpad / mousepad. It's interesting that we've independently invented the same technique.
- Beltalowda 4y agoGitHub started mangling text some months ago and it bugs the hell out of me. It's also completely unnecessary as GitHub already links things like @user, #123, and deadbeef (for commit hashes). I just want to copy the exact literal text I see; why does that need to be hard? You can set "dom.event.clipboardevents.enabled" in Firefox to disable all of that, but some websites can break horribly because they just assume it's there and will do $weird_shit if it's not. e.g. Twitter and Facebook messenger for example; it's not that you get an error either, it just behaved in really odd ways. It seems Twitter works now in quick test, and I no longer need to use Facebook Messenger, so let's try setting it again. There's also "clipboard.plainTextOnly", but it doesn't seem to work, or maybe it does something different from what I expect.
- CobrastanJorji 4y agoThe "closing the app after copying and before pasting" case is very interesting. Shows how even things that sound simple turn out to have very tricky edge cases as soon as you start optimizing and really thinking about how to implement them. The clipboard manager solution seems okay, but copying everything immediately seems like it defeats a lot of the elegance of the design. Perhaps it'd be preferable if the original program held the clipboard until it was about to exit, at which point it would issue a "last call" sort of announcement so that a clipboard manager could optionally "take over" the clipboard. But that wouldn't capture crashes or any app that doesn't send such a signal, so perhaps the aggressive copying is more thorough. But if that's desirable, maybe always copying data to the window manager is the better choice. Presumably Windows is doing this?
- Khoth 4y agoOn Windows, when you Copy the program supplying the data decides whether to send the data to the clipboard manager straight away, or whether to defer. If it defers, then yes it does a "last call" on closing. If it crashes you lose the clipboard. Some programs will ask you when you quit them if you want to keep the clipboard contents, if you'd copied a large amount of data.
- ygra 4y agoAnnoyingy, in Excel's case that question "Do you really want to quit? You have copied large amounts of data to the clipboard." even occurs when you have a single cell's worth in the clipboard. But that's also a confirmation question that no one really understands unless they understand how the clipboard works (or can work).
- boole1854 4y agoI just tested this on the latest desktop version of Excel on Windows 10, and I did not get the 'large amounts of data' warning with only a single cell copied in the clipboard (the cell contained the word 'foo'). Increasing the number of cells copied to a large number did cause the warning to appear. I did not investigate further to see exactly how many cells need to be copied to cause the warning to appear.
- Null-Set 4y agoThis design could have an interesting security twist to it. The copy side could maybe infer who the paste side is and change the output, similar to the problems of piping curl into bash.
- robust-cactus 4y agoGiven how much memory we have available these days, would we build it the same way? Having copy paste usually work outta the box everywhere might be more valuable than memory savings. Sidebar: I do at this point use a copy paste history app anyways that saves and plain text-ifies everything.
- ClassyJacket 4y agoWhat's the app?
- spacebouy 4y agoI have been using ditto[0] for years and am happy with it. [0] https://ditto-cp.sourceforge.io/ https://ditto-cp.sourceforge.io/
- the_mitsuhiko 4y agoThis design has the really annoying situation that applications closing down can't leave stuff in the clipboard. This results in a quite a frustrating behavior for users and also makes command line tools tricky. wl-clipboard lets you pipe text into the command to copy. The way it works is that it daemonizes in the background to fulfill the copy request. It either cancels on the first paste (command) or until some other application copies something into the clipboard. It's not completely awful design, but I'm surprised that the protocol does not offer at least the option to move content into the clipboard and exit.
- mzs 4y agolots results when I google 'wayland clipboard manager' - here's the first https://github.com/yory8/clipman https://github.com/yory8/clipman
- tinalumfoil 4y agoThat's an unfortunate list of known issues.
- GaryPalmer 4y agoI don't get it (Windows user). If I copy some text in the browser and then close the browser the clipboard is gone under linux? How is that good design, wouldn't it be preferable if the OS is holding the clipboard data as a middle man?
- the_mitsuhiko 4y agoIt's horrible design. It's basically an omission of one of the most critical parts of how the Windows/macOS clipboard APIs actually function where data can optionally be frozen. For whatever reason the wayland folks thought they can get away without that functionality and from what I can tell (as user and developer) you can't.
- masklinn 4y ago> I don't get it (Windows user). If I copy some text in the browser and then close the browser the clipboard is gone under linux? How is that good design, wouldn't it be preferable if the OS is holding the clipboard data as a middle man? The essay covers this: it was picked because it means only the pasted data (of the right mimetype) gets copied, so it avoids unnecessary copies. This is especially useful if the source can generate large amounts of data e.g. an image program is able to copy in multiple image formats, in which case said program would have to export everything to the OS on copy. But yes that also means all the data is lost unless the source program takes extra non-trivial measures to keep the data alive. This made some sick kind of sense in X11, because all that data might have to transit over the network too if you were using remote X.
- TMWNN 4y agoMight as well ask here. On MacOS I have eight years of clips saved in a SQLite database created by Ondesoft's ClipBuddy. It is, by far, the best MacOS clipboard manager: 1. Unlimited clip storage, with no limit whether by time or space. 2. Search clips. 3. Paste without formatting from the keyboard. 4. Scroll up and down the history before pasting, again with the keyboard. Ondesoft hasn't updated ClipBuddy in years, and each new MacOS version makes it creakier. It was broken on Monterey 12.5.1; with Monterey 12.6 it is mysteriously working again, but I know I can't depend on it forever. I have tried ClipDrop, Clipy, CopyClip, Clips, ClipMenu, Jumpcut, and Qlipper, but nothing has all virtues. The closest I've found is Maccy; while limited to 999 clips, it supports 3 and I can partially replicate 4 with BetterTouchTool's help.[1] I would appreciate suggestions other alternatives, whether free or paid. [1] Speaking of which, I've never been able to get BetterTouchTool's own clipboard manager to work.
- swah 4y agoAlfred and Raycast also do that - I use the combo cmd+opt+v to search the clipboard history and then paste. But its not infinite - I think the longest settings is to keep items for 90 days.
- jeroenhd 4y agoFor those wondering about how Windows does this, there is, as you'd expect, a Raymond Chen article about it: https://devblogs.microsoft.com/oldnewthing/20210526-00/?p=105252 https://devblogs.microsoft.com/oldnewthing/20210526-00/?p=10... (and some more, like https://devblogs.microsoft.com/oldnewthing/20220608-00/?p=106727 https://devblogs.microsoft.com/oldnewthing/20220608-00/?p=10...) Elsewhere in these comments there is also a link to an explainer for the macOS equivalent. Here's also an explainer for X11: https://www.uninformativ.de/blog/postings/2017-04-02/0/POSTING-en.html https://www.uninformativ.de/blog/postings/2017-04-02/0/POSTI... It's interesting to look at these clipboard APIs together to see what may have led to the Wayland design, which is probably the most recently designed clipboard implementation. I think the Wayland API is more elegant but also requires a clipboard manager in cases where you wouldn't expect to need tone (to copy less than a kilobyte of data before closing the program, for example).
- SeanLuke 4y ago> Elsewhere in these comments there is also a link to an explainer for the macOS equivalent. I know you didn't mean anything by this, but given that the entire concept of a clipboard was invented by the Mac/Lisa team (the Xerox Alto didn't have one), it seems wrong to describe it as an "equivalent" to Windows.
- lupire 4y agoComing first doesn't make it less equivalent.
- jeroenhd 4y agoI don't think it was the Apple Lisa that had the first clipboard. Xerox definitely had a clipboard and other experimental environments had them as well. The Lisa was the first to name it the "clipboard" but that doesn't really count in my opinion. Also, modern macOS isn't based on the old mac operating system after switching to Unix, so even for Apple computers the macOS clipboard is an "equivalent" of the old clipboard.
- 4y ago
- enriquto 4y agoNo word about unix-style clipboard? Select to copy, middle-click to paste. If I had to highlight an immediate usability advantage of linux with respect to windows and macos, it would be clearly this thing. It feels "at home" when you can do this. Also, I have a viscerally strong disagreement with the following sentence: > The majority of the implementations out there are broken and only handle text. For me, one of the main uses of copy paste is to transform something to plain text. A clipboard implementation that pasted non-text things would be broken.
- bowsamic 4y agoMost people want to copy and paste files and images
- enriquto 4y agoI understand this concern. But it seems that it would be better to have an orthogonal implementation of this. The clipboard remains text-only. If you select an image or a file, it copies its absolute path (or url) into the clipboard. Then it is the responsibility of the destination program to interpret what to do with this text. If you paste the filename of an image into a plain text editor, you'll get the filename verbatim. If you paste it into an image editor, it opens and pastes the image in there. But from the point of view of the clipboard it's always just text (maybe with some textual markers).
- NavinF 4y agoThat breaks common use cases such as copy-pasting private images that can only be downloaded using your login cookies. > If you paste the filename of an image into a plain text editor, you'll get the filename verbatim. If you paste it into an image editor, it opens and pastes the image in there That's how the clipboard already works on Windows as long as the source application provides both formats.
- jakub_jo 4y agoOr better: The data URI gets copied.
- imiric 4y agoIt's remarkable to me how we still don't have a security-minded clipboard implementation, seemingly on any OS. It's standard security practice now to use a password manager, but they all[1] exchange critically sensitive data with applications via the clipboard, which is accessible by any application that asks for it. The best we can do is automatically clear the clipboard after a certain time, but this still leaves a wide window for any application to grab the contents. And if you're using a clipboard manager, the standard on Linux DEs, then you have to remember to clear it from there afterwards as well, and suddenly your clipboard manager is a very attractive honey pot. We need a secure channel for password managers to pass credentials to applications that a) doesn't use the system clipboard, and b) doesn't simulate the keyboard to type into the password field. All modern OSs fail in this regard, AFAICT. [1]: Except the ones that function as a browser extension and are used for logging into websites. But using something as critical as a password manager from a browser extension might be an even worse security practice than using the clipboard.
- xerxesaa 4y agoKeypassXC takes a slightly different approach. It uses named pipes to send the password from the application to the browser extension. Though the browser is where I find myself using it 95% of the time, they also have an "auto type" feature that will go to the last window and type in your password for you (again, without passing through the clipboard).
- imiric 4y agoSure, but those are all workarounds for specific uses and operating systems, which require specific integration between the app and the browser. What I want is a native solution provided by the OS that would work for all apps and scenarios.
- alkonaut 4y agoApplications also have access to global desktop screen recording, which has similar security issues. Basically: the desktop including all user input, frame buffers etc. was created as a free-for-all with security as an afterthought. It's as if all processes run in the same memory space. I should be able to control which apps can read the screen outside of its own top level window, and be notified when it happens (just like OSes often indicate mic recording). A screen sharing or screenshot app would require the permission and I'd allow it. Apps that place sensitive content on a clipboard (such as password managers) could use an isolated form of clipboard where only apps that are granted permissions can read. E.g. I copy from my pw manager and when I paste, the OS asks me if I want to allow "Firefox" to read the secure clipboard content from "KeePass".
- evilpie 4y ago> Type starting with x- are non-standard. x-moz- means it’s a mozilla-defined one. There seems to be no standard mime type for a URL The standard web MIME for url(s) is text/uri-list: https://www.rfc-editor.org/rfc/rfc2483#section-5 https://www.rfc-editor.org/rfc/rfc2483#section-5
- chrismorgan 4y agoFor those curious about how you’d find things like this: look in the media type registry at <https://www.iana.org/assignments/media-types/media-types.xhtml https://www.iana.org/assignments/media-types/media-types.xht...>; the likely search terms for something like this would be “URI” and “URL”. Still, I would agree with the original statemnt “There seems to be no standard mime type for a URL.” as text/uri-list is for a list of URLs with ␍␊ line separator and #-prefied comments. It would have been nice to have a MIME type for an individual URL with none of that, but it’s a bit late now, for best results anyway.