Implement wait_for_window function.