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!

  • 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 Jul 15 '10 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 Jul 15 '10 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 Jul 15 '10 at 15:54
  • Get window dimension with decorations: unix.stackexchange.com/questions/14159/… – Ciro Santilli 郝海东冠状病六四事件法轮功 Aug 13 '14 at 6:48

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.
| improve this answer | |
  • Is there a way to get information including the decoration? – Victor Mar 27 '12 at 23:49

> 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
} done

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


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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