improvements to mouse handling (fixes bugs with moving mouse offscreen when drawing, zoom window bugs, etc.), also new lua functions from 77bf649fb448