Solved

C++/Linux: How can I find the screen resolution?

Posted on 2010-11-14
8
2,359 Views
Last Modified: 2012-05-10
I would like to write some code to query the display and get the screen resolution on Linux.
If there are multiple monitors, I'd like to know the resolution for all the monitors.

Any ideas how?
0
Comment
Question by:rjsurati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 78

Expert Comment

by:arnold
ID: 34131825
You are looking at system calls to the graphics API.
http://www.yolinux.com/TUTORIALS/LinuxTutorialC++.html
0
 
LVL 4

Expert Comment

by:denissie
ID: 34133940
Using QT:
http://www.qtforum.org/article/22414/read-screen-resolution.html

In X11, you'd need to call the Xlib's XGetWindowAttributes to get the various window info, including the size and position relative to parent:
Example: http://cvsweb.xfree86.org/cvsweb/xc/programs/xwininfo/xwininfo.c?rev=1.11&content-type=text/vnd.viewcvs-markup
Ref: http://efreedom.com/Question/1-1153052/Programmatically-Get-Resolution-Window-System-Linux

I hope it helps.
0
 
LVL 9

Expert Comment

by:expert_tanmay
ID: 34134927
you'd need to call the Xlib's XGetWindowAttributes to get the various window info, including the size and position relative to parent. you can man xwininfo to check its capabilities and also download the source xwininfo.c

just type xwininfo.c in google you will get the source..
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 4

Expert Comment

by:denissie
ID: 34135508
expert_tanmay, you've just copy/pasted the reference and what I wrote above :)
0
 
LVL 9

Expert Comment

by:expert_tanmay
ID: 34142169
denissie Oh yes I didn't realize that you have also written about xwininfo.c. I was writing code on getting live view of Nikon D90 on my desktop when I came across xwininfo.c by coincidence.

 
0
 

Author Comment

by:rjsurati
ID: 34144862
Guys, this is all great. But, I'm not sure how the multiple monitor case comes into play. Don't I need to enumerate each of the displays somehow?

I can call XGetWindowAttributes on a window, and then get the information of the root window. But how does that tell me how many monitors there are and which monitor has which coordinates?

I apologize -- I'm feeling a bit confused.
0
 
LVL 78

Accepted Solution

by:
arnold earned 500 total points
ID: 34145517
I think that is handled through the OS/kernel/graphics
i.e. all you would see is the range of the arrangement of the monitors. If there are three in a row, the information you are looking for is a position as if the three were a single large display.0,0-1920,1080 for a single monitor would be 0,0-5760,3240 for a three monitor setup.
0
 
LVL 78

Expert Comment

by:arnold
ID: 34145965
Oops, the range would be 0,0-5760,1080. (x,y)
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question