guys. I know this is an old question, but I've been searching for the same thing and, after a lot of testing, I came up with my own script and, if you don't mind, I'd really like to share it with you.
#!/bin/sh
ScreenX=$(xdpyinfo | awk -F'[ x]+' '/dimensions:/{print $3}')
ScreenY=$(xdpyinfo | awk -F'[ x]+' '/dimensions:/{print $4}')
WindowX=$(xwininfo -id $(xdotool getactivewindow) | awk -F'[ :]+' '/Width:/{print $3}')
WindowY=$(xwininfo -id $(xdotool getactivewindow) | awk -F'[ :]+' '/Height:/{print $3}')
#WindowX=$(xwininfo -id $(xdotool getactivewindow) | sed -n -e "s/^ \+Width: \([0-9]\+\).*/\1/p")
#WindowY=$(xwininfo -id $(xdotool getactivewindow) | sed -n -e "s/^ \+Height: \([0-9]\+\).*/\1/p")
PositionX=$(((ScreenX/2)-(WindowX/2)))
PositionY=$(((ScreenY/2)-(WindowY/2)))
#echo "Screen X: " $ScreenX
#echo "Window X: " $WindowX
#echo "Position X: " $PositionX
#echo "Screen Y: " $ScreenY
#echo "Window Y: " $WindowY
#echo "Position Y: " $PositionY
wmctrl -r :ACTIVE: -e 1,$PositionX,$PositionY,$WindowX,$WindowY
Some commands are commented. I decided to keep them just for curiosity purposes because they worked very well while I was trying to figure out what to do (I'm not very familiar with bash scripts).
If anyone knows how to make this script cleaner and/or smoother, feel free to enlighten us. That'd be very cool.
I hope it's useful.
Cheers.