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.
- 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.
- 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"
- 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
If you have this problem try next steps:
- You set the GTK scaling to hidpi and then find the VcXsrv executable in Windows OS.
- Open its properties,
compatibility --> hidpi settings --> override scaling and perform by application
. - Then apply the settings.
- The blurriness is most likely because Windows is trying to do the scaling instead of letting the apps do the job.
- Restart WSL and VcXsrv.
- Now try check text in your app.
Source: Jazzlike-Draw-3634 from reddit
- Install special package
sudo apt install x11-xkb-utils
- 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
- Restart WSL seance.
Source: nt86 from SU