Optical switching by capillary condensation