wl-clip-persist

Linus789MIT长期未更新

让 Wayland 下的剪贴板内容在复制它的程序关闭后依然保留,解决 Wayland 会话中关闭应用就丢失剪贴板的问题。

Keep Wayland clipboard even after programs close

v0.5.0发布于 2025-09-23 15:46 UTC271star13fork同步于 2026-11-07 07:33 UTC

怎么上手

由 README 提炼,执行前请确认
cargo build --release
wl-clip-persist --clipboard regular
硬件要求按 README 说明

README 未说明;需运行在支持 ext-data-control-v1 或 wlr-data-control-unstable-v1 协议的 Wayland 合成器上

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

在 Wayland 下让剪贴板内容在源程序关闭后依然可粘贴的后台小工具

让 Wayland 下的剪贴板内容在复制它的程序关闭后依然保留,解决 Wayland 会话中关闭应用就丢失剪贴板的问题。

核心能力

  • 复制时把剪贴板数据读入内存并重新写回剪贴板
  • 支持 regular、primary 或两者同时持久化
  • 可用正则按 MIME 类型过滤要处理的复制事件
  • 支持设置写入超时与选区大小上限以控制内存
  • Wayland 出错后可配置重连次数与延迟

容易踩的坑

需自行从源码构建,要求 Rust 1.85.0 或以上;合成器必须支持指定 Wayland 协议之一,否则无法工作;primary 模式可能破坏部分 GTK 应用的选区,建议只用 regular;开启 RUST_LOG=trace 会打印剪贴板前约 30 字节内容,提交日志前注意脱敏

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.5.0
  1. v0.5.0最新正式版2025-09-23 · 2025-09-23 15:46 UTC

    Added

    • Support for the ext-data-control-v1 protocol
    • Outdated clipboard data is now zeroized once it is not needed anymore
    • Graceful shutdown

    Changed

    • Default reconnect tries is now: 0 (#12)
    • More and better log messages

    Workarounds

    • Added workaround for issue #17 (we now ignore the SAVE_TARGETS mime type)
    • Added workaround for issue #22 (we now request mime types in a specific order)

    Building

    • New MSRV is: 1.85.0
  2. v0.4.32024-05-02 · 2024-05-02 23:41 UTC
    查看更新说明

    Do not offer mime types for which we do not have the data

  3. v0.4.22024-05-02 · 2024-05-02 22:10 UTC
    查看更新说明

    Fix mime type offer order not being preserved (#9)

  4. v0.4.12024-04-29 · 2024-04-29 15:15 UTC
    查看更新说明

    Fix writing large amounts of data (#10)

  5. v0.4.02024-04-15 · 2024-04-15 21:05 UTC
    查看更新说明

    Async rework.

    • Option --read-timeout is not needed anymore
    • Option --interrupt-old-clipboard-requests has been removed

    For building:

    • New MSRV is: 1.76.0
    • Compile-time and runtime dependencies are not needed anymore

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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.

    Wayland compositor requirements

    Your compositor has to support at least one of these Wayland protocols:

    • ext-data-control-v1
    • wlr-data-control-unstable-v1

    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: 0

    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
    

    Please be aware that this will show the first ~30 bytes of your text clipboard contents whenever you copy something. So, when you create an issue with the full log, either do not copy sensitive data to your clipboard or censor it.

    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.85.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