oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git
2,574 bytes raw
1
pub mod grid;
2
pub mod monocle;
3
pub mod normie;
4
pub mod tabbed;
5
pub mod tiling;
6
7
use x11rb::protocol::xproto::Window;
8
9
pub type LayoutBox = Box<dyn Layout>;
10
11
pub struct GapConfig {
12
    pub inner_horizontal: u32,
13
    pub inner_vertical: u32,
14
    pub outer_horizontal: u32,
15
    pub outer_vertical: u32,
16
}
17
18
pub enum LayoutType {
19
    Tiling,
20
    Normie,
21
    Grid,
22
    Monocle,
23
    Tabbed,
24
}
25
26
impl LayoutType {
27
    pub fn new(&self) -> LayoutBox {
28
        match self {
29
            Self::Tiling => Box::new(tiling::TilingLayout),
30
            Self::Normie => Box::new(normie::NormieLayout),
31
            Self::Grid => Box::new(grid::GridLayout),
32
            Self::Monocle => Box::new(monocle::MonocleLayout),
33
            Self::Tabbed => Box::new(tabbed::TabbedLayout),
34
        }
35
    }
36
37
    pub fn next(&self) -> Self {
38
        match self {
39
            Self::Tiling => Self::Normie,
40
            Self::Normie => Self::Grid,
41
            Self::Grid => Self::Monocle,
42
            Self::Monocle => Self::Tabbed,
43
            Self::Tabbed => Self::Tiling,
44
        }
45
    }
46
47
    pub fn as_str(&self) -> &'static str {
48
        match self {
49
            Self::Tiling => "tiling",
50
            Self::Normie => "normie",
51
            Self::Grid => "grid",
52
            Self::Monocle => "monocle",
53
            Self::Tabbed => "tabbed",
54
        }
55
    }
56
57
    pub fn from_str(s: &str) -> Result<Self, String> {
58
        match s.to_lowercase().as_str() {
59
            "tiling" => Ok(Self::Tiling),
60
            "normie" | "floating" => Ok(Self::Normie),
61
            "grid" => Ok(Self::Grid),
62
            "monocle" => Ok(Self::Monocle),
63
            "tabbed" => Ok(Self::Tabbed),
64
            _ => Err(format!("Invalid Layout Type: {}", s)),
65
        }
66
    }
67
}
68
69
pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
70
    let layout_type = LayoutType::from_str(s)?;
71
    Ok(layout_type.new())
72
}
73
74
pub fn next_layout(current_name: &str) -> &'static str {
75
    LayoutType::from_str(current_name)
76
        .ok()
77
        .map(|layout_type| layout_type.next())
78
        .unwrap_or(LayoutType::Tiling)
79
        .as_str()
80
}
81
82
pub trait Layout {
83
    fn arrange(
84
        &self,
85
        windows: &[Window],
86
        screen_width: u32,
87
        screen_height: u32,
88
        gaps: &GapConfig,
89
        master_factor: f32,
90
        num_master: i32,
91
        smartgaps_enabled: bool,
92
    ) -> Vec<WindowGeometry>;
93
    fn name(&self) -> &'static str;
94
    fn symbol(&self) -> &'static str;
95
}
96
97
#[derive(Clone)]
98
pub struct WindowGeometry {
99
    pub x_coordinate: i32,
100
    pub y_coordinate: i32,
101
    pub width: u32,
102
    pub height: u32,
103
}