This seems like a reasonable use case:
- Visual Studio Code on a Windows 11 computer
- Remote-SSH to an Ubuntu computer for development
- X11 Forwarding of interactive GUIs on the Ubuntu computer
Given that WSL includes an X11 server (WSLg) that does a great job of displaying GUIs from WSL, it seems reasonable to use this for remote X11 forwarding rather than install a 3rd party X11 server on the windows computer. However, I've been unable to get this to work.
First, to confirm X11 forwarding works with WSLg, I ssh from WSL to host xxx-ubuntu using "ssh -X yyy@xxx-ubuntu". I can run xeyes and they appear as expected, and I get:
$ echo $DISPLAY
localhost:10.0
On the Windows computer, the SSH config file is:
Host xxx-ubuntu
HostName xxx-ubuntu
User yyy
ForwardAgent yes
ForwardX11Trusted yes
ForwardX11 yes
In Visual Studio Code on the Windows computer, I installed the "Remote - SSH" extension by Microsoft.
I run the command, "Remote-SSH: Connect to Host..." and select "xxx-ubuntu". Visual Studio Code connects to xxx-ubuntu. I run xeyes and get the error:
$ xeyes
Error: Can't open display: localhost:10.0
If I install the Xming X server and try again with Visual Studio Code, it works as expected.
Why does this not work with WSLg?
It appears the only way to do this is to run VSCode from WSL. VSCode doesn't like this, but you just have to tell it to allow it, then any x11 forwarding will naturally be forwarded to WSLg.