Cross-platform get display info for MacOS、Windows、Linux. Like electron Display Object
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());
}idu32 - Unique identifier associated with the display.nameString - The name of the displayfriendly_nameString - The display friendly name,raw_handleCGDisplay/HMONITOR/Output - Native display raw handlexi32 - The display x coordinate.yi32 - The display y coordinate.widthu32 - The display pixel width.heightu32 - The display pixel height.width_mmi32 - The width of a display in millimeters. This value may be 0.height_mmi32 - The height of a display in millimeters. This value may be 0.rotationf32 - Can be 0, 90, 180, 270, represents screen rotation in clock-wise degrees.scale_factorf32 - Output device's pixel scale factor.frequencyf32 - The display refresh rate.is_primarybool - Whether the screen is the main screen
On Linux, you need to install libxcb、libxrandr
Debian/Ubuntu:
apt-get install libxcb1 libxrandr2Alpine:
apk add libxcb libxrandrArchLinux:
pacman -S libxcb libxrandr