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
//! # example
//! Get all display info
//! ```
//! use display_info::DisplayInfo;
//! use std::time::Instant;
//!
//! fn main() {
//!   let start = Instant::now();
//!
//!   let display_infos = DisplayInfo::all().unwrap();
//!   for display_info in display_infos {
//!     println!("display_info {display_info:?}");
//!   }
//!   let display_info = DisplayInfo::from_point(100, 100).unwrap();
//!   println!("display_info {display_info:?}");
//!   println!("运行耗时: {:?}", start.elapsed());
//! }
//! ```

use anyhow::Result;

#[cfg(target_os = "macos")]
mod darwin;
#[cfg(target_os = "macos")]
use darwin::*;

#[cfg(target_os = "windows")]
mod win32;
#[cfg(target_os = "windows")]
use win32::*;

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
use linux::*;

#[derive(Debug, Clone, Copy)]
pub struct DisplayInfo {
    /// Unique identifier associated with the display.
    pub id: u32,
    /// The display x coordinate.
    pub x: i32,
    /// The display x coordinate.
    pub y: i32,
    /// The display pixel width.
    pub width: u32,
    /// The display pixel height.
    pub height: u32,
    /// Can be 0, 90, 180, 270, represents screen rotation in clock-wise degrees.
    pub rotation: f32,
    /// Output device's pixel scale factor.
    pub scale_factor: f32,
    /// The display refresh rate.
    pub frequency: f32,
    /// Whether the screen is the main screen
    pub is_primary: bool,
}

impl DisplayInfo {
    pub fn all() -> Result<Vec<DisplayInfo>> {
        get_all()
    }

    pub fn from_point(x: i32, y: i32) -> Result<DisplayInfo> {
        get_from_point(x, y)
    }
}