Maybe it will be enough if you just save a pointer to the current active window somewhere?