-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmonitor.rs
More file actions
66 lines (55 loc) · 1.44 KB
/
monitor.rs
File metadata and controls
66 lines (55 loc) · 1.44 KB
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
use crate::{Point, Rect, Size, ui::sys};
/// Represents the geometry of a monitor.
#[derive(Debug, Clone, PartialEq)]
pub struct Monitor {
region: Rect,
client: Rect,
dpi: Size,
}
impl Monitor {
pub(crate) fn new(region: Rect, client: Rect, dpi: Size) -> Self {
Self {
region,
client,
dpi,
}
}
/// Retrieve all monitors.
pub fn all() -> Vec<Self> {
sys::monitor_get_all()
}
/// The physical region.
pub fn region(&self) -> Rect {
self.region
}
/// The client region.
pub fn client(&self) -> Rect {
self.client
}
/// Dpi of the monitor, 1.0 if no scale. You should take it into
/// consideration when setting the location of windows.
/// See [`Monitor::region_scaled`] & [`Monitor::client_scaled`].
pub fn dpi(&self) -> Size {
self.dpi
}
/// Scaled physical region.
pub fn region_scaled(&self) -> Rect {
div_rect(self.region, self.dpi)
}
/// Scaled client region.
pub fn client_scaled(&self) -> Rect {
div_rect(self.client, self.dpi)
}
}
#[inline]
fn div_rect(r: Rect, s: Size) -> Rect {
Rect::new(div_point(r.origin, s), div_size(r.size, s))
}
#[inline]
fn div_point(p: Point, s: Size) -> Point {
Point::new(p.x / s.width, p.y / s.height)
}
#[inline]
fn div_size(s1: Size, s2: Size) -> Size {
Size::new(s1.width / s2.width, s1.height / s2.height)
}