Clamp into range for the x and y.  This appears to work and should work in theory for any number of monitors in any configuration.  We will need to include both xrandr and xinerama for completeness.