Skip to content

GUI

Some time ago, you would need to have a complicated, convoluted and unreliable setup for using GUI apps within WSL. Thankfully, we now have WSLg, which transforms this whole ordeal into a non-pain-in-the-butt experience.

If you use the “official” Distribution, i.e. Ubuntu, it should also work out of the box. As we use ArchWSL, we have to setup the correct symlinks though.

  1. The environment variables should already be automagically setup to the correct values at this point.

    Terminal window
    $env.WAYLAND_DISPLAY = 'wayland-0'
    $env.DISPLAY = ':0'
  2. Everything we need, should already be in /mnt/wslg, namely runtime-dir and .X11-unix

  3. Create a systemd service that setups the Wayland runtime directory

    /etc/systemd/user/wslg-runtime-dir.service
    [Service]
    Type=oneshot
    ExecStart=sh -c "ln -fs /mnt/wslg/runtime-dir/* "%t
    [Install]
    WantedBy=default.target
  4. Create a systemd service that setups the X11 socket

    /etc/systemd/user/wslg-X11-unix.service
    [Service]
    Type=oneshot
    ExecStartPre=rm -rf /tmp/.X11-unix
    ExecStart=ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix
    [Install]
    WantedBy=default.target
  5. Enable those services

    Terminal window
    sudo systemctl --global enable wslg-runtime-dir
    sudo systemctl --global enable wslg-X11-unix
  6. Restart WSL

    Terminal window
    exit
    Terminal window
    wsl.exe --shutdown
    arch.exe