mre*_*req 8 window-management wmctrl
我创建了一些模仿 Unity Mod4+num行为的快捷方式。
wmctrl -xa Sublime || subl
Run Code Online (Sandbox Code Playgroud)
我不喜欢的是,一旦 sublime 运行,它总是聚焦第一个打开的窗口。我想聚焦最后一个“聚焦”窗口。与在 Unity 中相同。有国旗吗?
Rau*_*ner 14
此脚本执行您想要的操作:
#!/bin/bash
app=$1
workspace=$(wmctrl -d | grep '\*' | cut -d ' ' -f1)
win_list=$(wmctrl -lx | grep $app | grep " $workspace " | awk '{print $1}')
IDs=$(xprop -root|grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
IDs=(${IDs##*#})
for (( idx=${#IDs[@]}-1 ; idx>=0 ; idx-- )) ; do
for i in $win_list; do
if [ $((i)) = $((IDs[idx])) ]; then
wmctrl -ia $i
exit 0
fi
done
done
exit 1
Run Code Online (Sandbox Code Playgroud)
编辑:此脚本始终关注最后一个聚焦的窗口,而不是按照打开的顺序循环浏览窗口。
编辑 2:我修改了脚本(结果 wmctrl 和 xprop 使用略有不同的格式来显示十六进制数字)。
编辑 3:应用程序名称应取自 wmctrl -lx 的第三列以避免某些冲突。
我使用 制作了一个非常强大的应用程序切换器wmctrl。检查我的Ubuntu 论坛帖子和我的askubuntu 答案。
这是要启动的脚本:
#!/bin/bash
app_name=$1
workspace_number=`wmctrl -d | grep '\*' | cut -d' ' -f 1`
win_list=`wmctrl -lx | grep $app_name | grep " $workspace_number " | awk '{print $1}'`
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
# 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
Run Code Online (Sandbox Code Playgroud)