views:

167

answers:

4

linux only: i want to open two windows for my application, one on the main screen of the computer, and one on a virtual X11 sessions to be accessed by remote desktop only. Can some X11 expert tell me how this is done?

A: 

I am a little unclear on the question, but here's a hypothetical setup:

I am sitting on my computer (we'll call that the root session) and I have a shell. In this case there is an environment variable DISPLAY with the value "127.0.0.1:0.0".

A second session is started. You'll need to know what the display variable is on this machine. If it's also on the localhost it may be something like "127.0.0.1:1.0". If you do an "echo $DISPLAY" on the other host it will tell you this. If it reports ":1.0" or something without the "127.0.0.1" that's okay. The localhost is implied if an address is not specified.

Next, before going back to the root session you'll need to run "xhost" to allow other sources to display windows on this host. (Disclaimer: What I'm going to tell you to do is horribly insecure so you may want to read the man page for xhost if you are on an insecure network). Type "xhost +" in an xterm on the other display. This command (in particular the "+" option) allows any host to pop up windows on this display.

So then all you have to do is go back to your root session shell and (I assume bash) run "export DISPLAY="127.0.0.1:1.0". Then run "xterm", which should have the window popping up in the other session.

I hope this helps.

You might do a search for "X windows DISPLAY variable" if any of this is unclear.

Craig W. Wright
Please don’t recommend “horribly insecure” things.
andrew
A: 

It depends at what level you're programming -- if you're calling directly into Xlib, I imagine you know that the first argument to XCreateWindow is a Display * and of course that's how you tell X11 where to create the window. http://tronche.com/gui/x/xlib/window/XCreateWindow.html for details in case it helps.

If it's other languages/frameworks/etc that you're using, it would help if you mentioned which ones they are.

Alex Martelli
+1  A: 

You need to set the DISPLAY environment variable like this:

DISPLAY=host:0.0

See the X manpage for more details.

lothar
+1  A: 

The programmatic interface to this $DISPLAY functionality in xlib appears to be called XOpenDisplay(). You'll need to manage two (or more) Display objects.

It is possible that the various higher level interface toolkits (qt, ...) provide a more abstracted interface. That would save you considerable pain.

Good luck.

dmckee