wsl2-hacks icon indicating copy to clipboard operation
wsl2-hacks copied to clipboard

How to run xfe and similar GUI apps under wsl2hack

Open rye2020 opened this issue 3 years ago • 4 comments

xfe gives message "FXApp::openDisplay: unable to open display :0" I have tried several approaches without success. Does any one have a fix? I am running: Operating System: Ubuntu 20.04.5 LTS Kernel: Linux 5.15.57.1-microsoft-standard-WSL2 Architecture: x86-64

rye2020 avatar Sep 12 '22 16:09 rye2020

What are you running as an X server? I use MobaXterm and xfe works there. My bashrc has this:

export DISPLAY="$(ip route|awk '/^default/{print $3}'):0.0"

which sets DISPLAY to the windows IP so X apps can reach MobaXterm

timriker avatar Sep 12 '22 16:09 timriker

@timriker For me that does not work. What works for me it asking Windows for the IP address of the machine, and set DISPLAY accordingly.

My first approach to do that from within the .bashrc was:

export DISPLAY=$(ping.exe -n 1 $(hostname) | grep 'Pinging' | sed -re 's,Pinging [^\[]*\[([0-9.]*).*,\1,'):0.0

Maybe I have to say that I am not very familiar with awk. Probably it would have been easier. Also I could not use nslookup.exe as it would return more than one IP address, for I am connected via a biz VPN.

schwaerz avatar Sep 13 '22 14:09 schwaerz

The command is running "ip route" and then in awk, searching for a line starting with default and printing the third paramter. ip route should show the default route for your linux hyper-v instance which should route to the windows box. This command is for WSL2 instances. On WSL1 instances you can use 127.0.0.1 as these use the host network addresses.

if grep -q 'Microsoft' /proc/version ; then
  # WSL1
  export DISPLAY="${DISPLAY:-localhost:0.0}"
  export PULSE_SERVER="${PULSE_SERVER:-tcp:127.0.0.1}"
elif grep -q 'microsoft' /proc/version ; then
  # WSL2
  export DISPLAY="$(ip route|awk '/^default/{print $3}'):0.0"
  export PULSE_SERVER="${PULSE_SERVER:-tcp:$(ip route|awk '/^default/{print $3}')}"
fi

the PULSE_SERVER is for pre-WSLg instances. Not sure yet how to check for that as I'm on Windows 10.

timriker avatar Sep 13 '22 16:09 timriker

@timriker reminded me that I had to do what was done in WSL1 - start an Xserver - so I started VcXsvr. Voila! Thank you!

rye2020 avatar Sep 15 '22 00:09 rye2020