wslg: Cannot copy text *into* Kate editor, copying text *from* Kate works fine.
Environment
Windows build number: Microsoft Windows NT 10.0.21257.0
Your Distribution version: Ubuntu 20.04 LTS
Your WSLG version: 0.2.9.0
Steps to reproduce
- Open kate
- Open notepad (for verification)
- Copy text in windows.
- Paste in notepad (for verification)
- try paste in kate -> no text pasted
- copy text inside kate
- Paste in notepad -> this direction works fine.
WSL logs:
- Attach WSLg logs from
/mnt/wslg
You can access the wslg logs using explorer at: \\wsl\<Distro-Name>\mnt\wslg
(eg: \\wsl\Ubuntu-20.04\mnt\wslg
)
puseaudio.log
weston.log
versions.txt
versions.txt is not copyable (missing permissions): WSLG ( x86_64 ): 0.2.9+Branch.master.Sha.d49cb28cbf4be209347e3b48315081c1b38e4465 wayland: 8cd7c836eaceccc0e4ada7bdac43d86bfe3e0a0a FreeRDP: 297cb96a30ed00e1d7cba1ae9035cfeff82dbfd6 weston: a17db71354ad1c453e10a15805d907c52425499c pulseaudio: 2f0f0b8c3872780f15e275fc12899f4564f01bd5 sharedguestalloc: e2895c6a49105caaa651c05d4b96a46e5a621538
Expected behavior
copy/past of text works both directions
Actual behavior
can only copy text from linux to windows, but not other way round
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 158 (66 by maintainers)
Problem
This workaround, gracefully provided by @cpbotha, works for the most part, but I discovered a bug. Specifically, with this in my
init.el
, emacs loses focuses whenever it is (1) fullscreen (runM-x toggle-frame-fullscreen
), and (2) makes a call towl-copy
. This is extremely annoying.One possible cause might be the following known “bug” of
wl-copy
(fromman wl-clipboard
):The question, then, is if the wlroots data-control protocol is properly implemented. If it isn’t,
wl-copy
might be spawning an invisible window, which would explain my focus-related problems.Workaround
As a workaround for the previous workaround, I came up with the following. This solution uses the win32yank utility, a program which is written in rust, and is popular among those who use neovim on WSL. It handles unicode characters, a feature absent from the Windows-native
clip.exe
program, and it runs significantly faster than solutions centered onpowershell.exe Set-Clipboard -Value <String>
.choco
works pretty well:init.el
:Note that binaries installed through
choco
may not be in yourPATH
on WSL. On my end, anything installed throughchoco
has always been available from WSL by default.I gave it a shot this weekend, but I was not able to port the
!QCLIPBOARD
rejection on the substantially modifiedpgtkselect.c
.In the meantime, I’m using this bit of code in my init to work around the issue:
It calls out to the
wl-copy
CLI utility, but it does work.As someone who uses and develops on all three desktop platforms, I find the WSL2 implementation exceptionally useful.
WSLG has made and is still making enough progress so that my daily workflow, which involves a whole lot of Emacs pgtk running on WSL talking to the WSLG wayland compositor, is the smoothest it’s ever been.
Granted, I too am waiting for example for the window management to catch up (specifically Windows snapping for WSLG apps), but this requires changes to RDP which are being worked on as we speak, see https://github.com/microsoft/wslg/issues/727#issuecomment-1125569508 for in-progress screenshots. The performance and robustness of the WSLG connection justifies its use over my old X11 setups (I used to use X410, and sometimes also mobaXterm for this).
My clipboard issues have been fully resolved, thanks to @hideyukn88 (MS) working with @masm11 (an Emacs developer) to figure out and work around an unexpected inconsistency in clipboard handling between wayland, Emacs, and gtk (see #649).
To conclude: Thank you to everyone who has contributed to WSL and WSLG, your software adds value (and fun) to my workflow!
I use PHPStorm (IntelliJ IDEA variant) started from Linux and copy from various apps like Notepad, Notepad++, Edge, etc.
The only app from which copy-pasting works the Terminal app. Anything that resembles utf-8 contents seems not working.
I’ve also installed Firefox on Linux and tried to paste data from Windows, and all works flawlessly; only JetBrains IDE seems to fail.
I was surprised to learn some months back that Po Lu, who contributed massively to pgtk support in Emacs, recommends quite strongly against using it if you have the option of using plain old X. See this email (and its surrounding discussion) on the mailing list: https://lists.gnu.org/archive/html/emacs-devel/2022-04/msg01005.html
Mostly because of that, but also a little bit due to this bug and its work-around, I moved back to X11 Emacs on WSLg and have been enjoying a much smoother ride because of it.
also hitting this problem.
When copy from Chrome, to my editor on WSLg editor, it will paste correctly. However, once I copy-paste something at my editor, then copy some other content from Chrome to WSLg editor, it will still paste the previous content copied from my WSLg editor.
Started hitting this again. Re-enabled more verbose debugging to try to trap the case.
For windows PGTK users:
Try this patch. You should be able to copy from PGTK emacs with it.
win32.diff.gz
Ever since I started encountering this problem, I have made it a habit to
tail -f weston.log
in the hopes the problem would recur. Finally, it did. Here is the relevant outputThis is the line that looks unique:
[16:14:59.673] write error to target fd: Bad file descriptor
This timestamp seems to coincide with the recurrence of the problem of losing the ability to paste into Emacs.
@eliezedeck and all others, thank you very much for trying out patiently. Currently, as we understand, this is caused by Windows is failing to respond with clipboard data after WSLg requested (even though there seems no fault at WSLg side), and we don’t know yet why Windows is failing, but one issues with WSLg is, once it entered failed state, it remains failed state forever. We are experimenting some re-try logic to request data again or reset, once this is confirmed it does help, we will update here, thanks for trying out WSLg and helping us!
I have just also tested this with a Wayland app that does NOT go through XWayland, e.g. gedit on Ubuntu 20.04. (I first tested with a build of the pgtk - nativecomp branch of Emacs in https://github.com/flatwhatson/emacs but rather chose gedit 3.36.2 as a more easily reproducible case)
I can copy text in gedit and paste in a Windows app. I can NOT copy in a Windows app and then paste into gedit (nothing gets pasted).
Perhaps more interestingly, even
wl-paste -t text
outputs nothing, so somehow the copy from the windows app (Edge in my case) is not correctly transferred to wayland. When I copy something from a Wayland app (gedit),wl-paste -t
does output that exact copied text. @hideyukn88 Maybe this stripped-downwl-paste
example can reproduce on your side?This is the relevant error message in
weston.log
(both for gedit and wl-paste):P.S. I just shutdown wsl and started over. I could paste successfully twice from Edge to gedit on wayland, and the third time stopped working.
Here is the log from just after startup:
P.P.S. I repeated the experiment, copying from Edge and then running
wl-paste -t text
in Windows terminal. Works the first two times, and then stops working the third. I copied the first paragraph of this comment (try 1), then the third paragraph starting with “perhaps” (try 2), and then the paragraph starting with “P.S.” (try 3, did NOT work).Log from just after startup:
P.P.P.S. I continued with these experiments. When docker for desktop is running with its WSL2 backend, my copy paste breaks quite soon. Without docker for desktop, and hence no additional WSL2 instances but my main instance, copy paste continues working for many more tries.
Is it possible that the additional WSLg system distro instances that are started for each running WSL instance could be interfering with each other?
@gf9276, copy between Windows and Linux Wayland native application should work regardless of size, but there is issue from upstream branch which causes the problem between Wayland and X11 application, thus this impacts the copy between Windows and X11 since this goes through Windows to Wayland to X11, which is tracked by https://github.com/microsoft/wslg/issues/743, thanks!
Having the same issue with https://github.com/microsoft/wslg/issues/15#issuecomment-1560851310 like copying about 5k lines of codes will crash the copy/paste system of wslg It will not work anymore until a reboot…
Any help?
@hideyukn88
Hello, I have successfully reproduced this issue. When I copy a large amount of text from Windows 10 to Google Chrome in wslg, it triggers a copy failure and after that, I cannot copy anything from Windows 10 to wslg’s application (I have only tried Google Chrome and IDEA for now).
I’ve switched to the MS Store version of WSL and it still doesn’t solve the problem for me. That’s what I got now:
Funny enough, this update fixed another problem - now at least Emacs’s icon is properly displayed in the start menu and in the task bar. 😃
@sandric. please update WSL from Store app, https://www.microsoft.com/en-us/p/windows-subsystem-for-linux-preview/9p9tqf7mrm4r?activetab=pivot:overviewtab, thanks!
@edburns Hi, I just tested this setting and it seems to do nothing for my setup for some reason, the issue still occurs. I tried to check my wsl version, and somehow I don’t have
version
on mine, just status, which is strange since I’m on nightly windows 11 build and ranwsl --update
just now, and I should have wslg because I have graphical emacs without any x server setup. Here’s the status output:@bbatsov please also see my gist – it sets
interprogram-cut-function
to use wl-copy (but you could just as well doclip.exe
) whenever you kill anything, as Emacs normally would do.I’ve been using this workaround to get Emacs to copy stuff to Window’s clipboard:
Basically we just shell out to
clip.exe
on the WSL side, which works reliably, but we have to make sure we quotetext
properly. I’ve actually pasted this from Emacs using it. 😄I would be very interested in getting access to that pre-release build @edburns and @hideyukn88 😃
I can’t run the store-version of wsl, because of issues with Windows interop breaking ( https://github.com/microsoft/WSL/issues/7754 ) and not being able to SSH into store-version of WSL ( https://github.com/PowerShell/Win32-OpenSSH/issues/1632 ), so this means I’m dependent on the “system” versions that get published here on the github, unless someone knows of a better solution.
In short: I woud be grateful for updated WSL packages that can be downloaded from here (or elsewhere), and not from the MS store.
People might also be interested in my Emacs work-around for the current clipboard issues, it uses wl-copy and gets copy-pasting mostly working in and out of latest master pgtk Emacs on WSL Wayland: https://gist.github.com/cpbotha/fdd2c5ab3d22a33679c546323ea3bc0b
@hideyukn88 after a few tests, here is the relevant log:
Step 1
Here, I’m in Emacs (WSLg) and copy a text selection from the buffer.
Step 2
Here, I switched back to Firefox (Windows) and copy some text from a webpage.
Step 3
After this, I switch back to Emacs (WSLg) and use its “yank” command (pasting). This doesn’t produce any log in the weston.log and it is pasting the text I copied from Emacs at step 1 and not the one from Firefox.
Step 4
Here I use the keyboard shortcut associated to the taskbar entry (Emacs is in second position so Win+2) to send the window to the backend and then to the foreground again.
Step 5
Here I use the yank (paste) command again and it copies the text from Firefox as expected.
Hope this helps.
I’m having a similar issue - in weston.log I see the following message:
Then trying to paste:
And I found a way to repro:
@Hoffs, thanks, yes, we addressed that particular issue in WSLg 1.0.23, thanks!
It works for me initially (freshly started) or after reboot, then after a while (multiple computer Sleep, various apps used in the mean-time and one
wsl --shutdown
to save memory) it stopped working.UPDATE
As a work-around until a fix, may be a way to restart some service / process or anything in WSL to reset the clipboard feature.