Krithik Vaidya
Krithik Vaidya

Reputation: 100

Setting a consistent display number for X2Go client

So I've recently started using Ubuntu on WSL2, and I'm trying to use X2Go as my X window system to run GUI apps. I start up the Ubuntu WSL, and run the SSH daemon. Then, I use the x2go client on Windows to connect to the X2Go server running on the Ubuntu WSL, and it all works fine.

But I want to normally use the Windows Terminal for running BASH, and run the GUI applications in the X2Go client. For this, the $DISPLAY environment variable needs to be set.

Running session in X2Go client

In this case, the value for the environment variable would be DISPLAY=:60.0 (where 60 is the display number in the screenshot above and 0 indicates monitor 0). But, every time I restart the client session, I get a different display number (previous display number + 1), and the value of the environment variable needs to be changed again.

Is there any way I can make the display number consistent and set the DISPLAY environment variable in .bashrc so that I do not need to export it every time? I'm new to this, so let me know if something doesn't make sense or if there's an entirely different approach that's better for this.

Upvotes: 0

Views: 2828

Answers (2)

x2gouser
x2gouser

Reputation: 1

My Display is set on Windows X2Go to a number that obviously does not correspond to an active display, so I get shown an active session in the management panel, but do not receive an XDisplay. The XDisplay goes somewhere else, e.g., DISPLAY 52. The automatic assignment of a useful DISPLAY number fails. There are no indications of failed permissions that the display, e.g., gets blocked.

Upvotes: 0

alexkp
alexkp

Reputation: 46

Not exactly what you are after, but you can find the display number by looking at the full command line for the x2goagent process -- the display will be at the end:

$ pgrep -a x2goagent

So if you add the following to your .bashrc

x2g() {
    export DISPLAY=`pgrep -a x2goagent | rev | cut -d " " -f 1 | rev`
}

you can use the x2g function at the bash prompt to set your DISPLAY variable to wherever X2Go has decided to put the screen this time:

$ x2g
$ echo $DISPLAY
:55

It's not ideal because you need to enter this command for every shell, and do so after you have started the X2Go session. But it's a bit easier than finding the display manually every time.

Note that if you were to use a terminal executing within the WSL environment where the X2Go agent is running, DISPLAY is set automatically to the correct value (as long as you don't redefine it somewhere in your .bashrc or equivalent). I understand from your question that you are working from the Windows terminal running bash, however, you could potentially use (say) an xterm running in WSL for launching X11 apps, then continue to use the Windows terminal for everything else.

Upvotes: 3

Related Questions