Posted: . At: 9:30 AM. This was 1 year ago. Post ID: 17792
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to get information about connected monitors on Linux.

Getting information about connected display devices is very easy on Linux. The xrandr utility can print this information very easily.

Printing a list of all connected monitors.

┗━━━━━━━━━━┓ john@localhost ~/Documents
           ┗━━━━━━━━━━━━━╾ ╍▷ xrandr --listmonitors
Monitors: 2
 0: +*DVI-D-0 1920/477x1080/268+1920+0  DVI-D-0
 1: +HDMI-0 1920/508x1080/286+0+0  HDMI-0

This prints a list of all connected monitors on a Linux PC.

Use the –listproviders parameter to list all graphics cards that are actually in use in your Linux system.

┗━━━━━━━━━━┓ john@localhost /etc/skel
           ┗━━━━━━━━━━━━━╾ ╍▷ xrandr --listproviders
Providers: number : 1
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 4 outputs: 4 associated providers: 0 name:NVIDIA-0

Another way to list all GPU hardware installed on your machine is via the nvidia-smi command.

┗━━━━━━━━━━┓ john@localhost /etc/skel
           ┗━━━━━━━━━━━━━╾ ╍▷ nvidia-smi --list-gpus
GPU 0: NVIDIA GeForce GTX 1050 (UUID: GPU-19942ccc-f676-f224-4832-75e6bfefa5a4)

You may also use a C program to list all connected monitors on your Linux system.

monitors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xinerama.h>
 
int main(int arcg, char argv) {
 
    Display *d;
    int i, n;
    Display *display = XOpenDisplay(NULL);
	d = XOpenDisplay (NULL);
	if (!d) {
		printf ("display is null!\n");
		return 1;
	}
 
    int screenCount = ScreenCount(display);
 
	n = ScreenCount (d);
	printf ("screen count: %d; default screen: %d\n", n, DefaultScreen (d));
	for (i = 0; i < n; i++)
		printf ("[screen %d] width=%d height=%d\n", i, DisplayWidth (d, i), DisplayHeight (d, i));
 
	if (XineramaIsActive (d)) {
 
		XineramaScreenInfo *screens;
		int num_screens;
 
		screens = XineramaQueryScreens (d, &num_screens);
		printf ("There are %d monitor(s) connected to your computer.\n", num_screens);
 
		for (i = 0; i < num_screens; i++)
			printf ("[screen %d] x_org=%hd y_org=%hd width=%hd height=%hd\n", i, screens[i].x_org, screens[i].y_org, screens[i].width, screens[i].height);
 
	} else {
		printf ("Xinerama is NOT active.\n");
    }
 
    XCloseDisplay(display);
    return 0;
}

This works very well.

Compile it like this.

┗━━━━━━━━━━┓ john@localhost ~/Documents
           ┗━━━━━━━━━━━━━╾ ╍▷ gcc monitors.c -L/usr/X11/lib -lX11 -lXinerama -o list

This is the output you will get.

┗━━━━━━━━━━┓ john@localhost ~/Documents
           ┗━━━━━━━━━━━━━╾ ╍▷ ./list 
screen count: 1; default screen: 0
[screen 0] width=3280 height=1080
There are 2 monitor(s) connected to your computer.
[screen 0] x_org=1360 y_org=0 width=1920 height=1080
[screen 1] x_org=0 y_org=0 width=1360 height=768

This shows how easy it is to get useful information about your connected monitors and graphics cards on Linux.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.