3 ##############################################
4 ## dwm popup to choose between open windows ##
5 ## finally supports multi monitor ##
6 ##############################################
8 #############################################################
9 ## heavily commented, this was a nightmare to write ##
10 ## look at the git history of this file before touching it ##
11 #############################################################
13 # alt tab like behaviour with rofi
14 if ! [ -n "$1" ]; then
15 num=$(wmctrl -l | sed 's/ / /' | cut -d " " -f 4- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' |
16 rofi -dmenu -i -me-select-entry '' -me-accept-entry 'MousePrimary' -kb-row-down 'Alt+Tab,Down' -kb-row-up 'Alt+Ctrl+Tab,Up' -kb-accept-entry '!Alt_L,!Alt+Tab,Return' | cut -d '-' -f -1)
17 [[ -z "$num" ]] && exit
18 WID=$(wmctrl -l | sed -n "$num p" | cut -c -10)
23 echo "focus target $WID"
25 # focus $1, weird behaviour with multi monitor, see rest of the file
27 [[ $1 =~ "," ]] && echo "error focussing" && return 1
31 # single monitor like on a laptop is pretty straightforward
32 if ! [ -e ~/paperbenni/ismultimonitor ]; then
38 # convert decimal to hexadecimal
40 echo "0x0$(printf '%x\n' $1)"
43 # wmutils pfw sometimes returns one digit higher than xdotool
44 # but xdotool behaves weird with the root window in focus
46 if command pfw | grep -q '0x000001e1'; then
50 hex "$(xdotool getactivewindow)"
54 # warp mouse cursor to current window and get the monitor from the coordinates.
55 # more reliable than using window positions because of the root window always returning 0
58 XPOS=$(xdotool getmouselocation --shell | head -1 | grep -o '[0-9]*')
59 if [ "$XPOS" -gt "1919" ]; then
66 # sometimes there are trailing zeros, this only compares everything after these
68 NEW=$(echo "$1" | sed 's/^0x0*//g')
69 COMP=$(echo "$2" | sed 's/^0x0*//g')
70 echo "NEW $NEW COMP $COMP"
71 if [ "$NEW" = "$COMP" ]; then
78 # already on focused window?
79 wincomp "$WID" "$(pfw)" && exit
86 # solution for multi monitor glitches
87 if ! wincomp "$(pfw)" "$WID"; then
88 if ! [ "$OLDM" = "$(getmonitor)" ]; then
89 # do not attempt to focuswin the root window!!
90 if ! [ "$OLD" = "0x000001e1" ]; then
91 xdotool key 'super+comma'
93 xdotool key 'super+comma'
97 [ "$OLD" = "0x000001e1" ] || focuswin "$OLD"
98 xdotool key 'super+comma'
102 if ! [ "$OLD" = "0x000001e1" ]; then
103 if ! [ "$OLDM" = "$(getmonitor)" ]; then
104 xdotool key 'super+comma'
106 xdotool key 'super+comma'
111 xdotool key 'super+W'