Skip to content

Instantly share code, notes, and snippets.

@vyach-vasiliev
Last active June 9, 2024 22:23
Show Gist options
  • Save vyach-vasiliev/b46f98873c217035e959bcc2e589583c to your computer and use it in GitHub Desktop.
Save vyach-vasiliev/b46f98873c217035e959bcc2e589583c to your computer and use it in GitHub Desktop.
Run WSL with VcXsrv (2024)

Reason

I ran the application (Intellij IDEA in my case) like this (without VcXsrv) in WSL2.

export LIBGL_ALWAYS_SOFTWARE=1 && export DISPLAY=:0 && nohup idea.sh &

But after some time I observed 1-5-10 second freezes in the GUI interface.

Setup VcXsrv on Windows OS (10 ver in my case)

  1. Install VcXsrv that is an open-source and frequently updated Windows X Server (it will be the provider of graphics resources and keyboard/mouse events), then start it as follow:
  • Use multiple windows
  • Do not start client
  • Set "Disable access control" or add -ac into the additional parameters, it will avoid permission denied error when trying to run a GUI application.
  • Then you can save the configuration in order to reuse it later to launch VcXsvr directly with the right configuration.
  1. Windows firewall settings
  • Check that the Windows firewall settings are correctly configured, it must have both public and private checked for "VcXsvr windows xserver".
  • Settings are accesibles from "Windows settings > Update and security > Windows Securities > Firewall and network protection > Allow an application through firewall"
  1. WSL2 terminal configuration
  • The WSL2 terminal must be configured to set and export the DISPLAY environnment variable to use the Windows host’s IP of WSL2. The IP can be retrieve from the file /etc/resolv.conf that is generated by WSL2. Add the following lines into the .bashrc file to export needed variables.
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"
  • Launch VcXsvr, then verify it works correctly by launching xeyes app, install it if it is not already done.

Sources: Developer's Corner

Blurry text on WSL2 with X-server

If you have this problem try next steps:

  1. You set the GTK scaling to hidpi and then find the VcXsrv executable in Windows OS.
  2. Open its properties, compatibility --> hidpi settings --> override scaling and perform by application.
  3. Then apply the settings.
  4. The blurriness is most likely because Windows is trying to do the scaling instead of letting the apps do the job.
  5. Restart WSL and VcXsrv.
  6. Now try check text in your app.

Source: Jazzlike-Draw-3634 from reddit

Keyboard layout does not switch within WSL applications

  1. Install special package sudo apt install x11-xkb-utils
  2. Past this line in .bashrc (for US and RU languages in my case):
# for CTRL+SHIFT
setxkbmap us,ru -option grp:ctrl_shift_toggle
# or for ALT+SHIFT
setxkbmap us,ru -option grp:alt_shift_toggle
  1. Restart WSL seance.

Source: nt86 from SU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment