GithubHelp home page GithubHelp logo

wl-clip-persist's Introduction

wl-clip-persist

Normally, when you copy something on Wayland and then close the application you copied from, the copied data (e.g. text) disappears and you cannot paste it anymore. If you run wl-clip-persist in the background, however, the copied data persists.

How it works

Whenever you copy something, it reads all the clipboard data into memory and then overwrites the clipboard with the data from our memory. By doing so, the data is available even after the program you copied from exits.

Usage

Clipboard Type

When you specify the clipboard to operate on, the clipboard data there will persist. The clipboards we don’t operate on will continue to behave like before.

Regular clipboard

wl-clip-persist --clipboard regular

Primary clipboard

wl-clip-persist --clipboard primary

Regular and Primary clipboard

wl-clip-persist --clipboard both

Note

The general recommendation is to operate on the regular clipboard only, since the primary clipboard seems to have unintended side effects for some applications, see here.

Optional arguments

Write timeout

Default: 3000 ms

It is possible to change the write timeout. In this example, the write timeout is reduced to 1000 ms.

wl-clip-persist --clipboard regular --write-timeout 1000

If the data size exceeds the pipe buffer capacity, we will have to wait for the receiving client to read some of the content to write the rest to it. To avoid keeping old clipboard data around for too long, there is a timeout which is also useful to limit the memory usage.

Ignore event on error

Default: disabled

With --ignore-event-on-error only selection events where no error occurred are handled. If an error occurred and the selection event is ignored, you will still be able to paste the clipboard, but only for as long as the program you copied from is open.

When this option is disabled, it will try to read the entire data for as many MIME types as possible. For example, when a clipboard event offers image/png and text/plain data and we are only able to read the text/plain data entirely because a read error occurred for image/png, then the clipboard will be overwritten with our data that only offers text/plain.

Filter

Default: no filter

With --all-mime-type-regex <REGEX> only selection events where all offered MIME types have a match for the regex are handled. You might want to use this option to ignore selection events that offer for example images. If the event is ignored, you will still be able to paste the images, but only for as long as the program you copied them from is open.

Ignore events that offer images

wl-clip-persist --clipboard regular --all-mime-type-regex '(?i)^(?!image/).+'

Ignore most events that offer something else than text

wl-clip-persist --clipboard regular --all-mime-type-regex '(?i)^(?!(?:image|audio|video|font|model)/).+'

Selection size limit

Default: no limit

With --selection-size-limit <BYTES> only selection events whose total data size does not exceed the size limit are handled. If the size limit has been exceeded, you will still be able to paste the clipboard, but only for as long as the program you copied from is open.

Ignore events that exceed the size of 1 MiB

wl-clip-persist --clipboard regular --selection-size-limit 1048576

This option can be used to limit the memory usage.

Reconnect tries

Default: no limit

With --reconnect-tries, the number of tries to reconnect to the Wayland server after a Wayland error occurred will be limited.

This option only applies if a Wayland error occurred after at least one successful connection to the Wayland server has been established. If the first connection to the Wayland server on startup fails, the application will exit with exit code 1.

Reconnect delay

Default: 100 ms

With --reconnect-delay, the delay between reconnect tries to the Wayland server is adjusted.

After a Wayland error occurred, a reconnect will be tried immediately. If the reconnect failed, the delay is applied before another reconnect is tried.

Disable timestamps

Default: not disabled

With --disable-timestamps, the timestamps in the log messages are disabled. This might be useful for systemd services or similar, which provide their own timestamps.

Logging

You can modify the log level to see more of what is going on, e.g.

RUST_LOG=trace wl-clip-persist --clipboard regular

Troubleshooting

