[pygtk] Detecting number of monitors/screens?

Magnus Therning magnus at therning.org
Wed May 24 16:42:22 WST 2006


Hope you don't mind that I'm CCing the list as well.

On Wed, May 24, 2006 at 08:55:34AM +0100, Duncan Greenwood wrote:
>Magnus Therning wrote:
>
>>How do I find out how many heads X is using?
>>
>>I'm on a dual-head system at work and would like my program to be able
>>to detect that and change its behaviour appropriately (I'm moving around
>>windows and would like them to stay on a single monitor). I have been
>>looking at the API offered by wnck, it offers all information about the
>>screen/display/window I need, except for this little detail :-(
>>
>Magnus
>
>This is basically what the standard xdpyinfo(1) command does,
>converted to python:
>
>  >>> import gtk
>  >>> d = gtk.gdk.Display('mercury:0')
>  >>> d.get_n_screens()
>  1
>  >>> s = d.get_screen(0)
>  >>> s.get_n_monitors()
>  1
>  >>>
>
>Hope this helps.

Ah, it sure does. Thanks!

I also noticed that it's possible to get enough information to figure
out the entire configuration. Continuing on your snippet (but using
ipython of course):

 In [10]: m1 = s.get_monitor_geometry(0)
 In [11]: m1.x
 Out[11]: 1280
 In [12]: m1.y
 Out[12]: 0
 In [13]: m2 = s.get_monitor_geometry(1)
 In [14]: m2.x
 Out[14]: 0
 In [15]: m2.y
 Out[15]: 0
 In [16]: m2.width
 Out[16]: 1280
 In [17]: m2.height
 Out[17]: 1024

As you can see I have my first monitor to the right of my second :-)

/M

-- 
Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
magnus at therning.org             Jabber: magnus.therning at gmail.com
http://therning.org/magnus

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

Most people, I think, don't even know what a Rootkit is, so why should
they care about it?
     -- Thomas Hesse, president of Sony-BMG's Global Digital Business,
        commenting on XCP
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20060524/3ab47191/attachment.pgp


More information about the pygtk mailing list