tags:

views:

338

answers:

3

It seems like an simple problem, but I can't find the answer: How do you query (via X11) what monitors exist and their resolutions?

+5  A: 

Check out display macros and screen macros from the Xlib manual.

Specifically:

  • From the first link: ScreenCount(), ScreenOfDisplay()
  • From the second link: WidthOfScreen(), HeightOfScreen()
asveikau
+4  A: 

If Xinerama is in use, try XineramaQueryScreens. Otherwise, you may be able to assume a single screen and use (X)WidthOfScreen/(X)HeightOfScreen.

(Also see the other answer. It's remotely possible someone is using the old X screen model where your screens are :x.0, :x.1, etc.)

Nicholas Riley
+1 for xinerama
asveikau
+4  A: 

For modern X servers, there's also the XRandR extension, which provides the most up-to-date model of multi screen layout information, including overlapping screens and dynamic screen changes.

Documentation of it is available in the XRandR 1.3.1 Protocol spec and the libXrandr man page.

alanc