Linux get screen resolution

How to query X11 display resolution?

It seems like an simple problem, but I can’t find the answer: How do you query (via X11) what monitors exist and their resolutions?

8 Answers 8

This might be helpfull for cli and scripting

But xRandR might be more accurate, especially, when there is multiple monitor environment:

It seem xrandr compared to xwininfo -root doesn’t tell you about the monitor that is currently active though. However it’s telling you about the monitor by proxy of the active root window.

xprop -root is also an alternative to xwininfo , but every -root option requires a root window. During .xinitrc you can not rely on the existence of the root window.

If Xinerama is in use, try XineramaQueryScreens . Otherwise, you may be able to assume a single screen and use (X)WidthOfScreen / (X)HeightOfScreen.

(Also see the other answer. It’s remotely possible someone is using the old X screen model where your screens are :x.0 , :x.1 , etc.)

For modern X servers, there’s also the XRandR extension, which provides the most up-to-date model of multi screen layout information, including overlapping screens and dynamic screen changes.

Documentation of it is available in the XRandR 1.3.1 Protocol spec and the libXrandr man page.

The library X11 working only with unix-like OS, so it is a not cross-platform solution.

A full code

#include #include int main(const int argc, const char *argv[]) < Display *display; Screen *screen; // open a display display = XOpenDisplay(NULL); // return the number of available screens int count_screens = ScreenCount(display); printf("Total count screens: %d\n", count_screens); for (int i = 0; i < count_screens; ++i) < screen = ScreenOfDisplay(display, i); printf("\tScreen %d: %dX%d\n", i + 1, screen->width, screen->height); > // close the display XCloseDisplay(display); return 0; > 

A compilation

gcc -o setup setup.c -std=c11 `pkg-config --cflags --libs x11` 

A result (actual for my computer)

Total count screens: 1 Screen 1: 1366X768 

Thank you for providing the code. Do you know the answer to my question: stackoverflow.com/questions/42987932/…. I am asking if the screens you are finding in this code is the same as what Gtk3 3.22 calls monitors.

Any opinion/experience on Cygwin/Xming/etc.? X11 might not be portable, but if it’s ported/adapted, it’s as good as portable, no? Not my area of expertise — I’m used to using libraries like SDL2 that sweep this stuff under the rug.

This doesn’t work with multiple monitors, at least on my Ubuntu setup. The question used the word «monitors», with an «s». The results this code gives me: Total count screens: 1 Screen 1: 3520X1200 I’m using two «Join Displays», as denoted by the Display GUI settings. The first is 1920×1200. The second is a smaller, laptop display. The code results give you the total area covered by the two displays side-by-side. I want to programmatically determine the resolution of the primary display.

Читайте также:  Создать file linux терминал

Источник

How to Find Linux Desktop Screen Resolution from Command Line

The continued use of a Linux operating system distribution takes its users to the dimension of unknowns where they discover limitless knowns about the computing world. The Linux operating system ecosystem and community carries individuals of all professions and skillsets.

Knowing the screen resolution of your Linux desktop environment is vital for Linux users that have invested their time and effort in fields related to graphic designs and web software development. Such users can be able to gauge their work or project expectations and delivery from this information.

Additionally, knowing the screen resolution of your Linux desktop OS can help users customize/adjust the computer’s display settings to fit certain project/work criteria.

This article will walk us through valid means of achieving the above-stated objective.

Problem Statement

We can easily determine the Linux desktop screen resolution from its GUI-based display settings. Our goal, however, is to achieve the same objective but via the Linux terminal/command-line environment.

Method 1: Using xdpyinfo Utility

The xdpyinfo utility primarily displays some general information related to how the Linux machine can be used as a server. This information can include but is not limited to vendor release number, keycode range, focus, and a number of extensions.

Show X Server Info

The xdpyinfo utility should be installed by default on your Linux OS distribution and therefore disregard the need to install its associated package via the associated Linux OS package manager.

To use the xdpyinfo utility command to retrieve the Linux desktop screen resolution, we will first execute the xdpyinfo command, pipe it to a grep command that will retrieve the dimensions aspect of its output, and finally pipe the values of the dimension to the awk command for display as Linux terminal output.

The representation of the above-discussed command execution is as follows:

$ xdpyinfo | grep "dimensions" | awk '< print $2 >'

Find Linux Desktop Screen Resolution Using xdpyinfo Command

The above command execution denotes that we are dealing with a Linux desktop screen resolution of 1366 pixels in length by 768-pixel width.

Method 2: Using the xrandr Command

The xrandr utility also comes pre-installed on almost all Linux OS distributions. Its manual page gives a detailed overview of the command and its capability.

The xrandr command belongs to the RandR extension hence its representation as X Resize, Rotate, and Reflect Extension (xrandr).

Using the xrandr command on its own should output the current screen resolution of our Linux desktop together with other viable display settings info like VGA, DP, and HDMI connection statuses.

Show Linux Dispay Settings

To filter out the xrandr command to only output the current desktop screen resolution of our Linux machine, we will pipe it to a grep command with a ‘*’ command option that instructs it to retrieve the current screen resolution from the initial xrandr command. Afterward, the grep command data is piped to the awk command to print the Linux desktop’s current screen resolution.

Its implementation is shown below:

Find Linux Desktop Screen Resolution Using xrandr Command

As expected, an output of 1366 pixel length by 768-pixel width is printed.

Источник

Читайте также:  Linux mount samba fstab

How to find screen resolution in Linux desktop environment

One system setting that you often check or modify in Linux desktop environment is display setting, in particular, screen resolution. There are different ways to get display resolution information on Linux, either from the command line or from GUI-based display settings.

