//! Global toplevel stacking order on `Windows`: promote-to-top, remove, and
//! index lookup over the `toplevel_z_order` list. That list is the single
//! source of truth for Wayland-vs-Xwayland stacking and occlusion; the field
//! lives on `Windows` and is read directly by the hit-test and render paths,
//! so these three primitives are the only writers.

use super::*;

impl Windows {
    pub fn z_promote(&mut self, surface: &WlSurface) {
        self.toplevel_z_order.retain(|s| s != surface);
        self.toplevel_z_order.push(surface.clone());
    }

    pub fn z_remove(&mut self, surface: &WlSurface) {
        self.toplevel_z_order.retain(|s| s != surface);
    }

    pub(super) fn z_index(&self, surface: &WlSurface) -> Option<usize> {
        self.toplevel_z_order.iter().position(|s| s == surface)
    }
}
