I'm running Ubuntu and I want to get the number of attached monitors, their current resolution and, if possible, their position in relation to each other. Because I don't like parsing Console output of the xrandr command line tool—at least not if I don't have to—I would like to do that with Python-XLib or a similar Pythonic approach.
This is the xrandr output for my display config:
$ xrandr
Screen 0: minimum 320 x 200, current 2960 x 1050, maximum 8192 x 8192
DVI-0 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm
1680x1050 60.0*+
[some lines cut]
VGA-0 connected 1280x1024+1680+26 (normal left inverted right x axis y axis) 376mm x 301mm
1280x1024 60.0 + 75.0*
[some more lines cut]
I want to get these values with Python, in a way like this:
monitors = get_monitors()
print monitors[0].width # out: 1680
print monitors[1].width # out: 1280
print monitors[0].x_position # out: 0
print monitors[1].x_position # out: 1680
When trying to get informations via Python-XLib (or other libs like pyGTK and pygame), it seems that all monitors are always handled as one single display. For example this is what I got with XLib so far:
import Xlib
import Xlib.display
display = Xlib.display.Display(':0')
print display.screen_count() # output: 1
root = display.screen().root
print root.get_geometry().width # output: 2960 -> no way to get width of single monitor?
print root.get_geometry().height # output: 1050
But as I said I would prefer a cleaner approach without having to parse Console output. Is there really no way to get (detailed) Display informations with Python without having to parse xrandr output?
Xlib's ScreenCount returns the "invalid" actual screen count.