Handle open/close events.