Posted by Anonymous on Wed 20 Apr 2005 at 06:16
For some operations finding the dimensions of the current X11 Window System's root window (ie the desktop size) is important.
This can be useful for setting the size of wallpaper images, and other similar operations such as adding text to images.
The useful command xwininfo from the xbase-clients package can be used to do this.
The xwininfo command will display information about any named window, including the special "desktop" or "root" window:
skx@mystery:~$ /usr/X11R6/bin/xwininfo -root xwininfo: Window id: 0x3b (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: 1280 Height: 1024 Depth: 24 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 1280x1024+0+0
To obtain just the width and height you can use one of these commands:
# Get the dimensions skx@mystery:~$ /usr/X11R6/bin/xwininfo -root|grep '\(Width\|Height\)' Width: 1280 Height: 1024
Or to find them and work with them individually you could use something like this:
skx@mystery:~$ /usr/X11R6/bin/xwininfo -root|grep Width | awk '{ print $2}'
1280
skx@mystery:~$ /usr/X11R6/bin/xwininfo -root|grep Height | awk '{ print $2}'
1024
When invoked with no arguments you can simply click upon the window you wish to get information about, which can be useful if you don't want to specify the window by name (with the '-name' parameter).
This article can be found online at the Debian Administration website at the following bookmarkable URL:
This article is copyright 2005 Anonymous - please ask for permission to republish or translate.