How to limit cursor to a window or display?

I have figured out a bandaid sort of the way but it is here I must believe there should be a better way.