Refactor pointerlock

Closes #5566.