
Unity의 Mod4+ num동작을 모방한 몇 가지 단축키를 만들었습니다.
wmctrl -xa Sublime || subl
내가 싫어하는 점은 일단 sublime이 실행되면 항상 처음 열린 창에 초점을 맞춘다는 것입니다. 마지막 "초점" 창에 초점을 맞추고 싶습니다. Unity와 동일합니다. 그에 대한 플래그가 있나요?
답변1
이 스크립트는 원하는 작업을 수행합니다.
#!/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
편집: 이 스크립트는 열린 순서대로 창을 순환하는 대신 항상 마지막으로 초점을 맞춘 창에 초점을 맞춥니다.
편집 2: 스크립트를 수정했습니다(wmctrl과 xprop는 16진수 표시에 약간 다른 형식을 사용하는 것으로 나타났습니다).
편집 3: 특정 충돌을 방지하려면 wmctrl -lx의 세 번째 열에서 앱 이름을 가져와야 합니다.
답변2
저는 wmctrl
. 내 확인우분투 포럼 게시물그리고 내아쿠분투 답변.
실행할 스크립트는 다음과 같습니다.
#!/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
답변3
나는 매우 편리하다고 생각되는 이전 답변을 모두 조합했습니다. 이를 통해 다음이 가능해집니다.
- 앱의 가장 최근에 초점을 맞춘 창에 초점을 설정합니다(Raul Laasner의 답변).해당 창에 아직 포커스가 없는 경우;
- 그렇지 않으면 앱의 다음 창으로 순환합니다(mreq의 응답).
- 앱 창이 없으면 하나를 엽니다(이제 이 경우 실행할 명령을 지정하는 선택적인 두 번째 인수가 있습니다).
스크립트는 다음과 같습니다.
#!/bin/bash
if [ $# -lt 1 ] ; then
echo "Usage : $0 <window name> [<command to run if there is no window with that name>]"
exit 1
fi
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}'`
# Get the id of the active window (i.e., window which has the focus)
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
# If the window currently focused matches the first argument, seek the id of the next window in win_list which matches it
if [[ "$win_list" == *"$active_win_id"* ]]; then
# Get next window to focus on
# (sed removes the focused window and the previous windows from the list)
switch_to=`echo $win_list | sed s/.*$active_win_id// | awk '{print $1}'`
# If the focused 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 the currently focused window does not match the first argument
else
# Get the list of all the windows which do
win_list=$(wmctrl -lx | grep $app_name | awk '{print $1}')
IDs=$(xprop -root|grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
IDs=(${IDs##*#})
# For each window in focus order
for (( idx=${#IDs[@]}-1 ; idx>=0 ; idx-- )) ; do
for i in $win_list; do
# If the window matches the first argument, focus on it
if [ $((i)) = $((IDs[idx])) ]; then
wmctrl -ia $i
exit 0
fi
done
done
fi
# If a window to focus on has been found, focus on it
if [[ -n "${switch_to}" ]]
then
(wmctrl -ia "$switch_to") &
# If there is no window which matches the first argument
else
# If there is a second argument which specifies a command to run, run it
if [[ -n "$2" ]]
then
($2) &
fi
fi
exit 0
사용법의 예:
focus_window.sh vlc vlc
focus_window.sh gnome-control-center gnome-control-center
focus_window.sh gnome-terminal gnome-terminal
답변4
답변이 늦었지만 제 경우에는 Firefox를 사용하여 정상적으로 작동했습니다.
/usr/lib/firefox/firefox && sleep 0.5 && wmctrl -ia $(wmctrl -l Firefox | grep "Mozilla Firefox" | sort -r | head -n 1 | cut -d " " -f 1)
설명:
/usr/lib/firefox/firefox
- 파이어폭스를 엽니다
sleep 0.5
- 창문이 열릴 때까지 약간의 시간을 줍니다.
wmctrl -ia
- 특정 창 ID에 집중
$(wmctrl -l Firefox | grep "Mozilla Firefox" | sort -r | head -n 1 | cut -d " " -f 1)
- 내 경우에는 홈페이지에 열려 있는 마지막 창 ID를 가져오므로 이름은 "Mozilla Firefox"입니다.