tony / oxwm

Branch: 2d0ce78
Switch branches/tags
master
tonybtw added grid layout and positional movements. turns out grid layout was easy to add thanks to rusts based idiommatic enum. and positional movements is a solved problem (peeked leftwm for source) 026dcd9 2025-11-07
87 lines · 2 KB Raw Blame History
1 pub mod grid;
2 pub mod normie;
3 pub mod tiling;
4
5 use x11rb::protocol::xproto::Window;
6
7 pub type LayoutBox = Box<dyn Layout>;
8
9 pub struct GapConfig {
10 pub inner_horizontal: u32,
11 pub inner_vertical: u32,
12 pub outer_horizontal: u32,
13 pub outer_vertical: u32,
14 }
15
16 pub enum LayoutType {
17 Tiling,
18 Normie,
19 Grid,
20 }
21
22 impl LayoutType {
23 pub fn new(&self) -> LayoutBox {
24 match self {
25 Self::Tiling => Box::new(tiling::TilingLayout),
26 Self::Normie => Box::new(normie::NormieLayout),
27 Self::Grid => Box::new(grid::GridLayout),
28 }
29 }
30
31 pub fn next(&self) -> Self {
32 match self {
33 Self::Tiling => Self::Normie,
34 Self::Normie => Self::Grid,
35 Self::Grid => Self::Tiling,
36 }
37 }
38
39 pub fn as_str(&self) -> &'static str {
40 match self {
41 Self::Tiling => "tiling",
42 Self::Normie => "normie",
43 Self::Grid => "grid",
44 }
45 }
46
47 pub fn from_str(s: &str) -> Result<Self, String> {
48 match s.to_lowercase().as_str() {
49 "tiling" => Ok(Self::Tiling),
50 "normie" | "floating" => Ok(Self::Normie),
51 "grid" => Ok(Self::Grid),
52 _ => Err(format!("Invalid Layout Type: {}", s)),
53 }
54 }
55 }
56
57 pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
58 let layout_type = LayoutType::from_str(s)?;
59 Ok(layout_type.new())
60 }
61
62 pub fn next_layout(current_name: &str) -> &'static str {
63 LayoutType::from_str(current_name)
64 .ok()
65 .map(|layout_type| layout_type.next())
66 .unwrap_or(LayoutType::Tiling)
67 .as_str()
68 }
69
70 pub trait Layout {
71 fn arrange(
72 &self,
73 windows: &[Window],
74 screen_width: u32,
75 screen_height: u32,
76 gaps: &GapConfig,
77 ) -> Vec<WindowGeometry>;
78 fn name(&self) -> &'static str;
79 fn symbol(&self) -> &'static str;
80 }
81
82 pub struct WindowGeometry {
83 pub x_coordinate: i32,
84 pub y_coordinate: i32,
85 pub width: u32,
86 pub height: u32,
87 }