private void EnsureModality() { bool activateLayer = true; for (int i = layerStack.Count - 1; i >= 0; --i) { // the topmost layer is always activated since we set activateLayer as true InputLayer layer = layerStack[i]; if (activateLayer) { layer.Activate(); } else { layer.Deactivate(); } // if the current layer is modal, then the succeeding layers are deactivated if (activateLayer && layer.IsModal) { activateLayer = false; } } }