| 1 | pub mod normie; |
| 2 | pub mod tiling; |
| 3 | |
| 4 | use x11rb::protocol::xproto::Window; |
| 5 | |
| 6 | pub type LayoutBox = Box<dyn Layout>; |
| 7 | |
| 8 | pub struct GapConfig { |
| 9 | pub inner_horizontal: u32, |
| 10 | pub inner_vertical: u32, |
| 11 | pub outer_horizontal: u32, |
| 12 | pub outer_vertical: u32, |
| 13 | } |
| 14 | |
| 15 | pub const TILING: &str = "tiling"; |
| 16 | pub const NORMIE: &str = "normie"; |
| 17 | pub const FLOATING: &str = "floating"; |
| 18 | |
| 19 | pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> { |
| 20 | match s.to_lowercase().as_str() { |
| 21 | TILING => Ok(Box::new(tiling::TilingLayout)), |
| 22 | NORMIE | FLOATING => Ok(Box::new(normie::NormieLayout)), |
| 23 | _ => Err(format!("Unknown layout: {}", s)), |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | pub fn next_layout(current_name: &str) -> &'static str { |
| 28 | match current_name { |
| 29 | TILING => NORMIE, |
| 30 | NORMIE => TILING, |
| 31 | _ => TILING, |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | pub trait Layout { |
| 36 | fn arrange( |
| 37 | &self, |
| 38 | windows: &[Window], |
| 39 | screen_width: u32, |
| 40 | screen_height: u32, |
| 41 | gaps: &GapConfig, |
| 42 | ) -> Vec<WindowGeometry>; |
| 43 | fn name(&self) -> &'static str; |
| 44 | } |
| 45 | |
| 46 | pub struct WindowGeometry { |
| 47 | pub x_coordinate: i32, |
| 48 | pub y_coordinate: i32, |
| 49 | pub width: u32, |
| 50 | pub height: u32, |
| 51 | } |