Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've been trying to figure out the size of a window for use in a small script. My current technique is using wmctrl -lG to find out the dimensions. However, the problem is this:

The x and y figures it gives are for the top left of the window decorations, while the height and width are for just the content area. This means that if the window decorations add 20px of height and 2px of width, wmctrl will report a window as being 640x480, even if it takes up 660x482 on screen. This is a problem because my script's next step would be to use that area to tell ffmpeg to record the screen. I would like to avoid hardcoding in the size of the window decorations from my current setup.

What would suit is either a method to get the size of the window decorations so I can use them to figure out the position of the 640x480 content area, or a way to get the position of the content area directly, not that of the window decorations.

This horribly-rough not-at-all-to-scale diagram should illustrate:

share|improve this question
1  
I mixed up height and width in the figures for the diagram. –  Macha Jun 1 '11 at 16:44
add comment

1 Answer

up vote 10 down vote accepted

The following script will give you the top-left screen co-ords and size of the window (without any decoration). . . . xwininfo -id $(xdotool getactivewindow) contains enough information for you.


#!/bin/bash
# Get the coordinates of the active window's
#    top-left corner, and the window's size.
#    This excludes the window decoration.
  unset x y w h
  eval $(xwininfo -id $(xdotool getactivewindow) |
    sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
           -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
           -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
           -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
  echo -n "$x $y $w $h"
#
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.