#!/bin/bash
# set field separator to newline
ORIGIFS=${IFS}
IFS=$'\n'
#-----------------------------------------------------------
# get current desktop and width
cdesk=-1
width=-1
for k in `wmctrl -d | cut -d' ' -f1,3,12`
do
if [ "`echo ${k} | cut -d' ' -f2`" == "*" ]
then
cdesk=`echo ${k} | cut -d' ' -f1`
size=`echo ${k} | cut -d' ' -f3`
width=`echo ${size} | cut -d'x' -f1`
height=`echo ${size} | cut -d'x' -f2`
fi
done
(( height -= 26 ))
#-----------------------------------------------------------
# get number of windows on screen
winCount=0
for k in `wmctrl -l | cut -d' ' -f3`
do
if [ ${k} == ${cdesk} ]
then
(( winCount++ ))
fi
done
if [ ${winCount} -ne 0 ]
then
avgWidth=$(( width / winCount ))
else
avgWidth=${width}
fi
(( avgWidth -= 3 ))
#-----------------------------------------------------------
col=2
for k in `wmctrl -l | cut -d' ' -f1,3`
do
if [ "`echo ${k} | cut -d' ' -f2`" == "${cdesk}" ]
then
cwin="`echo ${k} | cut -d' ' -f1`"
wmctrl -i -r ${cwin} -e 0,${col},0,$((avgWidth)),${height}
(( col += avgWidth ))
fi
done
#-----------------------------------------------------------
IFS=${ORIGIFS}
#-----------------------------------------------------------