#!/bin/bash

# focus last POS opened window

win_list=$( wmctrl -lx | grep "pos.Pos" | awk '{print $1}')

IDs=$(xprop -root|grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
IDs=(${IDs##*#})

for (( idx=${#IDs[@]}-1 ; idx>=0 ; idx-- )) ; do
  for i in $win_list; do
    if [ $((i)) = $((IDs[idx])) ]; then
      wmctrl -ia $i
      exit 0
    fi
  done
done

exit 1