In this tutorial, I will describe how to find screen resolution in Linux desktop environment.

Method One: xdyinfo

One way to determine monitor resolution is via xdpyinfo , a command-line utility for showing information about an X server, including current display resolution. To check the current screen resolution from the command line, simply run:

$ xdpyinfo | grep "dimensions" | awk '< print $2 >'

Method Two: xrandr

The second screen resolution command is xrandr , a command-line interface for RandR (short for «X Resize, Rotate and Reflect Extension»). The xrandr command can show you the current screen resolution, as well as all possible display settings.

Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192 LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 194mm 1366x768 60.0*+ 40.1 1360x768 59.8 60.0 1024x768 60.0 800x600 60.3 56.2 640x480 59.9 VGA1 disconnected (normal left inverted right x axis y axis) HDMI1 disconnected (normal left inverted right x axis y axis) DP1 disconnected (normal left inverted right x axis y axis)

As you can see above, if you run xrandr command without any argument, you can get a list of all available screen resolutions. The currently set screen resolution is indicated with * marker. Therefore, to find the current display resolution only, use the following command.

Method Three: Display Settings

Every Linux desktop environment comes with its own GUI-based system settings, including display settings. Thus, you can use GUI-based display settings to determine the current screen resolution. To launch GUI-based display settings, you can use desktop-specific command line interface as demonstrated below.

To launch display settings on GNOME desktop environment, use either of the following commands:

$ gnome-control-center display

To launch display settings on KDE desktop environment, run:

To launch display settings on LXDE desktop environment, run:

To launch display settings on Xfce desktop environment, run:

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Источник

Linux Command Show Screen Resolution

This tutorial will show you how to get your screen or monitor resolution using command in linux , 4 command will be include, xrandr , xdpyinfo , xwininfo , xprop , all of them are X11 commands .

Use xrandr command

xrandr which stands X11 Resize and Rotate which is used to set the size, orientation and/or reflection of the outputs for a screen. It can also set the screen size.

And if we run it without any option, it will dump the state of the outputs, showing the existing modes for each of them.

j@ubuntu2004:~$ xrandr Screen 0: minimum 1 x 1, current 1914 x 884, maximum 16384 x 16384 Virtual1 connected primary 1914x884+0+0 (normal left inverted right x axis y axis) 0mm x 0mm 1914x884 60.00*+ 2560x1600 59.99 1920x1440 60.00 1856x1392 60.00 1792x1344 60.00 1920x1200 59.88 1600x1200 60.00 1680x1050 59.95 1400x1050 59.98 1280x1024 60.02 1440x900 59.89 1280x960 60.00 1360x768 60.02 1280x800 59.81 1152x864 75.00 1280x768 59.87 1024x768 60.00 800x600 60.32 640x480 59.94 j@ubuntu2004:~$ 

If there are multiple monitors ,each one will be displayed individually , like screen 0 , screen 1 etc.

Читайте также:  Alt tab windows linux

too many outputs, try below command to grep out only required information.

j@ubuntu2004:~$ xrandr | fgrep '*' 1914x884 60.00*+ j@ubuntu2004:~$ 

use xdpyinfo command

Xdpyinfo is a utility for displaying information about an X server. It is used to examine the capabilities of a server, the predefined values for various parameters used in communicating between clients and the server, and the different types of screens and visuals that are available.

By default, numeric information (opcode, base event, base error) about protocol extensions is not displayed.

Similarly to list resolution only ,try below command

j@ubuntu2004:~$ xdpyinfo | grep dimensions dimensions: 1914x884 pixels (506x234 millimeters) j@ubuntu2004:~$ 

Same as xrandr if there are multiple monitors , each one’s resolution will be displayed individually .

use command xwininfo

Xwininfo stands X11 windows information which is a utility for displaying information about windows. In the X Window System, every window is contained within another window, called its parent. This makes the windows form a hierarchy. The root window is the root of this hierarchy. It is as large as the screen, and all other windows are either children or descendants of it.

The output of this command looks like below:

j@ubuntu2004:~$ xwininfo -root xwininfo: Window id: 0x405 (the root window) (has no name) Absolute upper-left X: 0 Absolute upper-left Y: 0 Relative upper-left X: 0 Relative upper-left Y: 0 Width: 1914 Height: 884 Depth: 24 Visual: 0x21 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x20 (installed) Bit Gravity State: ForgetGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +0+0 -0+0 -0-0 +0-0 -geometry 1914x884+0+0 j@ubuntu2004:~$ 

Compare to xrandr and xdpyinfo , xwininfo just shows the window information of root window , so if you have more than one monitors it can’t show every monitor’s resolution.

Use command xprop

The xprop utility is for displaying window and font properties in an X server. One window or font is selected using the command line arguments or possibly in the case of a window, by clicking on the desired window. A list of properties is then given, possibly with formatting information.

The outputs of this command maybe very long you can use pipe and more command to find required information

Or just use below command to show your screen size only

j@ubuntu2004:~$ xprop -root _NET_DESKTOP_GEOMETRY _NET_DESKTOP_GEOMETRY(CARDINAL) = 1914, 884 j@ubuntu2004:~$ 

Conclusion

Now we have showed to how to find your screen or display resolution using command in linux , above examples already tested in Ubuntu/Gnome and Redhat Linux/KDE . If you still have queries ,feel free to leave a comment.

Linux Tutorials

Linuxtutorials is a Linux Sysadmin and DevOps blog that publishes articles and Tutorials about services ,commands, KDE,Gnome etc.

Источник

Оцените статью
Adblock
detector