Track mouse state via a state machine

This is a very alpha version of this state processing,
but it works for now
anal whitespace