[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2010-11-14
8
Medium Priority
?
2,434 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 81

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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 81

Accepted Solution

by:
arnold earned 2000 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 81

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

873 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