-
-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathmonitor.rs
More file actions
85 lines (75 loc) · 2.13 KB
/
Copy pathmonitor.rs
File metadata and controls
85 lines (75 loc) · 2.13 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use image::RgbaImage;
use crate::{error::XCapResult, platform::impl_monitor::ImplMonitor};
#[derive(Debug, Clone)]
pub struct Monitor {
pub(crate) impl_monitor: ImplMonitor,
}
impl Monitor {
pub(crate) fn new(impl_monitor: ImplMonitor) -> Monitor {
Monitor { impl_monitor }
}
}
impl Monitor {
pub fn all() -> XCapResult<Vec<Monitor>> {
let monitors = ImplMonitor::all()?
.iter()
.map(|impl_monitor| Monitor::new(impl_monitor.clone()))
.collect();
Ok(monitors)
}
pub fn from_point(x: i32, y: i32) -> XCapResult<Monitor> {
let impl_monitor = ImplMonitor::from_point(x, y)?;
Ok(Monitor::new(impl_monitor))
}
}
impl Monitor {
/// Unique identifier associated with the screen.
pub fn id(&self) -> u32 {
self.impl_monitor.id
}
/// Unique identifier associated with the screen.
pub fn name(&self) -> &str {
&self.impl_monitor.name
}
/// The screen x coordinate.
pub fn x(&self) -> i32 {
self.impl_monitor.x
}
/// The screen x coordinate.
pub fn y(&self) -> i32 {
self.impl_monitor.y
}
/// The screen pixel width.
pub fn width(&self) -> u32 {
self.impl_monitor.width
}
/// The screen pixel height.
pub fn height(&self) -> u32 {
self.impl_monitor.height
}
/// Can be 0, 90, 180, 270, represents screen rotation in clock-wise degrees.
pub fn rotation(&self) -> f32 {
self.impl_monitor.rotation
}
/// Output device's pixel scale factor.
pub fn scale_factor(&self) -> f32 {
self.impl_monitor.scale_factor
}
/// The screen refresh rate.
pub fn frequency(&self) -> f32 {
self.impl_monitor.frequency
}
/// Whether the screen is the main screen
pub fn is_primary(&self) -> bool {
self.impl_monitor.is_primary
}
}
impl Monitor {
/// Capture image of the monitor
pub fn capture_image(&self) -> XCapResult<RgbaImage> {
self.impl_monitor.capture_image()
}
pub fn capture_bytes(&self) -> XCapResult<Vec<u8>> {
self.impl_monitor.capture_bytes()
}
}