25

How can I get accurate window information in Linux? I know that I can use wmctrl to get a window's size, but the actual size of the window can vary due to window decorations. I need the following information and methods:

* precise window dimensions
* precise available screen space (excluding panels like gnome-panel)
* the ability to set a window to be a certain size, including decorations

What would be the best way to do this?

Thanks in advance!

4
  • If you are interested more in the python side, we can migrate this to our sister site about programming, StackOverflow.com. Just let us know.
    – Gnoupi
    Commented Jul 15, 2010 at 15:47
  • @Gnoupi: thanks, but this is actually a cross-post from SO, as a user suggested I might get a better answer here. The original question is at stackoverflow.com/questions/3233660/….
    – mellort
    Commented Jul 15, 2010 at 15:49
  • ok, I see. In this case, I think the python part of your question can be edited away. Answers on SU will most likely be using other commands, not programming. The question on SO should probably focus on asking how to do it in python.
    – Gnoupi
    Commented Jul 15, 2010 at 15:54
  • Get window dimension with decorations: unix.stackexchange.com/questions/14159/… Commented Aug 13, 2014 at 6:48

2 Answers 2

27

There are some command line programs that might help:

  • xwininfo: It gets you the size of the window excluding the decoration and the position absolute (to the screen) and relative (to the area for windows)
  • xdpyinfo: This gives far more information about your screen-device, than you ever want to know about. But it has somewhere in the output something like screen: #0 followed by dimension: 1024x768.
1
  • 1
    Is there a way to get information including the decoration?
    – Victor
    Commented Mar 27, 2012 at 23:49
6

> precise window dimensions

The following example (will work at least in sh, bash and zsh) will print window geometry with and without frame for all windows with "KWrite" somewhere in title.

windows="$(wmiface findNormalWindows "KWrite" "" "" "" "" "")"
for window in $(echo $windows); do
{
  echo $window
  wmiface framePosition $window
  wmiface frameSize $window
  wmiface windowPosition $window
  wmiface windowSize $window
  echo
} done

> precise available screen space (excluding panels like gnome-panel)

xrandr

For example:

xrandr | head -n1 | cut -d, -f2 | cut -d" " -f3-5

Output in my case:

4400 x 2560

Not sure how to exclude panels - if you have more than one monitor, they can be even in middle of virtual screen, so screen geometry without panels can be more complicated than "available screen space".

> the ability to set a window to be a certain size, including decorations

wmiface setFrameGeometry $window $x $y $width $height

Read wmiface README for even more possible commands.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .