How to obtain information about all connected screens using XLib

Marius Gedminas mgedmin at
Thu Sep 13 02:54:24 PDT 2007

On Thu, Sep 13, 2007 at 12:29:19AM +0000, Jeremy Roberson wrote:
> Here is the problem.  I need to obtain screen information for all of
> the connected monitors individually.  When a multi monitor setup is
> configured for extended desktop, I can only get results for the
> combined screen using Xlib and XOpenDisplay.  X only seems to
> recognize one combined screen, not both.  Any ideas or help would be
> appreciated.  There must be a way to get individual screen information
> in this type of configuration.

You probably need libXrandr or libXinerama for this.  I don't know the
low-level APIs, but I've used Gdk's Python bindings to get this info:

import gtk.gdk
screen = gtk.gdk.screen_get_default()
n = screen.get_n_monitors()
for i in range(n):
    rect = screen.get_monitor_geometry(i)
    print "Monitor %d: %dx%d at (%d, %d)" % (i, rect.width, rect.height,
                                             rect.x, rect.y)

Marius Gedminas
You've obviously never tried to reverse engineer a chip using an electron
microscope. [...] That's like looking at the grains of sand on a beach
and trying to map out the coastline of Hawaii. -- Cutie Pi, July 2006
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <>

More information about the xorg mailing list