1#[cfg(target_os = "windows")]
2mod windows;
3
4#[cfg(target_os = "windows")]
5pub use windows::WindowsError;
6
7#[cfg(target_os = "windows")]
8pub type Error = WindowsError;
9
10#[cfg(target_os = "windows")]
11pub type CoordinateType = i32;
12
13#[cfg(target_os = "windows")]
14pub type ProportionType = i32;
15
16#[cfg(target_os = "linux")]
17mod linux;
18
19#[cfg(target_os = "linux")]
20pub use x11rb;
21
22#[cfg(target_os = "linux")]
23pub type Error = x11rb::errors::ConnectionError;
24
25#[cfg(target_os = "linux")]
26pub type CoordinateType = i16;
27
28#[cfg(target_os = "linux")]
29pub type ProportionType = u16;
30
31#[cfg(target_os = "macos")]
32mod macos;
33
34#[cfg(target_os = "macos")]
35pub use macos::MacOSError;
36
37#[cfg(target_os = "macos")]
38pub type Error = MacOSError;
39
40#[cfg(target_os = "macos")]
41pub type CoordinateType = f64;
42
43#[cfg(target_os = "macos")]
44pub type ProportionType = f64;
45
46pub use image::RgbImage;
47
48#[derive(Debug, Copy, Clone)]
49#[repr(C)]
50pub(crate) struct Bgr {
51 b: u8,
52 g: u8,
53 r: u8,
54 _padding: u8,
55}
56
57pub trait Capturer {
58 fn capture(&self, index: usize) -> Result<RgbImage, Error>;
60 fn capture_primary(&self) -> Result<RgbImage, Error>;
62 fn capture_all(&self) -> Result<Vec<RgbImage>, Error>;
64 fn displays(&self) -> &[Display];
66 fn refresh_displays(&mut self) -> Result<(), Error>;
68}
69
70#[derive(Debug, Copy, Clone)]
71pub struct Display {
72 top: CoordinateType,
73 left: CoordinateType,
74 width: ProportionType,
75 height: ProportionType,
76}
77
78impl Display {
79 pub fn width(&self) -> ProportionType {
80 self.width
81 }
82 pub fn height(&self) -> ProportionType {
83 self.height
84 }
85}
86
87#[cfg(target_os = "windows")]
88pub fn init_capturer() -> Result<impl Capturer, Error> {
89 use windows::*;
90 Ok(WindowsCapturer::new()?)
91}
92
93#[cfg(target_os = "linux")]
94pub fn init_capturer() -> Result<impl Capturer, Error> {
95 use linux::*;
96 Ok(X11Capturer::new()?)
97}
98
99#[cfg(target_os = "macos")]
100pub fn init_capturer() -> Result<impl Capturer, Error> {
101 use macos::*;
102 Ok(MacOSCapturer::new()?)
103}