-
Notifications
You must be signed in to change notification settings - Fork 16
/
underneath.sh
executable file
·41 lines (34 loc) · 1.05 KB
/
underneath.sh
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
#!/bin/sh
#
# wildefyr - 2016 (c) MIT
# print window id directly underneath mouse
# fuck sh
intCheck() {
test $1 -ne 0 2> /dev/null
test $? -ne 2 || return 1
}
# find current mouse location or check input for XY coordinates
test $# -eq 0 && {
pointerX="$(wmp | cut -d\ -f 1)"
pointerY="$(wmp | cut -d\ -f 2)"
} || {
intCheck $1 && pointerX=$1 || return 1
intCheck $2 && pointerY=$2 || return 1
}
# start from the currently highest stacked window
for wid in $(lsw | tac); do
windowX="$(wattr x $wid)"
windowY="$(wattr y $wid)"
# we won't get a match if the left and top edges are greater than X or Y
test "$windowX" -gt "$pointerX" && continue
test "$windowY" -gt "$pointerY" && continue
windowW="$(wattr w $wid)"
windowH="$(wattr h $wid)"
# we won't get a match if the right and bottom edges are less than X or Y
test "$((windowX + windowW))" -lt "$pointerX" && continue
test "$((windowY + windowH))" -lt "$pointerY" && continue
# print match!
printf '%s\n' "$wid"
unset -v wid
exit
done