1 use crate::models::Tag;
2 use crate::models::Window;
3 use crate::models::Workspace;
4
5 /// Layout which splits the workspace into two columns.
6 /// Gives first column 2/3 workspace width on the right side, 1/3 for second column on left side.
7 /// Divides second column height for other windows.
8 ///
9 /// Meant for ultra-wide monitors.
10 ///
11 /// 1 window
12 /// +-----------------------------------------+
13 /// | |
14 /// | |
15 /// | |
16 /// | |
17 /// | 1 |
18 /// | |
19 /// | |
20 /// | |
21 /// +-----------------------------------------+
22 /// 2 windows
23 /// +--------------------+--------------------+
24 /// | | |
25 /// | | |
26 /// | | |
27 /// | 2 | 1 |
28 /// | | |
29 /// | | |
30 /// | | |
31 /// | | |
32 /// +--------------------+--------------------+
33 /// 3 windows
34 /// +--------------------+--------------------+
35 /// | | |
36 /// | 2 | |
37 /// | | |
38 /// +_____________+ 1 |
39 /// | | |
40 /// | 3 | |
41 /// | | |
42 /// | | |
43 /// +--------------------+--------------------+
44 /// 4 windows
45 /// +--------------------+--------------------+
46 /// | | |
47 /// | 2 | |
48 /// +_____________+ |
49 /// | | 1 |
50 /// | 3 | |
51 /// +_____________+ |
52 /// | | |
53 /// | 4 | |
54 /// +--------------------+--------------------+
55
update(workspace: &Workspace, tag: &Tag, windows: &mut Vec<&mut Window>)56 pub fn update(workspace: &Workspace, tag: &Tag, windows: &mut Vec<&mut Window>) {
57 let window_count = windows.len();
58
59 if window_count == 0 {
60 return;
61 }
62
63 let column_count = match window_count {
64 1 => 1,
65 _ => 2,
66 };
67 let workspace_width = workspace.width_limited(column_count);
68 let workspace_x = workspace.x_limited(column_count);
69
70 let primary_width = match window_count {
71 1 => workspace_width,
72 _ => (workspace_width as f32 / 100.0 * tag.main_width_percentage().floor()) as i32,
73 };
74
75 let third_part = workspace_width - primary_width;
76
77 let (mut main_x, mut stack_x) = match window_count {
78 1 => (workspace_x, 0),
79 _ => (workspace_x + third_part, workspace_x),
80 };
81 if tag.flipped_horizontal {
82 main_x = workspace_x;
83 stack_x = workspace_x + primary_width;
84 }
85
86 let mut iter = windows.iter_mut();
87
88 // build the primary window
89 {
90 if let Some(first) = iter.next() {
91 first.set_height(workspace.height());
92 first.set_width(primary_width);
93 first.set_x(main_x);
94 first.set_y(workspace.y());
95 }
96 }
97
98 // build other windows
99 let height = (workspace.height() as f32 / (window_count - 1) as f32).floor() as i32;
100
101 let mut y = 0;
102
103 for w in iter {
104 w.set_height(height);
105 w.set_width(third_part);
106 w.set_x(stack_x);
107 w.set_y(workspace.y() + y);
108 y += height;
109 }
110 }
111