Solved

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

Posted on 2010-11-14
8
2,285 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 77

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
 
LVL 4

Expert Comment

by:denissie
ID: 34135508
expert_tanmay, you've just copy/pasted the reference and what I wrote above :)
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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 77

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 77

Expert Comment

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now