-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetnextwindidinactvclass
executable file
·72 lines (60 loc) · 1.67 KB
/
getnextwindidinactvclass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
#
# File:
# getnextwindidinactvclass
#
# Description:
# Get the ID of the next window in the class of the active window.
#
# Options:
# -n [name] return only IDs of windows with titles partially matched by
# [name]
#
# Returns:
# ID of the next window in class; ID of the active window if no other windows
# in the class exist
#
while getopts n: OPT; do
case "${OPT}" in
n) OPT_WIND_NAME="${OPTARG}"
;;
esac
done
shift $((OPTIND - 1))
getActvWindId() {
echo "$(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5 | rev | cut -c 2- | \
rev | sed 's/^0x/0x0/')"
}
ACTV_WIND_ID="$(getActvWindId)"
getWindIdsInClass() {
echo "$(wmctrl -lx | awk -v class="${1}" '$3 ~ class {print $1}')"
}
getWindClassById() {
echo "$(xprop -id "${1}" WM_CLASS | sed -n \
's/[^"]*"\([^"]*\)",\s"\([^"]*\)"/\1.\2/p')"
}
CLASS_WIND_IDS=($(getWindIdsInClass "$(getWindClassById "${ACTV_WIND_ID}")"))
if [ -n "${OPT_WIND_NAME}" ]; then
getWindNameById() {
echo "$(xprop -id "${1}" WM_NAME 2>/dev/null | sed -n \
's/[^"]*"\(.*\)./\1/p')"
}
for windId in "${CLASS_WIND_IDS[@]}"; do
windName="$(getWindNameById "${windId}")"
if [[ "${windName}" = *"${OPT_WIND_NAME}"* ]]; then
clssWindIdsTmp+=("${windId}")
fi
done
CLASS_WIND_IDS=("${clssWindIdsTmp[@]}")
fi
for indx in ${!CLASS_WIND_IDS[@]}; do
if [ "${CLASS_WIND_IDS[${indx}]}" = "${ACTV_WIND_ID}" ]; then
clssWindIdsActvWindIdPos="${indx}"
break
fi
done
if [ "${clssWindIdsActvWindIdPos}" -eq $(("${#CLASS_WIND_IDS[@]}" - 1)) ]; then
echo "${CLASS_WIND_IDS[0]}"
else
echo "${CLASS_WIND_IDS[$((clssWindIdsActvWindIdPos + 1))]}"
fi