tony / oxwm

Branch: 0335582
Switch branches/tags
master
tonybtw Updated for commit message requests and added floating (normie layout) and bind to toggle layouts. 0335582 2025-10-25
81 lines · 2.6 KB Raw Blame History
1 use super::{GapConfig, Layout, WindowGeometry};
2 use x11rb::protocol::xproto::Window;
3
4 pub struct TilingLayout;
5
6 impl Layout for TilingLayout {
7 fn name(&self) -> &'static str {
8 super::TILING
9 }
10
11 fn arrange(
12 &self,
13 windows: &[Window],
14 screen_width: u32,
15 screen_height: u32,
16 gaps: &GapConfig,
17 ) -> Vec<WindowGeometry> {
18 let window_count = windows.len();
19 if window_count == 0 {
20 return Vec::new();
21 }
22
23 if window_count == 1 {
24 let x = gaps.outer_horizontal as i32;
25 let y = gaps.outer_vertical as i32;
26 let width = screen_width.saturating_sub(2 * gaps.outer_horizontal);
27 let height = screen_height.saturating_sub(2 * gaps.outer_vertical);
28
29 vec![WindowGeometry {
30 x_coordinate: x,
31 y_coordinate: y,
32 width,
33 height,
34 }]
35 } else {
36 let mut geometries = Vec::new();
37
38 let master_width = (screen_width / 2)
39 .saturating_sub(gaps.outer_horizontal)
40 .saturating_sub(gaps.inner_horizontal / 2);
41
42 let master_x = gaps.outer_horizontal as i32;
43 let master_y = gaps.outer_vertical as i32;
44 let master_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
45
46 geometries.push(WindowGeometry {
47 x_coordinate: master_x,
48 y_coordinate: master_y,
49 width: master_width,
50 height: master_height,
51 });
52
53 let stack_count = window_count - 1;
54 let stack_x = (screen_width / 2 + gaps.inner_horizontal / 2) as i32;
55 let stack_width = (screen_width / 2)
56 .saturating_sub(gaps.outer_horizontal)
57 .saturating_sub(gaps.inner_horizontal / 2);
58
59 let total_stack_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
60
61 let total_inner_gaps = gaps.inner_vertical * (stack_count as u32 - 1);
62 let stack_height =
63 total_stack_height.saturating_sub(total_inner_gaps) / stack_count as u32;
64
65 for i in 1..window_count {
66 let stack_index = i - 1;
67 let y_offset = gaps.outer_vertical
68 + (stack_index as u32) * (stack_height + gaps.inner_vertical);
69
70 geometries.push(WindowGeometry {
71 x_coordinate: stack_x,
72 y_coordinate: y_offset as i32,
73 width: stack_width,
74 height: stack_height,
75 });
76 }
77
78 return geometries;
79 }
80 }
81 }