Noticed while investigating the situation that lead to D27109, vt(4) will switch away from the current window but never switch back if the console ends up being ungrabbed.
Resolve this by recording the active window in cngrab(), and restore it on the last cnungrab() if we actually switched away.
While I was hacking on this, I noticed that vt_allocate_keyboard will do a cnungrab/cngrab dance if it needs to. Yank out basically just the parts it needs and use those directly to avoid clobbering the pre-grab window state -- it just wants the keyboard restored.