#!/bin/bash

WINDOW=`wmctrl -l | sort -k 4 | awk \
'{for (i=4; i<=NF; i++) printf("%s ",$i); printf("\n%s\n%s\n",$2,$1)}' \
| zenity  --width=600 --height=600 --title "Select window" \
    --list --text "" \
    --column "Window Name" --column "Desktop" --column "Window ID" --print-column 3`

if [ $? -eq 0 ]
then
    OP=`zenity --title "Select operation" \
    --list --text "" \
    --column 'Avaliable Operations:' 'Switch to' 'Bring here' 'Move to the top-left corner'`
    
    case $OP in
	('Switch to') wmctrl -i -a $WINDOW ;;
	('Bring here') wmctrl -i -R $WINDOW ;;
	('Move to the top-left corner') wmctrl -i -r $WINDOW -e 0,0,0,-1,-1; wmctrl -i -r $WINDOW -e 0,0,0,-1,-1; wmctrl -i -R $WINDOW;;
    esac

fi
