7 Answers
7

In addition to all the references to :1, :2, etc; you can also specify a network name or ip address before the colon, e.g. 192.168.0.1:0 - this will connect to a machine over the network. Most modern X servers have authentication ("MIT-MAGIC-COOKIE"), you will have to sort that out before you connect - see xhost and xauth.

Also, if you use ssh -X <remotehost>, then any X commands you run in that ssh session will connect to a different port (a quick test on my box shows :10), which is then pushed through your ssh connection back to the box you are coming from, and will show up on your screen there.

It has to do with the X Window Server. They define what display numbers there are.

You shouldn't need to worry about explicitly supporting a display number; at the very most, you simply hand the reference to the X Window Client library and let it figure it out.

Modern servers can make multiple displays available with multi-head adapters and with multiple adapters. The vast majority of the time, :0 will be your only display. This is because there really is only one, and that's the default number when there is just one. It is possible to make it start as :2, which is unusual, but everything would still work okay.

With multi-head displays and/or multiple cards, it is possible to have an X Server manage multiple displays as discrete screens (i.e. with things like Xinerama turned off). Then you can get display numbers like :0.0 and :0.1. I used to run a desktop like this for a long time. Nothing broke because everything took the display number and just handed it to the X Client library. One unusual advantage was that each screen gets it's own list of virtual desktops. In a Xinerama display, you can't do that. But you have the disadvantage of not being able to move windows between screens, because they have different display numbers.

You can even do things like run multiple X Servers. That's when you get :0 and :1 etc. The problem with that is who gets the keyboard and mouse.

By default a machine will normally only be running one display - :0, which is normally on VT 7.

If you run a second X server, it will be :1. You can do that from the command line, but the easier way is to choose "start new session" in KDE (I assume GNOME has some equivalent, but I'm not familiar with it). That lets you log in again on a second X server, which will be running on VT 8 (ie. you can swap between them with Ctrl-Alt-F7 and Ctrl-Alt-F8).

You should then be able to run applications on either by using "DISPLAY=:1 xterm" or whatever.

Don't worry about using other displays at first. Probably the only time you'll have to worry about displays is when you connect to a remote computer and connect your remote applications to the display.

Your applications that you write won't have to directly worry about the display; the X library will take care of it for you.