Linux:获取窗口边框高度 [英] Linux : Get window border height
问题描述
我尝试在bash脚本中获取窗口的最大大小(即屏幕的大小减去屏幕边缘的面板的大小).我正在使用Kubuntu,但是如果它可以在任何linux系统上都可以,那就太好了.
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.
当前,我的解决方案是通过wmctrl最大化活动窗口:
Currently, my solution is to maximize the active window via wmctrl :
wmctrl -r :ACTIVE: -b add,maximized_horz,maximized_vert
然后通过xwininfo获取窗口的大小:
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).
所以我的问题是:
1-是否有删除窗口边框的命令? (我只知道手动操作)
1 - Is there a command to remove the border of a window ? (I only know how to do it manually)
2-是否有更好的方法可以做到这一点? (如果可以在不最大化窗口的情况下做到这一点,那就太好了
2 - Is there a better way to do this ? (if it can be done without maximizing a window it could be great)
预先感谢您的帮助
推荐答案
我意识到我所说的 border 实际上是标题栏...如果我使用xwininfo -stats
,我确实会边框宽度(在我的情况下为0).标题栏的高度(最大化窗口后)是在字段 Absolute left-left 中获得的.以下是预期的高度:
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))
感谢您的帮助!
这篇关于Linux:获取窗口边框高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!