#!/bin/bash
# $1 monitor number
# $2 from desktop
# $3 to desktop

################### NEED CONFIG #############################
monitors=3
#############################################################

################### AUTHOR, VERSION #########################
#Yokotashi aka lhc
#http://kanal.ucw.cz
#
#version 0.01, alpha
#licence GPL
##############################################################

#example wmctrl -lpG
#id      desktop PID  x,y-offs  wide heigh machine                                window title
#0x02000022  0 25252  1920 48   1920 1052 office32.anaconda.englab.brq.redhat.com root@intel-denlow-r-02:~/powerclamp_noperf_by5__2

#assuming there are no monitors on the top on another, so we care about x offset only
#the window is on the monitor if x-offset of it is on the monitor

#################### TODO ####################################
#check if all parameters are present and right
#################### TODO ####################################


if [ "$1" -le "0" ]; then
	echo "There is no monitor $1"
	exit
fi 
if ! [ "$1" -le "$monitors" ]; then 
	echo "There is no monitor $1"
	exit
fi

m="$1"
m_1="$((m - 1))"
 
if [ "$3" -eq "$2" ]; then
	#there is nothing to do
	echo -n ""
fi

ClusterDuck_ls_monitor "$1" | while read id desktop PID xoffs yoffs wide height machine title; do
	if [ "$desktop" -eq "$2" ]; then
		echo "moving #id from $2 to $3 window title: $title" 
		wmctrl -i -r "$id" -t "$3"
	fi	
done
