Solved

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

Posted on 2010-11-14
8
2,271 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 76

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 Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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 76

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 76

Expert Comment

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

Featured Post

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)

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

747 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

9 Experts available now in Live!

Get 1:1 Help Now