在通过编译code linux的操作窗口的大小? [英] Manipulate window size in linux via compiled code?

查看:127
本文介绍了在通过编译code linux的操作窗口的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了几个剧本的一个窗口最大化到屏幕的一半大小(以方便放置窗口并排侧)使用xrandr,grep和wmctrl如下:

 #!/斌/庆典W =`xrandr 2  - ;的/ dev / null的| grep的'*'| grep的-Po'\\ D +(?= X)'`
H =`xrandr 2 - ;的/ dev / null的| grep的'*'| grep的-Po(小于?= X)\\ D +''
wmctrl -r:ACTIVE:-b删除,maximized_horz,最大化,VERT
wmctrl -r:ACTIVE:-e 0,0,0,$((W / 2)),$ H

有没有办法更本身做到这一点?该脚本以及我的桌面上,但在我的笔记本电脑有一个半秒滞后是一种恼人的。


解决方案

测试code

 #= W_H$(打印 - 1280×1024 0.0 *| awk的'/.*\\*$/{sub(/ * $ /,);子(×,); $ 1 = $ 1/2;打印}')
#W =$ {%W_H *}; H =$ {#W_H *}

实际code

 #匹配的awk只有行结束'*',删除一切从去年空间EOL,以X替换
#看起来W_H像640 1040,下面的分割空间焦炭填充正确的变种
W_H =$(xrandr | AWK'/\\*/{sub(/[0-9\\.*\\+]*$/,);分(×,); $ 1 = $ 1 / ;打印}')
W =$ {%W_H *}; H =$ {#W_H *}
wmctrl -r:ACTIVE:-b删除,maximized_horz,最大化,VERT
wmctrl -r:ACTIVE:-e 0,0,0,$ {白},$ {H}

请注意,我已经做了DIV里面AWK W的此外,反引号是POSIX壳pcated德$ P $。使您的生活更轻松,并使用$()的指挥substituton; - )

我希望这有助于。

I wrote a couple of scripts to maximize a window to half the size of the screen (to make it easy to place windows side-by-side) using xrandr, grep, and wmctrl as follows:

#!/bin/bash

w=`xrandr 2> /dev/null | grep '*' | grep -Po '\d+(?=x)'`
h=`xrandr 2> /dev/null | grep '*' | grep -Po '(?<=x)\d+'`
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized,vert
wmctrl -r :ACTIVE: -e 0,0,0,$((w / 2)),$h

Is there a way to do this more natively? The script works well on my desktop, but on my laptop there's a half-second lag that is kind of annoying.

解决方案

test code

# w_h="$(print -- "1280x1024 0.0*" | awk '/.*\*$/{sub(/ .*$/, "");sub("x"," ");$1=$1/2 ;print}')"
# w="${w_h% *}" ; h="${w_h#* }"

actual code

# awk matches only line ending with '*', remove everything from last space to EOL, replace X with " "
# w_H looks like "640 1040", below splits on space char populating correct var
w_h="$(xrandr | awk '/\*/{sub(/[0-9\.*\+]*$/, ""); sub("x", " "); $1=$1/2; print}')"
w="${w_h% *}" ; h="${w_h#* }"
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized,vert
wmctrl -r :ACTIVE: -e 0,0,0,${w},${h}

Note that I have done the div on W inside awk. Also, backticks are deprecated in posix shells. Make your life easier and use $() for command substituton ;-)

I hope this helps.

这篇关于在通过编译code linux的操作窗口的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