tony / oxwm

Branch: 52048f6
Switch branches/tags
master
tonybtw Updated for commit message requests and added floating (normie layout) and bind to toggle layouts. 0335582 2025-10-25
49 lines · 1.1 KB Raw Blame History
1 pub mod normie;
2 pub mod tiling;
3
4 use x11rb::protocol::xproto::Window;
5
6 pub struct GapConfig {
7 pub inner_horizontal: u32,
8 pub inner_vertical: u32,
9 pub outer_horizontal: u32,
10 pub outer_vertical: u32,
11 }
12
13 pub const TILING: &str = "tiling";
14 pub const NORMIE: &str = "normie";
15 pub const FLOATING: &str = "floating";
16
17 pub fn layout_from_str(s: &str) -> Result<Box<dyn Layout>, String> {
18 match s.to_lowercase().as_str() {
19 TILING => Ok(Box::new(tiling::TilingLayout)),
20 NORMIE | FLOATING => Ok(Box::new(normie::NormieLayout)),
21 _ => Err(format!("Unknown layout: {}", s)),
22 }
23 }
24
25 pub fn next_layout(current_name: &str) -> &'static str {
26 match current_name {
27 TILING => NORMIE,
28 NORMIE => TILING,
29 _ => TILING,
30 }
31 }
32
33 pub trait Layout {
34 fn arrange(
35 &self,
36 windows: &[Window],
37 screen_width: u32,
38 screen_height: u32,
39 gaps: &GapConfig,
40 ) -> Vec<WindowGeometry>;
41 fn name(&self) -> &'static str;
42 }
43
44 pub struct WindowGeometry {
45 pub x_coordinate: i32,
46 pub y_coordinate: i32,
47 pub width: u32,
48 pub height: u32,
49 }