Do you use let's encrypt?





6397 votes ~ 21 comments

 

Finding the dimensions of the X11 display

Posted by Anonymous on Wed 20 Apr 2005 at 06:16

Tags:

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

 

 


Re: Finding the dimensions of the X11 display
Posted by Anonymous (82.70.xx.xx) on Wed 20 Apr 2005 at 15:57
Gah, those last two have a rather useless use of grep..

Try xwininfo -root |awk '/Width/{print $2}' and xwininfo -root |awk '/Height/{print $2}' instead.

[ Parent | Reply to this comment ]

Re: Finding the dimensions of the X11 display
Posted by Steve (82.41.xx.xx) on Thu 21 Apr 2005 at 16:46
[ 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 is better
Posted by Anonymous (194.47.xx.xx) on Thu 21 Apr 2005 at 11:02
I think it's cleaner to use xdpyinfo for this; this can show the sizes of all your screens if you have more than one.
$ 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 ]

Re: xdpyinfo is better
Posted by Steve (82.41.xx.xx) on Thu 21 Apr 2005 at 16:48
[ 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 ]

Re: Finding the dimensions of the X11 display
Posted by rednecktek (65.40.xx.xx) on Mon 2 May 2005 at 16:15
This is something I use to set a roottail on my desktops (which are all diffferent widths). Hopefully this will help someone else. Of course, now I'll have to modify the expressions, now that I see a better way. ;)
#!/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 ]