Files
wldash/src/doublemempool.rs
T
Kenny Levinsen b53a909e1c Dynamic widget configuration and layout
1. Implement new layout API, replacing previous hard-coded layout.
2. Make the widgets (previously modules) configurable.
3. Split some widgets into smaller modules.
4. Configuration file (reluctantly JSON at time of writing).
5. More correct damage handling, copying damage to next buffer.
2019-09-06 21:54:04 +02:00

35 lines
849 B
Rust

use smithay_client_toolkit::utils::MemPool;
use wayland_client::protocol::wl_shm;
pub struct DoubleMemPool {
pool1: MemPool,
pool2: MemPool,
switch: bool,
}
impl DoubleMemPool {
pub fn new(shm: &wl_shm::WlShm) -> ::std::io::Result<DoubleMemPool> {
Ok(DoubleMemPool {
pool1: MemPool::new(shm, move || {})?,
pool2: MemPool::new(shm, move || {})?,
switch: false,
})
}
pub fn pool(&mut self) -> Option<(&mut MemPool, &mut MemPool)> {
let switch = self.switch;
self.switch = !self.switch;
let (last, cur) = if switch {
(&mut self.pool2, &mut self.pool1)
} else {
(&mut self.pool1, &mut self.pool2)
};
if cur.is_used() {
None
} else {
Some((last, cur))
}
}
}