Finding the dimensions of the X11 display
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).
Try xwininfo -root |awk '/Width/{print $2}' and xwininfo -root |awk '/Height/{print $2}' instead.
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
I just showed what I'm used to using - I guess you're right though, my piping skillz need work!
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
$ xdpyinfo | grep dimensions dimensions: 1280x960 pixels (322x241 millimeters) $It also shows the screen size in millimeters (you have your system configured correctly, right?)
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
That's a better tool for this specific use, the advantage of my approach is that you can use it for arbitary windows.
xdpyinfo only works for the desktop. I guess I should have mentioned it though, so thanks for bringing it up.
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
#!/bin/sh
WIDTH=`xwininfo -root | grep Width | cut -d":" -f2`
WIDTH=`expr $WIDTH - 20`
WIDTH=${WIDTH}"x150-10-50"
root-tail -g $WIDTH /dev/xconsole,green /dev/emerg,red /dev/kerninfo,blue &
[ Parent | Reply to this comment ]