1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use wm::layout::*;
#[derive(Debug)]
pub struct Monocle {
pub offset_x: u32,
pub offset_y: u32,
}
impl Default for Monocle {
fn default() -> Monocle {
Monocle {
offset_x: 20,
offset_y: 20,
}
}
}
impl Layout for Monocle {
fn arrange(&self, num_windows: usize, screen: &TilingArea) -> Vec<Option<Geometry>> {
let mut res = Vec::with_capacity(num_windows);
res.push(Some(Geometry {
x: self.offset_x + screen.offset_x,
y: self.offset_y + screen.offset_y,
width: screen.width - 2 * self.offset_x - 2,
height: screen.height - 2 * self.offset_y - 2,
}));
for _ in 1..num_windows {
res.push(None);
}
res
}
fn right_window(&self, _: usize, _: usize) -> Option<usize> {
None
}
fn left_window(&self, _: usize, _: usize) -> Option<usize> {
None
}
fn top_window(&self, _: usize, _: usize) -> Option<usize> {
None
}
fn bottom_window(&self, _: usize, _: usize) -> Option<usize> {
None
}
fn new_window_as_master(&self) -> bool {
true
}
fn edit_layout(&mut self, msg: LayoutMessage) -> bool {
match msg {
LayoutMessage::XOffAbs(x) => self.offset_x = x,
LayoutMessage::XOffRel(x) => {
self.offset_x = if x < 0 {
self.offset_x.saturating_sub(x.abs() as u32)
} else {
self.offset_x.saturating_add(x.abs() as u32)
}
}
LayoutMessage::YOffAbs(y) => self.offset_y = y,
LayoutMessage::YOffRel(y) => {
self.offset_y = if y < 0 {
self.offset_y.saturating_sub(y.abs() as u32)
} else {
self.offset_y.saturating_add(y.abs() as u32)
}
}
_ => return false,
};
true
}
}