views:

88

answers:

1

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? I am interested in working with Python so something with a python module would be preferred.

Thanks in advance!

+1  A: 

The best way is to use X11/xlib directly (Documentation: http://tronche.com/gui/x/xlib/ )

Beginning from the Root you can walk through a tree via XQueryTree() and get the window Attributes via XGetWindowAttributes () / XGetGeometry ().

Ok, this is a C-Library, but there is also a Python Port: http://python-xlib.sourceforge.net/?page=documentation

nob
How would X11 know the size of the window decorations?
mellort
Because the windows are organised in an Tree, and if you substract the size of an child window from its parent window you get the size of the decorations. Often things like close-buttons in the decoration are also X11-Windows.`Root-Window (your Desktop) - Top-Level-Window (window with Deco) - Child windows (may be part of the decoration or content area etc.) - Buttons etc`This approach does not work always, e.g. when Compiz is on, Compiz paints the window decoration circumventing X11 (but I am not sure on that)
nob
But you can try an easy dump-testprogram and figure out in which part of the window hirarchy you are interested in. You can even grab its contents via XGetImage().
nob