-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunder
executable file
·34 lines (26 loc) · 878 Bytes
/
under
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
#!/bin/sh
#
# under
main() {
mouse="$(wmp)"
pointX=${mouse% *}
pointY=${mouse#* }
for wid in $( (lsw; lsw -o) | tac); do
windowX="$(wattr x "$wid")"
windowY="$(wattr y "$wid")"
# no match if the left and top edges are greater than X or Y
[ "$windowX" -gt "$pointX" ] && continue
[ "$windowY" -gt "$pointY" ] && continue
windowW="$(wattr w "$wid")"
windowH="$(wattr h "$wid")"
# no match if the right and bottom edges are less than X or Y
[ "$((windowX + windowW))" -lt "$pointX" ] && continue
[ "$((windowY + windowH))" -lt "$pointY" ] && continue
# print wid on detection if no args passed
[ "$#" -eq 0 ] && printf '%s\n' "$wid"
exit
done
# run args as command to shell as no window was detected
[ "$#" -gt 0 ] && sh -c "$@"
}
main "$@"