Skip to content

Instantly share code, notes, and snippets.

@KirillY
Last active June 13, 2022 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KirillY/bc4253edfd62b27c452d01595d19efce to your computer and use it in GitHub Desktop.
Save KirillY/bc4253edfd62b27c452d01595d19efce to your computer and use it in GitHub Desktop.
#vcxrv #teachmeskills #tms

1. Install and setup Windows X-server

1.1 Download and install
1.2 Autorun vcxsrv config.xlaunch

Put this into shell:startup folder (usually %AppData%\Microsoft\Windows\Start Menu\Programs\Startup\config.xlaunch);

<?xml version="1.0" encoding="UTF-8"?>
<XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="-1" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="-screen 0 1920x1080@1" Wgl="True" DisableAC="True" XDMCPTerminate="False"/>
  • reference superuser.com/questions/1372854/do-i-launch-the-app-xlaunch-for-every-login-to-use-gui-in-ubuntu-wsl-in-windows
1.3 Restart system or run config.xlaunch

2. Set DISPLAY variable inside WSL to <wsl_hostname_ip>:0 route Display remote location to host machine

2.1 Add to .bashrc or .zshrc - for WSL-based graphic applications
export DISPLAY=$(ip route  | awk '/default via / {print $3; exit}' 2>/dev/null):0 
export LIBGL_ALWAYS_INDIRECT=1
2.2a Set DISPLAY code of testing framework - for Windows-based Pycharm
import subprocess
import os

def _get_wsl_host_address() -> str:
    """
    :return: ip:port for wsl host
    """
    wsl_hostname_ip = subprocess.check_output("cat /etc/resolv.conf | grep nameserver | awk '{print $2}'", shell=True)
    return f"{wsl_hostname_ip.decode('utf-8').strip()}:0"

if get_is_inside_wsl() in ["True", "true"]:
    os.environ["DISPLAY"] = _get_wsl_host_address()
2.2b Set static IP for WSL adapter - for Windows-based Pycharm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment