use crate::{
core::{hooks::LayoutHook, State},
pure::geometry::Rect,
x::XConn,
Xid,
};
#[derive(Debug, Clone, Default)]
pub struct SpacingHook {
pub outer_px: u32,
pub inner_px: u32,
pub top_px: u32,
pub bottom_px: u32,
}
impl<X: XConn> LayoutHook<X> for SpacingHook {
fn transform_initial(&mut self, mut r: Rect, _: &State<X>, _: &X) -> Rect {
if r.w == 0 || r.h == 0 {
return r;
}
r.y += self.top_px as i32;
r.h = r.h - self.top_px - self.bottom_px;
shrink(r, self.outer_px)
}
fn transform_positions(
&mut self,
_: Rect,
positions: Vec<(Xid, Rect)>,
_: &State<X>,
_: &X,
) -> Vec<(Xid, Rect)> {
positions
.into_iter()
.map(|(id, r)| (id, shrink(r, self.inner_px)))
.collect()
}
}
fn shrink(r: Rect, px: u32) -> Rect {
if r.w == 0 || r.h == 0 {
return r;
}
Rect {
x: r.x + px as i32,
y: r.y + px as i32,
w: r.w - 2 * px,
h: r.h - 2 * px,
}
}