The event at the bottom does just that..

Code:
on *:active:*:{
  if (!$istok(%popup_cids,$cid,32)) { 
    rebuildmenu
    set %popup_cids $addtok(%popup_cids,$cid,32) 
    ; Status window opening.
  }
  elseif (!$scid($lactivecid)) {
    rebuildmenu
    if ($remtok(%popup_cids,$lactivecid,1,32)) { set %popup_cids $v1 }
    else { unset %popup_cids }
    ; Status window closing.
  }
}


The only thing it doesn't address is things like /server -z, which opens a new server window but doesn't activate it, which is why I aliased the /server command at the top.

I wouldn't say any of that is "too round about" and it does what you ask for, no?