How to query X11 display resolution?

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.)


Check out display macros and screen macros from the Xlib manual.

Specifically:

  • From the first link: ScreenCount(), ScreenOfDisplay()
  • From the second link: WidthOfScreen(), HeightOfScreen()

This might be helpfull for cli and scripting

xwininfo -root

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

xrandr

Tags:

Linux

X11