jay-compositor 1.15.0

The Jay compositor
use crate::utils::numcell::NumCell;

#[derive(Default)]
pub struct ThresholdCounter {
    counter: NumCell<usize>,
}

impl ThresholdCounter {
    fn inc(&self) -> bool {
        self.counter.fetch_add(1) == 0
    }

    fn dec(&self) -> bool {
        self.counter.fetch_sub(1) == 1
    }

    pub fn adj(&self, inc: bool) -> bool {
        if inc { self.inc() } else { self.dec() }
    }

    pub fn active(&self) -> bool {
        self.counter.get() > 0
    }
}