Skip to content

How to: Let VcXsrv and X11 apps use Unix Domain Socket under Windows 10 (including WSL)

Martin Chloride edited this page Apr 22, 2019 · 2 revisions

Note: There is no proven advantages of utilizing Unix Domain Socket over TCP loopback for VcXsrv. Let me know if you have any.

Background

Under real Linux, a X server usually listens a Unix Domain Socket (AF_UNIX) at /tmp/.x11-unix/X# where # is the display number. However until the end of 2017, windows does not provide any Unix Domain Socket functionalities, so as the Windows port of X-Org Server: XWin, and its fork VcXsrv. The good news is: Windows 10 now supports Unix Domain Socket, and furthermore it can be used for inter-process communication even across Win32 and WSL. That means theoretically it is possible to run GUI applications even desktop environments in WSL displaying everything on VcXsrv, a Win32 application, communicating under Unix Domain Socket. You can now try it out by downloading the latest release from this repository.

Steps

Start X server in Win32

  1. Go to the release page.
  2. Download and install the latest release under C drive. Currently I did not compile for any platforms other than amd64. If you need them, please compile for yourself. PRs are welcomed.
  3. Run VcXsrv with the following arguments: -nolisten tcp -listen unix. For example: ./vcxsrv.exe :0 -multiwindow -nolisten tcp -listen unix.
  4. Right click on the X icon in the system tray and launch xcalc to test whether it works.

Start X client in WSL

  1. Remove /tmp/.X11-unix. Command: sudo rm -rf /tmp/.X11-unix.
  2. Create a symlink to /mnt/c/tmp/.X11-unix. Command: sudo ln -s /mnt/c/tmp/.X11-unix /tmp/X11-unix.
  3. Download the patch for libxcb. If you want to patch by yourself, check the commit.
  4. Install the patched libxcb to /usr/local/lib (or anywhere you like, as long as it can be linked). Command: sudo cp libxcb.so.1.1.0 /usr/local/lib/; sudo ln -s /usr/local/lib/libxcb.so.1.1.0 /usr/local/lib/libxcb.so.1; sudo ln -s /usr/local/lib/libxcb.so.1.1.0 /usr/local/lib/libxcb.so;.
  5. Refresh your ld cache. Command: sudo ldconfig.
  6. Run your X client with the following environment variable: DISPLAY=:0. Example: DISPLAY=:0 gnome-terminal.

Why it took so long to port to VcXsrv since Windows 10 supported Unix Domain Socket

Because writing a new application using Unix Domain Socket is trivial but porting an old one is not. The original code does not expect a Unix Domain Socket API under Win32. I need to revisit all these assumptions. On the other hand, the path of the Unix Domain Socket used by X11 applications is hard-coded, so I have to make sure the POSIX path works under Win32 as well. Lastly, since there are still some limitations of Unix Domain Socket across Win32 and WSL, I spent lots of time debugging and patching libxcb.