#!/bin/bash
# $1 monitor number
# monitor 1 is on the left

################### NEED CONFIG #############################
monitors=3
monitor[0]=0
monitor[1]=1920
monitor[2]=3840
monitor[3]=5120
#############################################################

################### 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. If you need that
#setup, you should rewrite tests below to be 2-dimensional.

monitors=3
monitor[0]=0
monitor[1]=1920
monitor[2]=3840
monitor[3]=5120

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

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))"
 
wmctrl -lpG | while read id desktop PID xoffs yoffs wide height machine title; do
	if [ "$xoffs" -lt "${monitor[$m]}" -a "$xoffs" -ge "${monitor[$m_1]}" ]; then
		echo "$id $desktop $PID $xoffs $yoffs $wide $height $machine $title" 
	fi
done
