我正在configurationxbindkeys使用快捷方式更改窗口焦点。 例如,我设法创build了一个专注于应用程序窗口的快捷方式,让我们说一个终结器窗口:
wmctrl -xa terminator
不幸的是,它始终聚焦在相同的终止窗口,阻止我循环终止窗口。
你能build议我一个关注终结者窗口的命令吗?如果再次按下,会循环遍历所有终止者窗口吗?
更新2013年3月30日
我修改了这个脚本http://lars.st0ne.at/blog/switch%20between%20windows%20within%20the%20same%20application来创build一个脚本
script.sh NAME
关注应用程序名称或在NAME的所有窗口中循环,如果它的一个窗口已经被聚焦,但是它不能正常工作。
这是脚本
win_class=$1 # 'terminator' # $1 # get list of all windows matching with the class above win_list=$(wmctrl -x -l | grep -i $win_class | awk '{print $1}' ) # get id of the focused window active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}') # get next window to focus on, removing id active switch_to=$(echo $win_list | sed s/.*$active_win_id// | awk '{print $1}') # if the current window is the last in the list ... take the first one if [ "$switch_to" == '' ];then switch_to=$(echo $win_list | awk '{print $1}') fi # switch to window wmctrl -i -a $switch_to
该脚本确实专注于应用程序的窗口,并循环遍历它们,直到它到达一个窗口,我想最后创build。 在那一点上,骑自行车不再工作了。
如果没有窗口焦点,我在脚本中发现了一个问题。
你可以尝试下面的修改脚本:
#!/bin/bash win_class=$1 # 'terminator' # $1 # get list of all windows matching with the class above win_list=$(wmctrl -x -l | grep -i $win_class | awk '{print $1}' ) # get id of the focused window active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}') if [ "$active_win_id" == "0" ]; then active_win_id="" fi # get next window to focus on, removing id active switch_to=$(echo $win_list | sed s/.*$active_win_id// | awk '{print $1}') # if the current window is the last in the list ... take the first one if [ "$switch_to" == '' ];then switch_to=$(echo $win_list | awk '{print $1}') fi # switch to window wmctrl -i -a $switch_to
这个剧本适合我。
无论如何,似乎脚本没有找到你的情况下的活动窗口。 因此,它设法切换到您的应用程序,但无法循环。 它切换到$ win_list中的第一个窗口,因为sed命令无法从$ win_list中删除活动窗口(以及之前的所有列表条目)。
尝试下面的命令:
xprop -root _NET_ACTIVE_WINDOW
输出应该是这样的:
_NET_ACTIVE_WINDOW(WINDOW): window id # 0x2400005
属性“_NET_ACTIVE_WINDOW”是EWMH标准的一部分。 请参阅: http : //standards.freedesktop.org/wm-spec/wm-spec-1.3.html
也许你正在使用非EWMH (扩展窗口管理器提示)兼容的窗口管理器! 你在用哪个WM?
…一些窗口管理器允许通过配置或插件启用EWMH兼容性。
通过st0ne修改脚本后,我有一个通用的版本(不需要指定app_name)。 希望对某人有用。 🙂
#!/bin/bash active_win_id=`xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}' | awk -F', ' '{print $1}'` if [ "$active_win_id" == "0" ]; then active_win_id="" fi app_name=`wmctrl -lx | grep $active_win_id | awk '{print $3}'` workspace_number=`wmctrl -d | grep '\*' | cut -d' ' -f 1` win_list=`wmctrl -lx | grep -ri $app_name | grep " $workspace_number " | awk '{print $1}'` # get next window to focus on, removing id active switch_to=`echo $win_list | sed s/.*$active_win_id// | awk '{print $1}'` # if the current window is the last in the list ... take the first one if [ "$switch_to" == "" ];then switch_to=`echo $win_list | awk '{print $1}'` fi if [[ -n "${switch_to}" ]] then (wmctrl -ia "$switch_to") & else if [[ -n "$2" ]] then ($2) & fi fi exit 0