-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocus
executable file
·104 lines (87 loc) · 2.16 KB
/
focus
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
#
# focus
usage() {
base="$(basename "$0")"
cat >&2 << EOF
Usage:
$ $base -w | wid : Focus given window id.
$ $base -n | next : Focus the next window in stack.
$ $base -c | cycle : Focus the next window in stack on the same screen.
$ $base -p | prev : Focus the previous window in stack.
$ $base -h | help : Show this help.
EOF
[ $# -eq 0 ] || exit "$1"
}
window() {
wid="$1"
if widCheck "$wid"; then
[ "$wid" != "$PFW" ] && focus
else
exit 1
fi
}
next() {
wid="$(lsw | head -n 1)"
focus
}
prev() {
wid="$(lsw | tail -n 2 | head -n 1)"
focus
}
cycle() {
wid="$(lsw | grep "$(listwindows)" | head -n 1)"
focus
}
swap() {
wid="$(lsw | grep -v "$(listwindows)" | tail -n 1)"
focus
}
focus() {
# move mouse to center of new window
# be as responsive as possible to user input
wtf "$wid"
if [ -z "$nojump" ]; then
chwso -r "$wid"
wmp -a $(($(wattr x "$wid") + $(wattr w "$wid") / 2 + BW)) \
$(($(wattr y "$wid") + $(wattr h "$wid") / 2 + BW))
fi
# no border when wid is found to be fullscreen
if [ "$(atomx MODE "$wid")" = "full" ]; then
chwb -s "$BW" -c "$INACTIVE" "$PFW"
chwb -s 0 "$wid"
else
# set border when focusing from a fullscreen wid
if [ "$(atomx MODE "$PFW")" = "full" ]; then
chwb -s 0 "$PFW"
chwb -s "$BW" -c "$ACTIVE" "$wid"
else
# normal focusing
chwb -s "$BW" -c "$INACTIVE" "$PFW"
chwb -s "$BW" -c "$ACTIVE" "$wid"
fi
fi
}
unfocus() {
wtf "$(lsw -r)"
chwb -s "$BW" -c "$INACTIVE" "$PFW"
}
main() {
. fwmrc
wmenv
wmcolours
case "$3" in
nojump) nojump=1 ;;
esac
case "$1" in
-w|--wid|wid) window "$2" ;;
-n|--next|next) next ;;
-p|--prev|prev) prev ;;
-s|--swap|swap) swap ;;
-c|--cycle|cycle) cycle ;;
-u|--unfocus|unfocus) unfocus ;;
-h|--help|help) usage 0 ;;
*) usage 1 ;;
esac
}
main "$@"