Implement PortletListener and check the WindowState, see the PortletDemo for an example.
Best Regards, Marc