tony / oxwm

Branch: 84c9fb0
Switch branches/tags
master
tonybtw Added vanity gaps. with toggle =) 605d25b 2025-10-06
77 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 arrange(
8 &self,
9 windows: &[Window],
10 screen_width: u32,
11 screen_height: u32,
12 gaps: &GapConfig,
13 ) -> Vec<WindowGeometry> {
14 let window_count = windows.len();
15 if window_count == 0 {
16 return Vec::new();
17 }
18
19 if window_count == 1 {
20 let x = gaps.outer_horizontal as i32;
21 let y = gaps.outer_vertical as i32;
22 let width = screen_width.saturating_sub(2 * gaps.outer_horizontal);
23 let height = screen_height.saturating_sub(2 * gaps.outer_vertical);
24
25 vec![WindowGeometry {
26 x_coordinate: x,
27 y_coordinate: y,
28 width,
29 height,
30 }]
31 } else {
32 let mut geometries = Vec::new();
33
34 let master_width = (screen_width / 2)
35 .saturating_sub(gaps.outer_horizontal)
36 .saturating_sub(gaps.inner_horizontal / 2);
37
38 let master_x = gaps.outer_horizontal as i32;
39 let master_y = gaps.outer_vertical as i32;
40 let master_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
41
42 geometries.push(WindowGeometry {
43 x_coordinate: master_x,
44 y_coordinate: master_y,
45 width: master_width,
46 height: master_height,
47 });
48
49 let stack_count = window_count - 1;
50 let stack_x = (screen_width / 2 + gaps.inner_horizontal / 2) as i32;
51 let stack_width = (screen_width / 2)
52 .saturating_sub(gaps.outer_horizontal)
53 .saturating_sub(gaps.inner_horizontal / 2);
54
55 let total_stack_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
56
57 let total_inner_gaps = gaps.inner_vertical * (stack_count as u32 - 1);
58 let stack_height =
59 total_stack_height.saturating_sub(total_inner_gaps) / stack_count as u32;
60
61 for i in 1..window_count {
62 let stack_index = i - 1;
63 let y_offset = gaps.outer_vertical
64 + (stack_index as u32) * (stack_height + gaps.inner_vertical);
65
66 geometries.push(WindowGeometry {
67 x_coordinate: stack_x,
68 y_coordinate: y_offset as i32,
69 width: stack_width,
70 height: stack_height,
71 });
72 }
73
74 return geometries;
75 }
76 }
77 }