问题
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
回答1:
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 !
回答2:
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
来源:https://stackoverflow.com/questions/18514989/linux-get-window-border-height