# Getting info about attached displays

**URL:** <https://www.ruby-forum.com/t/getting-info-about-attached-displays/157609>\
**Category:** Ruby\
**Created:** [January 13, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/getting-info-about-attached-displays/157609 "2009-01-13T18:01:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [January 13, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/getting-info-about-attached-displays/157609/1 "2009-01-13T18:01:52Z")

</div>

Hi,  
I have a ruby daemon process that needs to get info about the monitors  
attached to the machine it is running on. Does anyone have any nice  
x-platform way of doing this? Barring that, how about some Windows  
calls?

Thanks!

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [January 13, 2009, 6:49pm UTC](https://www.ruby-forum.com/t/getting-info-about-attached-displays/157609/2 "2009-01-13T18:49:54Z")

</div>

On Tue, Jan 13, 2009 at 11:01 AM, Phil S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> I have a ruby daemon process that needs to get info about the monitors  
> attached to the machine it is running on. Does anyone have any nice  
> x-platform way of doing this? Barring that, how about some Windows  
> calls?
> 
> ## Thanks!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).  
> Phil, that’s really more of a general unix (or DOS in the case of  
> windows) question.

Still, for real OSes running X, xdpyinfo is a utility that provides  
tons of info, including the number of attached screens…

irb\>%x[xdpyinfo][/number of screens: +[0-9]+/]  
=\> “number of screens: 1”

I’d suggest just running it into less, so you can get acquainted with  
it’s output. The man page sadly doesn’t point you to useful C calls,  
but the source should be decently documented if you want to grab it  
from [x.org](http://x.org) or [xfree86.org](http://xfree86.org).

–Kyle

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [January 13, 2009, 7:00pm UTC](https://www.ruby-forum.com/t/getting-info-about-attached-displays/157609/3 "2009-01-13T19:00:55Z")

</div>

Kyle S. wrote:

> On Tue, Jan 13, 2009 at 11:01 AM, Phil S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,  
> > I have a ruby daemon process that needs to get info about the monitors  
> > attached to the machine it is running on. Does anyone have any nice  
> > x-platform way of doing this? Barring that, how about some Windows  
> > calls?
> > 
> > ## Thanks!
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).  
> > Phil, that’s really more of a general unix (or DOS in the case of  
> > windows) question.
> 
> Still, for real OSes running X, xdpyinfo is a utility that provides  
> tons of info, including the number of attached screens…
> 
> irb\>%x[xdpyinfo][/number of screens: +[0-9]+/]  
> =\> “number of screens: 1”
> 
> I’d suggest just running it into less, so you can get acquainted with  
> it’s output. The man page sadly doesn’t point you to useful C calls,  
> but the source should be decently documented if you want to grab it  
> from [x.org](http://x.org) or [xfree86.org](http://xfree86.org).
> 
> –Kyle

Thanks Kyle,  
Yes… I realise now that it is more OS based (though I still can’t find  
the windows command for it!).

The problem with xdpyinfo is that number of screens is actually NOT the  
number of displays. I have 2 monitors attached and I get the answer of  
1, because I have one virtual desktop spanning the two.

Anyway… off topic!

Thanks again

---

<div class="post-metadata">

**Author:** ![philswenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7feea3/32.png) [@philswenson](https://www.ruby-forum.com/u/philswenson)\
**Post date:** [January 13, 2009, 9:40pm UTC](https://www.ruby-forum.com/t/getting-info-about-attached-displays/157609/4 "2009-01-13T21:40:23Z")

</div>

Phil, there are two ways you can have two monitors being a virtual  
display, the driver may take care of it (like the nvidia one, and I  
have no way of knowing how to detect that), or it may be through  
xinerama. If it’s through xinerama, you should be able to tell what  
the geometries and positions of the component screens are, even if you  
use it as one huge screen.
