1 use crate::models::Tag;
2 use crate::models::Window;
3 use crate::models::Workspace;
4 // use crate::models::WindowState;
5
6 /// Layout which gives only one window with the full desktop realestate. A monocle mode.
update(workspace: &Workspace, tag: &Tag, windows: &mut Vec<&mut Window>)7 pub fn update(workspace: &Workspace, tag: &Tag, windows: &mut Vec<&mut Window>) {
8 let window_count = windows.len();
9
10 if window_count == 0 {
11 return;
12 }
13
14 let column_count = match window_count {
15 1 => 1,
16 _ => 2,
17 };
18 let workspace_width = workspace.width_limited(column_count);
19 let workspace_x = workspace.x_limited(column_count);
20
21 let primary_width = match window_count {
22 1 => workspace_width as i32,
23 _ => (workspace_width as f32 / 100.0 * tag.main_width_percentage()).floor() as i32,
24 };
25
26 let mut main_x = workspace_x;
27 let stack_x = if tag.flipped_horizontal {
28 main_x = match window_count {
29 1 => main_x,
30 _ => main_x + workspace_width - primary_width,
31 };
32 match window_count {
33 1 => 0,
34 _ => workspace_x,
35 }
36 } else {
37 workspace_x + primary_width
38 };
39
40 //Display main and second window
41 let mut iter = windows.iter_mut();
42 {
43 if let Some(first) = iter.next() {
44 first.set_height(workspace.height());
45 first.set_width(primary_width);
46 first.set_x(main_x);
47 first.set_y(workspace.y());
48
49 first.set_visible(true);
50 }
51 if let Some(second) = iter.next() {
52 second.set_height(workspace.height());
53 second.set_width(workspace_width - primary_width);
54 second.set_x(stack_x);
55 second.set_y(workspace.y());
56
57 second.set_visible(true);
58 }
59 }
60 //Hide the other windows behind the second
61 {
62 if window_count > 2 {
63 for w in iter {
64 w.set_height(workspace.height());
65 w.set_width(workspace_width - primary_width);
66 w.set_x(stack_x);
67 w.set_y(workspace.y());
68
69 w.set_visible(false);
70 }
71 }
72 }
73 }
74