#!/bin/sh
function get_window_list() {
XAUTHORITY=$auth DISPLAY=:1 xwininfo -tree -root|grep '('|cut -d'(' -f1|awk '{print $1}'|grep ^0x
}

killall -STOP socat
t=$(mktemp /tmp/sido-sign-sak.XXXXXXXX)
auth=$(ps -eocmd | grep " :1 " | grep X | grep /var | grep auth | tr ' ' '\n' |grep ^/var/)
get_window_list > $t
XAUTHORITY=$auth DISPLAY=:1 xterm -name SAK -title SAK -bg red -fg black -e /usr/lib/sido/sido-sign &
pid=$!
sleep 4
t2=$(mktemp /tmp/sido-sign-sak.XXXXXXXX)
get_window_list > $t2
# XAUTHORITY=$auth DISPLAY=:1 xvkbd &
# XAUTHORITY=$auth DISPLAY=:1 xwininfo -tree -root
for w in $(sort -nr $t $t2 | uniq -u); do
    XAUTHORITY=$auth DISPLAY=:1 /usr/lib/sido/sido-show-window $w
done
wait $pid

killall -CONT socat
rm -f $t1 $t2
