[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

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

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
Technology Partners: 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!

 
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 80

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 80

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

656 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