#!/bin/sh
AREASDIR="$HOME/.areasrc"
WORKSPACE=`wmctrl -X`
AREAS=`wc -l $AREASDIR/$WORKSPACE | awk '{ print $1 }'`

#not sure if this is only for kde, but my windows were displaced 
#in kde because of the borders (wmctrl moves the windows without calculating the decorations in kde)
#if kde is set to one then SIDEDIST and TOPDIST are subtracted from the positions, 20 and 5 work for me
if [ -f $AREASDIR/kde ]; then
KDE="1"
fi
SIDEDIST="5"
TOPDIST="20"

# Bereich gibt es nicht
if [ "$1" -gt "$AREAS" ]
then
  exit 0
fi

AREA=`head -$1 $AREASDIR/$WORKSPACE | tail -1`

NEWPOSX=`echo $AREA | cut -d " " -f 1`
NEWPOSY=`echo $AREA | cut -d " " -f 2`
NEWPOSW=`echo $AREA | cut -d " " -f 3`
NEWPOSH=`echo $AREA | cut -d " " -f 4`
if [ "x$KDE" == "x1" ]; then
  wmctrl -r :ACTIVE: -e 0,$((NEWPOSX-SIDEDIST)),$((NEWPOSY-TOPDIST)),$NEWPOSW,$NEWPOSH
else
  wmctrl -r :ACTIVE: -e 0,$NEWPOSX,$NEWPOSY,$NEWPOSW,$NEWPOSH
fi
