+proc setupinnerwindow {} {
+ global innerwindow_after innerwindow
+ catch { after cancel $innerwindow_after }
+ catch { unset innerwindow_after }
+ if {[info exists innerwindow]} return
+ set children {}
+ foreach child [winfo children .i] {
+ if {![winfo exists $child]} continue
+ lappend children $child
+ }
+ if {[llength $children]==1} {
+ set innerwindow [lindex $children 0]
+ bind $innerwindow <Destroy> {
+ innerwindow-unavailable
+ catch { unset innerwindow }
+ after idle setupinnerwindow
+ }
+ innerwindow-available
+ } else {
+ after 5000 setupinnerwindow
+ }
+}
+