-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher
executable file
·157 lines (138 loc) · 4.42 KB
/
watcher
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/sh
#
# watcher
usage() {
base=$(basename "$0")
cat >&2 << EOF
Usage:
$base
EOF
[ $# -eq 0 ] || exit "$1"
}
debug() {
wew | while read -r ev wid; do
NAME="$(atomx WM_NAME "$wid")"
CLASS="$(atomx WM_CLASS "$wid")"
echo "$ev" "$wid" "$NAME" "$CLASS"
done
}
# add delay and to execute in the background
addgroup() {
sleep 2
# test if window has appeared and add to group
wattr m "$wid" && group -a "$1" "$2"
}
main() {
. fwmrc
wmenv
wmgaps
# focus immediately
focus -w "$(under)"
wew | while read -r ev wid; do
case "$ev" in
CREATE)
NAME="$(atomx WM_NAME "$wid")"
CLASS="$(atomx WM_CLASS "$wid")"
if wattr o "$wid"; then
case "$CLASS" in
lemonbar)
chwso -l "$wid"
;;
esac
fi
if ! wattr o "$wid"; then
# autogroups
[ -f "$autogroup" ] && {
while read -r line; do
group=${line% *}
class=${line#* }
[ "$class" = "$CLASS" ] && {
addgroup "$group" "$wid" &
break
}
done < "$autogroup"
}
# position
case "$CLASS" in
qutebrowser)
[ "$(wattr xywh "$wid")" = "50 50 800 600" ] && {
wrs 200 200 "$wid"
move center "$wid"
} || {
move left "$wid" "$PRI"
}
;;
gl)
sleep 0.22
;;
discord|Steam)
continue
;;
obs)
chwb -s "$BW" -c "$INACTIVE" "$wid"
chwso -r "$wid"
continue
;;
dragon)
move center "$wid"
wmv -a $(wmp) "$wid"
continue
;;
win10)
move full "$wid" "$PRI"
continue
;;
google-chrome)
move center "$wid" "$PRI"
;;
steam_app_1182480)
group -u 8
continue
;;
"Wine System Tray")
group -u 8
continue
;;
steam_app_*)
move full "$wid" "$PRI"
continue
;;
# origin
solaar)
group -u 8
continue
;;
urxvt)
case "$NAME" in
"calender")
move -bl "$wid" "$PRI"
;;
"cava"|"volbar")
move -br "$wid" "$PRI"
;;
esac
wmv -a $(wmp) "$wid"
;;
*)
wmv -a $(wmp) "$wid"
;;
esac
focus -w "$wid" nojump
fi
;;
UNMAP|DESTROY)
# add way to retrieve group id that wid belonged to
;;
ENTER)
if [ "$wid" != "$(pfw 2> /dev/null)" ]; then
wattr o "$wid" || focus -w "$wid" nojump
fi
;;
esac
done
}
autogroup="$HOME/.autogroup"
case "$1" in
-d|debug) debug ;;
esac
main "$@"