New hooks focus-in-hook, focus-out-hook.
These are normal hooks run when an Emacs frame gains or
loses input focus.
Cool. I think the lack of such a hook is what was preventing an implementation of "save all buffers" when the user clicks outside the window, something commonly used in IDEs.