rudolfninja
rudolfninja

Reputation: 497

How to get display devices name in Linux

I'd like to find linux analogs of EnumDisplayDevices and EnumDisplaySettingsEx WinAPI functions.

The info I need to get is display name and state (if it active or not), width, height, bits per pixel and frequency. How can I get this info using C (C++)? Thanks.

Upvotes: 2

Views: 6136

Answers (2)

paulsm4
paulsm4

Reputation: 121849

Some programmer dude and ramrunner are absolutely correct. For most Linux systems, the graphical "desktop" is based on X Windows. Command-line tools for querying your X "display" include xrandr and xdpyinfo. The C-language source code for both are freely available; you can find many example programs with a Google search.

... HOWEVER ...

X Windows is "client/server". Your Linux "desktop" need not be on your physical PC; your X "display" could just as easily be a Windows desktop. In this case - xrandr and xdpyinfo are still applicable: they refer to where you're displaying (e.g. an XMing client on Windows), and not the physical host Linux is running on.

If you want to query the graphics devicews on your physical server ... then you'll instead use commands like lshw -c display or get-edid

Upvotes: 2

ramrunner
ramrunner

Reputation: 1372

As mentioned by 'Some programmer dude' in the comments you can have to go through the X window system. Most specifically one option would be the RandR protocol. Here is the protocol specification as well as the source code of the command xrandr that invokes the XRR functions and outputs most of the info that you want on the terminal. Look for the place where the

XRRScreenResources  *res

is populated and then how the modes are fetched from it using the find_mode() function.

other commands that might assist you and don't go over the RandR extensions could be xprop(1), xdpyinfo(1), xwininfo(1)

Upvotes: 2

Related Questions