oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git
2,791 bytes raw
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::LayoutType::Tiling.as_str()
9
    }
10
11
    fn symbol(&self) -> &'static str {
12
        "[]="
13
    }
14
15
    fn arrange(
16
        &self,
17
        windows: &[Window],
18
        screen_width: u32,
19
        screen_height: u32,
20
        gaps: &GapConfig,
21
    ) -> Vec<WindowGeometry> {
22
        let window_count = windows.len();
23
        if window_count == 0 {
24
            return Vec::new();
25
        }
26
27
        if window_count == 1 {
28
            let x = gaps.outer_horizontal as i32;
29
            let y = gaps.outer_vertical as i32;
30
            let width = screen_width.saturating_sub(2 * gaps.outer_horizontal);
31
            let height = screen_height.saturating_sub(2 * gaps.outer_vertical);
32
33
            vec![WindowGeometry {
34
                x_coordinate: x,
35
                y_coordinate: y,
36
                width,
37
                height,
38
            }]
39
        } else {
40
            let mut geometries = Vec::new();
41
42
            let master_width = (screen_width / 2)
43
                .saturating_sub(gaps.outer_horizontal)
44
                .saturating_sub(gaps.inner_horizontal / 2);
45
46
            let master_x = gaps.outer_horizontal as i32;
47
            let master_y = gaps.outer_vertical as i32;
48
            let master_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
49
50
            geometries.push(WindowGeometry {
51
                x_coordinate: master_x,
52
                y_coordinate: master_y,
53
                width: master_width,
54
                height: master_height,
55
            });
56
57
            let stack_count = window_count - 1;
58
            let stack_x = (screen_width / 2 + gaps.inner_horizontal / 2) as i32;
59
            let stack_width = (screen_width / 2)
60
                .saturating_sub(gaps.outer_horizontal)
61
                .saturating_sub(gaps.inner_horizontal / 2);
62
63
            let total_stack_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
64
65
            let total_inner_gaps = gaps.inner_vertical * (stack_count as u32 - 1);
66
            let stack_height =
67
                total_stack_height.saturating_sub(total_inner_gaps) / stack_count as u32;
68
69
            for i in 1..window_count {
70
                let stack_index = i - 1;
71
                let y_offset = gaps.outer_vertical
72
                    + (stack_index as u32) * (stack_height + gaps.inner_vertical);
73
74
                geometries.push(WindowGeometry {
75
                    x_coordinate: stack_x,
76
                    y_coordinate: y_offset as i32,
77
                    width: stack_width,
78
                    height: stack_height,
79
                });
80
            }
81
82
            return geometries;
83
        }
84
    }
85
}