Skip to content

Instantly share code, notes, and snippets.

@jimathyp
Last active November 21, 2021 21:03
Show Gist options
  • Select an option

  • Save jimathyp/6cb7f2a03abd59130567329b5dff35f2 to your computer and use it in GitHub Desktop.

Select an option

Save jimathyp/6cb7f2a03abd59130567329b5dff35f2 to your computer and use it in GitHub Desktop.

XWindows Configuration for WSL

Windows 11 will have "WSLg"

https://github.com/microsoft/wslg WSLg is short for Windows Subsystem for Linux GUI and the purpose of the project is to enable support for running Linux GUI applications (X11 and Wayland) on Windows in a fully integrated desktop experience.

Setup and installation for running LInux GUI in Win 10

http://www.straightrunning.com/XmingNotes/IDH_FINISH.htm

WSL, install XLaunch

Requires "-ac" option when starting - can enter this at the "Additional parameters for VcXsrv" box on the "Extra Settings" page when starting X via the GUI.

Xlaunch options

-ac
disables host-based access control mechanisms. Enables access by any host, and permits any host to modify the access control list.
Use with extreme caution. This option exists primarily for running test suites remotely.
(from https://x.cygwin.com/docs/man1/Xserver.1.html)

-wgl Enable the GLX extension to use the native Windows WGL interface for hardware-accelerated OpenGL.

Or, add to the "Target" options in the XLaunch shortcut properties box (Windows). (that doesn't seem to work - Windows complains "... specified in the Target box is not valid. Make sure the path and file name are correct."

Also saving the configuration from that GUI screen creates a file (*.xlaunch), which needs to be associated with XLaunch when double clicked on.

Add to %AppData%\Microsoft\Windows\Start Menu\Programs\Startup

Or

xlaunch -run filename.xlaunch

(from https://sourceforge.net/p/vcxsrv/discussion/986201/thread/9f8dacce/)

https://superuser.com/questions/1372854/do-i-launch-the-app-xlaunch-for-every-login-to-use-gui-in-ubuntu-wsl-in-windows

The config file is just XML, eg.

<?xml version="1.0" encoding="UTF-8"?>
<XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="0" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="-ac" Wgl="True" DisableAC="True" XDMCPTerminate="False"/>

XWin man page https://x.cygwin.com/docs/man1/XWin.1.html XServer man page https://x.cygwin.com/docs/man1/Xserver.1.html

Running GUI apps in WSL

$ xcalc

Error: Can't open display:

First check DISPLAY env

$ echo $DISPLAY

You will need to get the IP address of the Windows host Couple ways. dig lookup for the hostname from WSL, or use Task Manager and check the Ethernet interface (or wifi).

hostname -f
hostname --fqdn
hostname --long

Likely need the full hostname with domain not short hostname. (other utils: dnsdomainname, domainname)

The /etc/hosts will have the hostname (and domain) but this was a 127.0.1.1 address.

If using DISPLAY 0

DISPLAY=$(dig $(hostname --fqdn) +short):0.0
export DISPLAY
export LIBGL_ALWAYS_INDIRECT=1

(Needs to be sourced - I have this in a separate file, not in bash_profile, due to having to work on different networks)

This checks if a script is being run or sourced:

if [ "$0" = "$BASH_SOURCE" ]; then
     echo "Error: Script must be sourced"
     exit 1
fi

Options

export LIBGL_ALWAYS_INDIRECT=1

Indirect rendering means that the GLX protocol will be used to transmit OpenGL commands and the X.org will do the real drawing.

Direct rendering means that application can access hardware directly without communication with X.org first via mesa.

The direct rendering is faster as it does not require change of context into X.org process.

Clarification: In both cases the rendering is done by GPU (or technically - may be done by GPU). However in indirect rendering the process looks like:

Program calls a command(s) Command(s) is/are sent to X.org by GLX protocol X.org calls hardware (i.e. GPU) to draw In direct rendering

Program calls a command(s) Command(s) is/are sent to GPU

https://en.wikipedia.org/wiki/Direct_Rendering_Infrastructure

from https://unix.stackexchange.com/questions/1437/what-does-libgl-always-indirect-1-actually-do

Summary

  1. In WSL export the DISPLAY variable which is the IP address of the Windows machine and the display number
  2. In Windows, start XLaunch, make sure the DISPLAY is the same as used in WSL, and use -ac option if required to allow clients to connect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment