Moved the code that dispatches a sdl event to after the new mouse state was changed. Fixes #849