1

I try to get in a bash script the maximal size of a window (i.e. the size of the screen minus the panels on the edges of the screen). I am using Kubuntu but if it could work for any linux system it would be great.

Currently, my solution is to maximize the active window via wmctrl :

wmctrl -r :ACTIVE: -b add,maximized_horz,maximized_vert

and then get the size of the window thanks to xwininfo :

xwininfo -id $(xdotool getactivewindow)

Unfortunately, I don't get the size of the window but the size of the window and it's border (if I remove the border, I get the expected value).

So my questions are :

1 - Is there a command to remove the border of a window ? (I only know how to do it manually)

2 - Is there a better way to do this ? (if it can be done without maximizing a window it could be great)

Thanks in advance for your help

Zach
  • 600
  • 5
  • 16
  • Do you mean `but the size of the window and (+) the border of the window`? – konsolebox Aug 29 '13 at 15:29
  • But you could actually just calculate it arithmetically but you have to tell us how data is really shown and what you want to take. With bash it should be possible. – konsolebox Aug 29 '13 at 15:45
  • Yes it's "and" instead of "minus" sorry. – Zach Aug 29 '13 at 16:08
  • Currently the only way to get the expected value is to remove the border. However, I don't know how to remove it with a command. Once the border is removed, I execute `$ xwininfo -id $(xdotool getactivewindow) | grep Height` and it gives me the value I want: `Height: 1015` – Zach Aug 29 '13 at 16:15
  • 1
    Did you try extracting the border width from the `-stats` option of `xwininfo`? – lurker Aug 29 '13 at 17:20

3 Answers3

3

I realised that what I was calling border was in fact the title bar... If I use xwininfo -stats I indeed get the border width (0 in my case). The title bar height (after maximizing the window) is obtained in the field Absolute upper-left. The following gives me the expected height :

eval $(xwininfo -id $(xdotool getactivewindow) | sed -n -e "s/^  Height: \+\([0-9]\+\).*/Height=\1/p" -e "s/^  Absolute upper-left Y:  \+\([0-9]\+\).*/HeightTitleBar=\1/p")
Height=$(($Height+$HeightTitleBar))

Thanks for your help !

Zach
  • 600
  • 5
  • 16
1

This would get your height, width and border width:

{ read __ WIDTH; read __ HEIGHT; read __ __ BORDER_WIDTH; } < <(xwininfo -id "$(xdotool getactivewindow)" | grep -o -e 'Height:.*' -e 'Width:.*' -e 'Border width:.*')
echo "Height: $HEIGHT, Width: $WIDTH, Border width: $BORDER_WIDTH"

With that you now have $HEIGHT, $WIDTH, and $BORDER_WIDTH. You could just re-calculate those with arithmetic expressions: http://tldp.org/LDP/abs/html/arithexp.html

konsolebox
  • 72,135
  • 12
  • 99
  • 105
0

I've only checked for KDE/Plasma, but when you xprop a window you can get the measurements of the decoration from one of these two entries (values are from my desktop):

_KDE_NET_WM_FRAME_STRUT(CARDINAL) = 0, 0, 41, 4

_NET_FRAME_EXTENTS(CARDINAL) = 0, 0, 41, 4
Amirhossein Yari
  • 2,054
  • 3
  • 26
  • 38
KLoop
  • 1