News for hackers. Stuff that matters.
Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @08:16AM (#29808487)
I'm working on a clipboard manager, because I'm not happy with any of the ones currently available. Here are my design goals:

- The system should be able to efficiently store, manipulate, and search an unlimited number of clipboard entries with reasonable performance.

- The software should be cross-platform, and should have implementations for major desktop platforms (Windows, X11, Wayland, macOS).

- Non-text data (images) and rich text (e.g. HTML) should be supported.

- Clipboard history can be shared across instances using a network connection.

- Instances may temporarily go offline, and sync up with other instances once a connection is re-established.

- - All functionality should continue to be available when offline (other than sync).

- Deletions must be propagated across instances.

- Deleted clips must not be trivially recoverable.

- Deleted clips must be deleted everywhere, including any copies in OS clipboards.

- Sync should be incremental (and otherwise generally efficient).

- When connected, actions should propagate across instances in real time (instantly, as opposed to polling, and with no unnecessary roundtrips).

- Relaying should be supported (in a `A <-> B <-> C` scheme, A should be able to see C's actions).

- Network topology cycles should not result in a feedback loop.

- It should be safe and easy to simply copy the database file to another host, "pre-seeding" the clipboard history.

- Support "portable installs" (carrying the software, configuration, and database on portable storage).

- It should be easy to write interoperable implementations of bridges/clients in most programming languages.

- Non-GUI functionality should be separated (or separatable) from GUI functionality, so that a GUI toolkit doesn't need to be loaded at all times.

Any suggestions?

Re:The weight of the clipboard by BuyMyBitcoins on Wednesday January 05, 2022 @09:59AM (#29809742)
As someone who used to work with spreadsheets extensively at a bank, I can tell you that some kind of stack/queue functionality would be a godsend.

For instance, in this mode you hit Ctrl+C five times, then the subsequent five Ctrl+V actions paste the data in FIFO order. It may not seem like much, but going in between app windows in order to grab data is a big time sink. Being able to copy items sequentially and then paste them sequentially would be a killer app in most Excel heavy office workflows. You could also add a toggle for LIFO, or maybe some keyboard shortcut / chording for toggling modes while the user is pasting.

I had actually tried to implement this as a hobby project but truthfully, my MVP was rudimentary at best because I’m inexperienced at COM+ and developing for the Windows Shell.

Edit: I’m using ‘Stack/Queue’ loosely, not in the rigid data structure term of art way.

Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @10:58AM (#29810562)
Thanks for sharing! As I understood, I think many clipboard managers already allow this, or at least, CopyQ and Ditto do. The approach is to just copy all the items you need, and then press "Win+V 5" five times. 5 would paste the fifth item in the history, but every time you did that, it is pulled to the top of the list, putting the next item in that spot.

Would this work, or is there more to it?

Re:The weight of the clipboard by BuyMyBitcoins on Wednesday January 05, 2022 @02:24PM (#29813635)
Thank you for sharing as well, I’ll have to give those two programs a try because they seem to be doing what I was hoping for. Best of luck on your project!
Re:The weight of the clipboard by layer8 on Wednesday January 05, 2022 @12:03PM (#29811592)
One clipboard feature/mode I’d like to have is "append to current clipboard content" (for text). I.e. like `>>` vs. `>` in the shell. Not multiple clipboard entries, just a single one that is textually appended to.
Re:The weight of the clipboard by PeterisP on Wednesday January 05, 2022 @11:29AM (#29811057)
> rich text (e.g. HTML) should be supported.

While there definitely are good use cases where rich text clipboard should be supported, for me personally a major use case requires eliminating rich text - where I'm frequently pasting some data from some web system into e.g. a word document and I want to explicitly paste just the text, because it really does not matter what styling the web page used for some ID. Word's "Paste Special"->"Unformatted text" is horribly inconvenient, so currently I just paste it in my text editor and re-copy it, ensuring that only the text remains in the clipboard.

Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @11:40AM (#29811235)
I don't have Microsoft Word, but most applications allow pasting just text using the shortcut Ctrl+Shift+V.

Edit: I see Microsoft Word doesn't natively have that shortcut, but there are two ways to "implement" it here: https://superuser.com/questions/988527/how-can-i-use-ctrl-sh...

Removing rich text formats is a good idea for a clipboard manager feature/plugin, though.

Re:The weight of the clipboard by layer8 on Wednesday January 05, 2022 @11:59AM (#29811529)
Re:The weight of the clipboard by TuringTest on Wednesday January 05, 2022 @12:56PM (#29812451)
Or configure CopyQ with a "Paste clipboard as plain text" action.

I used to use PureText for this, but this morning I discovered CopyQ and now I'm enjoying its enhanced clipboard capabilities, including that feature.

Re:The weight of the clipboard by myself248 on Wednesday January 05, 2022 @11:19AM (#29810918)
I have always wanted a "clipboard firewall", such that apps on List A can never copy and paste between apps on List B. Basically two separate clipboards.

If I want to move things between them, I should open the clipboard manager and manually move an individual item, or bridge the two clipboards for a specified time, after which they go back to being isolated.

Is that sensible/practical?

Re:The weight of the clipboard by hateful on Wednesday January 05, 2022 @02:24PM (#29813646)
I wonder if it could be done with AutoHotKey. Perhaps having a global script variable for each List. AutoHotKey already supports interacting with the clipboard and targeting different Apps/Windows based on a number of criteria (class, title, exe, pid). So when you hit Ctrl+c or Ctrl+v you would hit logic to direct the clipboard contents to one of your list variables, then when you hit Ctrl+v it would do a similar check. You could even map a different key for a "global" clipboard (e.g. Ctrl+Shift+v or the rightCtrl+v).

All of my AutoHotKey triggers are off of the right control since I noticed a long time ago that I never use it regularly. In the old days (~2004) I would use it to write HTML. Hitting right Control+a for example would surround the text with an <a> and have logic for @ or http: etc - or hitting right Control+l would surround a list of items with <ol><li>. These days I have very few macros, the most useful one being code that will "type" what's on my clipboard rather than paste it which is useful for places that don't allow pasting.

>^v:: SendRaw %clipboard% Return

Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @11:36AM (#29811181)
From a security perspective, I don't think it's possible to do with the standard OS APIs.

When an application makes data available in the clipboard, it's a free-for-all for every other application. The clipboard manager would have to race other applications to make a copy of the data, and then empty the OS clipboard.

APIs also may not allow making decisions based on which application requested the clipboard. It's possible to do in X11, but not Windows.

This goal could be achievable by intercepting the OS clipboard API. On X11, this can be done by MITM-ing the connection to the X server - https://github.com/CyberShadow/hax11 does this, and already has one clipboard-related security feature (disabling the selection mechanism). On Windows, the best bet is probably global DLL injection and API hooks, but applications can "opt out" by running as a different user or requesting a higher integrity level.

Re:The weight of the clipboard by JKCalhoun on Wednesday January 05, 2022 @10:34AM (#29810217)
A bit orthogonal, but here's my suggestion:

In addition to: cut | copy | paste

Add: swap

It swaps the current selection with the contents of the clipboard (replacing the clipboard with the selection, replacing the section with the prior contents of the clipboard — a swap).

It's a nerdy ask, if anything adds more complexity to the clipboard concept. But I have found myself having a need for this shortcut often.

Maybe others have as well.

Re:The weight of the clipboard by Tyr42 on Wednesday January 05, 2022 @11:06AM (#29810692)
In vim that's what happens if you select some text, then paste. Honestly I sometimes want to turn this off, as I want to paste the same thing multiple times, and I resort to putting the fragment to paste into a named register.
Re:The weight of the clipboard by TheSalarian on Wednesday January 05, 2022 @11:16AM (#29810849)
For what it's worth, I know I'd certainly use it.
Re:The weight of the clipboard by hu3 on Wednesday January 05, 2022 @03:41PM (#29814624)
SQLite seems like a great choice of storage since it fills these requirements:

- The system should be able to efficiently store, manipulate, and search an unlimited number of clipboard entries with reasonable performance.

- All functionality should continue to be available when offline (other than sync).

- The software should be cross-platform, and should have implementations for major desktop platforms (Windows, X11, Wayland, macOS).

- It should be safe and easy to simply copy the database file to another host, "pre-seeding" the clipboard history.

- It should be easy to write interoperable implementations of bridges/clients in most programming languages.

- Non-GUI functionality should be separated (or separatable) from GUI functionality, so that a GUI toolkit doesn't need to be loaded at all times.

But I'm not sure how to do this in SQLite as it probably does not fill deleted records with zero bits (but you could do that in your application):

- Deleted clips must not be trivially recoverable.

Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @03:42PM (#29814635)
Yes, I'm already using SQLite! It's great. Ditto uses it too.

To make SQLite zero-out deleted pages, issue "PRAGMA secure_delete = on".

Re:The weight of the clipboard by arantius on Wednesday January 05, 2022 @01:36PM (#29813053)
Fast/fuzzy search for pasting.

The clipboard manager I used on Windows, which only works there and hasn't been supported for a while, allowed a "Win+V, type, enter" workflow to very easily search for whatever I "type"d as a substring, and paste that entry. No interacting with menus, no up/down presses, no mouse. I miss that feature.

Re:The weight of the clipboard by still_grokking on Wednesday January 05, 2022 @10:16AM (#29809959)
Sounds like a sync plugin for CopyQ.

https://hluk.github.io/CopyQ/

If I would guess, I would assume there is already one somewhere.

If there isn't maybe just using Syncthing would be enough?

https://syncthing.net/

Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @10:59AM (#29810573)
I'm using CopyQ (and SyncThing) right now. Its design limits the number of entries, and sync doesn't work very well.
Re:The weight of the clipboard by still_grokking on Wednesday January 05, 2022 @05:44PM (#29816212)
I hope you're going to build only a sync plugin like suggested and not a whole clipboard manager.

Nobody needs yet another clipboard manager as there is almost a perfect one out there. Which can be extended by plugins! (I don't think it's a valid approach to start a new project because some project doing most of the wanted stuff isn't "perfect". The result is almost always "yet another 80% solution").

The "limited" number of entries is not an issue, imho. You can set it to x-thousand entries if you like. (One thousand entries are enough for more than two weeks of history for me. A clipboard is not a means of permanent data storage at all so this is fine; even one can have something akin to permanent entries by just using tabs in CopyQ).

Implementing in CopyQ some of the suggestions mentioned here would be great though!

Re:The weight of the clipboard by CyberShadow on Wednesday January 05, 2022 @06:40PM (#29816892)
I don't think a sync plugin would work. Entire parts of CopyQ's architecture would need to be redesigned, which would affect the rest of its ecosystem.

You can read the issue I filed in CopyQ's repository back when I switched to Linux and had to stop using Ditto for the justifications of infinite history: https://github.com/hluk/CopyQ/issues/510

CopyQ is also bound to use Qt's clipboard implementation, which provides the common subset of Qt's supported platforms, with all the consequent limitations. See the other issues I filed for details.

Re:The weight of the clipboard by enriquto on Wednesday January 05, 2022 @12:59PM (#29812513)
> Any suggestions?

Ability for keyboard-free editing, as in classical X: select to copy, click to paste.

Re:The weight of the clipboard by sholladay on Wednesday January 05, 2022 @09:42AM (#29809512)
The Paste app satisfies most of these requirements, though it’s Mac only for now. It is easily one of my favorite apps on any device.

https://pasteapp.io/

Re:The weight of the clipboard by jtsiskin on Wednesday January 05, 2022 @09:52AM (#29809646)
Your desired syncing behavior sounds like couchDB
Re:The weight of the clipboard by slickdork on Wednesday January 05, 2022 @03:50PM (#29814735)
This is something I would love, but also wouldn't use unless it had end to end encryption.
Re:The weight of the clipboard by dirtyid on Thursday January 06, 2022 @07:20AM (#29822643)
hot keys for different clip boards

clip boards for different apps

regex to process entries