Skip to content

fix(wayland): copied text not paste-able in some programs#2612

Draft
bew wants to merge 3 commits into
espanso:devfrom
bew:fix-wezterm-wayland-paste
Draft

fix(wayland): copied text not paste-able in some programs#2612
bew wants to merge 3 commits into
espanso:devfrom
bew:fix-wezterm-wayland-paste

Conversation

@bew

@bew bew commented Jan 1, 2026

Copy link
Copy Markdown
Contributor

Hello!

(note: this was fully Human-made, zero AI involved)

Note

Edit: Skimming GH issues mentioning Wayland, I think this PR could fix the following issues:
#2428 #2162 #2270 #2497 #2582 #1670 #2340 #901 #1367
(maybe more, to be confirmed)

Context

Since I had to switch to Wayland a few months ago, I've always had trouble with Espanso and attributed it to some weirdness around Wayland, protocol instabilities, KDE Plasma6.. (and the missing capability on NixOS)

For example some expansions would work in Firefox but not all, and almost no expansions would work in Wezterm (the trigger is removed but the replacement is not pasted).
Other times it would simply paste the wrong clipboard data, as if Espanso didn't set the clipboard at all.
And when I had something like foo in my clipboard, tried an expansion that failed, I couldn't paste the original foo that was supposed to be restored by Espanso after the expansion.

Since latest NixOS 25.11 release, the capability issue was fully resolved and I was still having these weird issues..
The first day of 2026 motivated me to dive in and actually fix this! 😀

Findings

With WAYLAND_DEBUG=1 and some additional debug logs I've found that the MIME type of the copied text is set correctly then immediately overwritten to a bad type:

...
[ 442709.543] {Default Queue}  -> wl_data_device_manager#7.get_data_device(new id wl_data_device#3, wl_seat#6)
[ 442741.732] {Default Queue}  -> wl_data_device_manager#7.create_data_source(new id wl_data_source#11)
...

!! NOTE: The clipboard is set here
[ 442747.844] {Default Queue}  -> wl_data_device#3.set_selection(wl_data_source#11, 35716)

!! NOTE: The data type is set correctly here (`offer` line)
[ 442747.880] {Default Queue} wl_data_device#3.data_offer(new id wl_data_offer#4278190080)
[ 442747.891] {Default Queue} wl_data_offer#4278190080.offer("text/plain;charset=utf-8")   // <- here
[ 442747.900] {Default Queue} wl_data_device#3.selection(wl_data_offer#4278190080)
...

!! BAD: The data type is ~immediately overwritten to a bad type
[ 442748.373] {Default Queue} wl_data_device#3.data_offer(new id wl_data_offer#4278190081)
[ 442748.383] {Default Queue} wl_data_offer#4278190081.offer("l�4��U")   // <- here
[ 442748.390] {Default Queue} wl_data_device#3.selection(wl_data_offer#4278190081)
...

And this weird MIME type was also used when restoring the original clipboard content, easy to validate with wl-paste --list-types.

In Wezterm, I've found that only selection with MIME type text/plain;charset=utf-8 can be pasted, so the weird l�4��U type doesn't cut it and nothing can be pasted after Espanso changed the clipboard.

It probably worked better in Firefox because the browser have a lot more flexibility on the kind of data that can be pasted, potentially doing its own detection.

The fix

I'm not exactly sure why the MIME type was immediately overwritten after being correct for less than a second.
I tried to disable Klipper (KDE's clipboard manager) which might have caused this but I still had the same issue.
👉 Anyway, manually setting the MIME type fixes everything for me, and all my expansions work everywhere.

Thoughts

The clipboard restoration might need a better impl, to actually restore the original MIME type instead of forcing plain text. I'd prefer to do this in a separate PR though.

Also is there a reason the wl-clipboard crate isn't used, instead of calling wl-copy & wl-paste cli?
(using the cli is probably easier to do / think about 👀)

@bew bew requested a review from Archigos as a code owner January 1, 2026 19:36
@bew bew changed the title fix(wayland): text copy not paste-able in some programs fix(wayland): copied text not paste-able in some programs Jan 1, 2026
@bew bew force-pushed the fix-wezterm-wayland-paste branch from 0d89808 to 276038a Compare January 1, 2026 19:43
@bew

bew commented Jan 1, 2026

Copy link
Copy Markdown
Contributor Author

The build failures in CI are due to unused imports in files unrelated to this PR 👀

@bew bew force-pushed the fix-wezterm-wayland-paste branch from 276038a to 3743195 Compare June 20, 2026 08:50
@bew bew marked this pull request as draft June 20, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant