correctly calculate mouse position relative to the window