Linux : Get window border height

1.8k views Asked by At

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

3

There are 3 answers

0
Zach On BEST ANSWER

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 !

0
konsolebox On

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

0
KLoop On

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