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
use crate::data_types::{Point, Region};
use xcb::{base::Reply, ffi::randr::xcb_randr_get_crtc_info_reply_t};
type CRTCInfoReply = Reply<xcb_randr_get_crtc_info_reply_t>;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Screen {
pub wix: usize,
true_region: Region,
effective_region: Region,
}
impl Screen {
pub fn new(region: Region, wix: usize) -> Screen {
Screen {
true_region: region,
effective_region: region,
wix,
}
}
pub fn from_crtc_info_reply(r: CRTCInfoReply, wix: usize) -> Screen {
let region = Region::new(
r.x() as u32,
r.y() as u32,
r.width() as u32,
r.height() as u32,
);
Screen {
true_region: region,
effective_region: region,
wix,
}
}
pub fn update_effective_region(&mut self, bar_height: u32, top_bar: bool) {
let (x, y, w, h) = self.true_region.values();
self.effective_region = if top_bar {
Region::new(x, y + bar_height, w, h - bar_height)
} else {
Region::new(x, y, w, h - bar_height)
}
}
pub fn region(&self, effective_only: bool) -> Region {
if effective_only {
self.effective_region
} else {
self.true_region
}
}
pub fn contains(&self, p: Point) -> bool {
let (x1, y1, w, h) = self.true_region.values();
let (x2, y2) = (x1 + w, x1 + h);
p.x >= x1 && p.x < x2 && p.y >= y1 && p.y < y2
}
}