use crate::pure::{
geometry::{Rect, RelativeRect},
Stack, Workspace,
};
use std::{collections::HashMap, fmt, hash::Hash};
#[derive(Default, Debug, Clone)]
pub struct Screen<C> {
pub(crate) index: usize,
pub workspace: Workspace<C>,
pub(crate) r: Rect,
}
impl<C: fmt::Display> fmt::Display for Screen<C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Screen({}: {:?}):\n - workspace: {}",
self.index, self.r, self.workspace
)
}
}
impl<C> Screen<C> {
pub fn index(&self) -> usize {
self.index
}
pub fn geometry(&self) -> Rect {
self.r
}
}
impl<C> Screen<C>
where
C: Clone + Eq + Hash,
{
pub fn screen_clients(&self, floating: &HashMap<C, RelativeRect>) -> ScreenClients<C> {
ScreenClients {
floating: self
.workspace
.clients()
.flat_map(|c| floating.get(c).map(|r| (c.clone(), *r)))
.collect(),
tiling: self
.workspace
.stack
.as_ref()
.and_then(|st| st.from_filtered(|c| !floating.contains_key(c))),
tag: self.workspace.tag.clone(),
r_s: self.r,
}
}
}
#[derive(Debug)]
pub struct ScreenClients<C> {
pub floating: Vec<(C, RelativeRect)>,
pub tiling: Option<Stack<C>>,
pub tag: String,
pub r_s: Rect,
}