tony / oxwm

Branch: ef90096
Switch branches/tags
master
tonybanters Cleaned up consts to enum dd010d0 2025-10-29
81 lines · 1.8 KB Raw Blame History
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 enum LayoutType {
16 Tiling,
17 Normie,
18 }
19
20 impl LayoutType {
21 pub fn new(&self) -> LayoutBox {
22 match self {
23 Self::Tiling => Box::new(tiling::TilingLayout),
24 Self::Normie => Box::new(normie::NormieLayout),
25 }
26 }
27
28 pub fn next(&self) -> Self {
29 match self {
30 Self::Tiling => Self::Normie,
31 Self::Normie => Self::Tiling,
32 }
33 }
34
35 pub fn as_str(&self) -> &'static str {
36 match self {
37 Self::Tiling => "tiling",
38 Self::Normie => "normie",
39 }
40 }
41
42 pub fn from_str(s: &str) -> Result<Self, String> {
43 match s.to_lowercase().as_str() {
44 "tiling" => Ok(Self::Tiling),
45 "normie" | "floating" => Ok(Self::Normie),
46 _ => Err(format!("Invalid Layout Type: {}", s)),
47 }
48 }
49 }
50
51 pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
52 let layout_type = LayoutType::from_str(s)?;
53 Ok(layout_type.new())
54 }
55
56 pub fn next_layout(current_name: &str) -> &'static str {
57 LayoutType::from_str(current_name)
58 .ok()
59 .map(|layout_type| layout_type.next())
60 .unwrap_or(LayoutType::Tiling)
61 .as_str()
62 }
63
64 pub trait Layout {
65 fn arrange(
66 &self,
67 windows: &[Window],
68 screen_width: u32,
69 screen_height: u32,
70 gaps: &GapConfig,
71 ) -> Vec<WindowGeometry>;
72 fn name(&self) -> &'static str;
73 fn symbol(&self) -> &'static str;
74 }
75
76 pub struct WindowGeometry {
77 pub x_coordinate: i32,
78 pub y_coordinate: i32,
79 pub width: u32,
80 pub height: u32,
81 }