Recently, a considerable effort has been made to determine the precise displacement criteria for three-fluid configurations in pores of angular cross section. These configurations may contain thick conducting fluid layers, such as oil layers residing between gas in the center and water in the corners of the pore. For pores of uniform, but arbitrary, wettability and in the absence of contact angle hysteresis, a precise thermodynamic criterion for the existence of such layers has been established. In this paper we derive similar criteria for layers in pores of nonuniform wettability, where additional and more complicated layer configurations arise. The criteria for formation and removal of layers are consistent with the capillary entry conditions for the accompanying three-phase bulk displacements, which is essential for accurate pore-scale modeling of three-phase flow. We consider the particular case of three-phase gas invasion in a star-shaped pore with a specific choice of interfacial tensions and contact angles. For this case all possible fluid configurations arise, but only if the water-wet surface in the pore corners is small. Copyright 2007 by the American Geophysical Union.