Primary selection mode breaks the selection system (#3)

especially those based on GTK, e.g. Thunar and Inkscape

[...] once you start using the primary mode or both, it becomes impossible to select text, because once you release the cursor to finalize the selection, it disappears.

Solution: Use the regular clipboard only, e.g.

wl-clip-persist --clipboard regular

Inkscape crashes when copy-pasting anything (#7)

Solution:

wl-clip-persist --clipboard regular --all-mime-type-regex '(?i)^(?!image/x-inkscape-svg).+'

FAQ

Is it possible to have a clipboard history?

It is perfectly possible to use a clipboard history application alongside wl-clip-persist. For example cliphist will work.

Is it possible to ignore clipboard events from password managers?

Depends. If the password manager advertises the selection event with the additional MIME type x-kde-passwordManagerHint, like for example KeePassXC does, then we can ignore the selection event via:

wl-clip-persist --clipboard regular --all-mime-type-regex '^(?!x-kde-passwordManagerHint).+'

Build from source

  • Install rustup to get the rust compiler installed on your system. Install rustup
  • Rust version 1.76.0 or later is required
  • Build in release mode: cargo build --release
  • The resulting executable can be found at target/release/wl-clip-persist

Thanks

wl-clip-persist's People

Contributors

linus789 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

wl-clip-persist's Issues

Screenshot lacks bottom part when wl-clip-persist launched.

Linux arch 6.8.7-arch1-1.
Hyprland.
Hyprshot or grim for screenshots, same issue for both.
On system start I run wl-clip-persist --clipboard regular

wl-clip-persist cuts out bottom of the screenshot.
Sometimes it's around half, sometimes it's almost all image.
If screenshot is taken and wl-clip-persist is not running it's ok.
Once wl-clip-persist kicks in, this screenshot cuts out.
As a workaround I kill _wl-clip-persist for several seconds bind = , Print, exec, pkill wl-clip-persist && hyprshot -m region -d --clipboard-only && sleep 6 && wl-clip-persist --clipboard regular <- that is bad so I restricted data size for which it will work, so now I run wl-clip-persist --clipboard regular -l 4096 on system start, it's enough for any text I may copy but less than any image I'll copy.

Without wl-clip-persist:
image

With wl-clip-persist:
image

Any ideas where to dig, maybe I need to provide some additional info?
Or maybe it's not wl-clip-persist issue?

The primary selection mode breaks the selection system.

The primary selection mode breaks the selection system.

The primary and both selection systems (perhaps because it involves the primary) break the selection system and make it very uncomfortable to select text in some applications, especially those based on GTK, e.g. Thunar and Inkscape, other applications such as Chrome are not affected.

Perhaps a video will illustrate the situation better:

Kooha-2023-05-26-22-02-40.mp4

As you can see in the video, without running the program, the selection system works normally, just as if you run the program using the regular option.

But once you start using the primary mode or both, it becomes impossible to select text, because once you release the cursor to finalize the selection, it disappears.


I am not an English speaker, this was translated using a program on the Internet, I apologize for any inaccuracies.

Hooking in to the primary clipboard deselects all Ctrl-A + complete desktop freezes

wl-clip persist -c regular works fine. With -c primary or -c both, the following abnormalities happen:

Dupe of #3 ### Ctrl-A Selecting text (most commonly with Ctrl-A) in dialogues is consistently buggy. Anything selected is instantly deselected.

Examples: Thunar (rename), GIMP (Ctrl-N pixels).
Possibly related: #6

Complete desktop freezes

Using Sway (1.9-3) on Arch Linux. A well-reproducible example with GIMP (2.10.38-1):

  1. Ctrl-N: Create a new document
  2. Ctrl-S: Attempt to open the dialogue to Save (As). If it doesn't crash on first time, try again. I can reproduce in 1-3 times looping Ctrl-S Esc.
  3. Sway / the system is frozen. Time stops ticking. Switching TTY with Ctrl-Alt-F4 doesn't work. Power/Sleep inputs are ignored. Have to force shut-down.

If desired, I can reproduce and collect logs with SSH.

Any drop-downs from the top (File, Edit, Select) don't open, open very slowly, or cause the same freeze.

clipboard still run at wayland compositor exit

Exit wayland compositor(like hyprland), my tty show me and keep repeating the same error

2024-07-17T01:54:07.539 ERROR main > Wayland connect error: Connection reset by peer (os error 104)
  Attempt to reconnect in 100 ms...
2024-07-17T01:54:07.640 ERROR main > Wayland connect error: No such file or directory (os error 2)
  Attempt to reconnect in 100 ms...

Maybe the program should be stoped when exiting the compositor?

Full copy from chrome's adreess bar doesn't work

When I type something in an address bar and then press ctrl-a (or manually select everything) + ctrl-c, it doesn't copy anything. If I select just part of a line and hit ctrl-c it works. It also works if I select the entire line and copy it by right clicking + selecting Copy button (not always). Everything works fine without wl-clip-persist.

As I said, the problem persists only if I select the entire line and then copy with ctrl-c. It's probably something to do with chrome as it works fine with firefox. In general it works good with chrome too, but only full adress bar copying with ctrl-c doesn't work.

Logs (see last line) RUST_LOG=trace wl-clip-persist --clipboard regular:

[2023-08-31T12:10:45.687Z TRACE wl-clip-persist Seat 4] Initialized seat
[2023-08-31T12:10:47.259Z TRACE wl-clip-persist Seat 4] Handle new regular clipboard selection event
[2023-08-31T12:10:47.259Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: UTF8_STRING
[2023-08-31T12:10:47.259Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: text/plain;charset=utf-8
[2023-08-31T12:10:47.259Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: TEXT
[2023-08-31T12:10:47.259Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: STRING
[2023-08-31T12:10:47.259Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: text/plain
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Created regular clipboard data source 6
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Handle new regular clipboard selection event
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: TEXT
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: STRING
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: text/plain;charset=utf-8
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: UTF8_STRING
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Current selection event offers mime type: text/plain
[2023-08-31T12:10:47.261Z TRACE wl-clip-persist Seat 4] Regular clipboard got a new selection event, so ignore the old one

Info

wl-clip-persist 0.3.1
Browser: Google Chrome 116.0.5845.96 (Preferred Ozone platform = Wayland)
WM: Hyprland, built from branch at commit 91e28bbe9df85e2e94fbcc0137106362aea14ab5
OS: Nixos-unstable

Can't Copy Nerd Font Icons/Glyphs

I'm not 100% sure on the right verbiage to refer to these little icons that are available in nerd patched fonts and/or font awesome. But, whenever I have wl-clip-persist running, I cannot copy those items. They just won't copy at all. Closing wl-clip-persist and they are immediately copyable. However, then, they obviously don't persist closing the window I copied from.

Here are some icons that I mean:


󰤨
󰝟

I don't even known how to make them show up here. As I type them I just get tiny boxes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.