The function screen-active-p is the predicate for whether a screen is active.
Note
A screen is normally "active". It can become inactive only when it "dies", which can happen on X interface (GTK+ or Motif) when the X connection get broken for any reason.