View Full Version : Detecting connected X displays
02-22-2004, 10:44 PM
Is there a way to detect how many / which displays are supported under X. I suppose one way would be to iterate x and y from 0 to N and try to open display ":x.y", and store all successful opens in a list of supported display names.
What is the difference betwen the number before and after the "." in the display name?
How does nVidia twin-view work vs having separate graphics cards installed?
Note: I'm only interseted in local displays, not networked ones (I will probably check getenv("DISPLAY"), and add it to my list of supported displays if it is not a local display).
02-27-2004, 08:36 PM
Probably iteration is the only way... I can't think of any other. But only for the display number. The second number is the screen number and the number of screens can be found through the Display struct. Additional cards would provide you with additional displays whereas twinview should give you an additional screen for the same display. And the numbers for local displays start at 0 and increase sequentially for each additional display, except networked displays where you have telnet or ssh(ed) into another machine (usually start at 10 from my limited experience).
hope it helps
02-29-2004, 11:12 PM
Thanks for the help. I pretty much suspected that iteration was the only way. Your information was what I was looking for - I will see how it works (not that I will be able to test it on my own machine http://www.opengl.org/discussion_boards/ubb/frown.gif ).
first let me say that I don't have a reliable system setup right now so I'm not 100% sure about what I'm going to say, but I am pretty sure.
Now here's a quote from the X manual page:
From the user's perspective, every X server has a display name of the form:
This information is used by the application to determine how it should connect to the server and which screen it
should use by default (on displays with multiple monitors):
The hostname specifies the name of the machine to which the display is physically connected. If the
hostname is not given, the most efficient way of communicating to a server on the same machine will be
The phrase "display" is usually used to refer to collection of monitors that share a common keyboard and
pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one
display. Larger, multi-user systems, however, frequently have several displays so that more than one
person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a
display number (beginning at 0) when the X server for that display is started. The display number must
always be given in a display name.
Some displays share a single keyboard and pointer among two or more monitors. Since each monitor has its
own set of windows, each screen is assigned a screen number (beginning at 0) when the X server for that
display is started. If the screen number is not given, screen 0 will be used.
It seems that each seperate X server process you start starts a seperate display which can have different screens (which are configured in XF86Config-4). Screen numbers must be consecutive and you can get them from the display structure using a macro provided by X without doing any probing. But this is not possible with displays and probing won't help you either. The display number is specified when the server starts and it doesn't have to be consecutive, just positive. Try this at a command prompt with no server running:
$X :0.0 &
$X :123.0 &
This will give you two servers(two displays) but obviously you can't find the second one unless you probe all numbers between 0 and 123. Anyway the display numbers running on a machine are specified by the user so it's not your business to 'autodetect' them. I don't know what you need this for but either let the user specify all available displays in a list in some config. file or if its for GLFW specify the display as a parameter in some API call.
I hope all this helps.
PS: I'm considering using a toolkit since I'm tired of fighting with X (and totally terrified of doing the same with win32). GLFW is on the top of my list of choices (and at the bottom, it's the only one. I guess I could consider glut or freeglut but I don't like them and I wouldn't even consider SDL). I think I'm going to send you and email one of these days (if I ever get my system runnning) about some details in GLFW which cause me some trouble.
[This message has been edited by zen (edited 03-01-2004).]
03-01-2004, 10:08 PM
Thanks for the info. Yes, it's for GLFW. Based on what you are saying, I guess the only thing I need/want to do is to query the number of screens for the default display.
The thing is that I want to add support for multiple "displays" (=screens under X, =displays under Win32). Probably two functions: glfwGetNumberOfDisplays and glfwBindDisplay. (btw, I would like to unify most/all glfwGet's into a single function).
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.