fix(wayland): copied text not paste-able in some programs#2612
Draft
bew wants to merge 3 commits into
Draft
Conversation
0d89808 to
276038a
Compare
Contributor
Author
|
The build failures in CI are due to unused imports in files unrelated to this PR 👀 |
276038a to
3743195
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
fooin my clipboard, tried an expansion that failed, I couldn't paste the originalfoothat 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=1and 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: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-8can be pasted, so the weirdl�4��Utype 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-clipboardcrate isn't used, instead of callingwl-copy&wl-pastecli?(using the cli is probably easier to do / think about 👀)