diff --git a/Cargo.lock b/Cargo.lock index ace9426..a0ef69b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -548,7 +548,7 @@ dependencies = [ [[package]] name = "windows-capture" -version = "1.0.36" +version = "1.0.37" dependencies = [ "image", "log", @@ -560,7 +560,7 @@ dependencies = [ [[package]] name = "windows-capture-python" -version = "1.0.36" +version = "1.0.37" dependencies = [ "pyo3", "windows", diff --git a/Cargo.toml b/Cargo.toml index 302b835..43a9677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-capture" -version = "1.0.36" +version = "1.0.37" authors = ["NiiightmareXD"] edition = "2021" description = "Fastest Windows Screen Capture Library For Rust 🔥" diff --git a/README.md b/README.md index 1c027df..c9e6feb 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add this library to your `Cargo.toml`: ```toml [dependencies] -windows-capture = "1.0.36" +windows-capture = "1.0.37" ``` or run this command diff --git a/src/lib.rs b/src/lib.rs index e02f4f6..e1dd123 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ //! //! ```toml //! [dependencies] -//! windows-capture = "1.0.36" +//! windows-capture = "1.0.37" //! ``` //! or run this command //! diff --git a/src/monitor.rs b/src/monitor.rs index d4f9b1b..8da9e85 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -1,11 +1,12 @@ -use std::{error::Error, ptr}; +use std::{error::Error, mem, ptr}; use windows::{ Graphics::Capture::GraphicsCaptureItem, Win32::{ Foundation::{BOOL, LPARAM, POINT, RECT, TRUE}, Graphics::Gdi::{ - EnumDisplayMonitors, MonitorFromPoint, HDC, HMONITOR, MONITOR_DEFAULTTOPRIMARY, + EnumDisplayMonitors, GetMonitorInfoW, MonitorFromPoint, HDC, HMONITOR, MONITORINFO, + MONITORINFOEXW, MONITOR_DEFAULTTOPRIMARY, }, System::WinRT::Graphics::Capture::IGraphicsCaptureItemInterop, }, @@ -45,12 +46,41 @@ impl Monitor { None => return Err(Box::new(MonitorErrors::NotFound)), }; - Ok(Self { monitor }) + Ok(monitor) + } + + /// Get Monitor Device Name + pub fn name(&self) -> Result> { + let mut monitor_info = MONITORINFOEXW { + monitorInfo: MONITORINFO { + cbSize: mem::size_of::() as u32, + rcMonitor: RECT::default(), + rcWork: RECT::default(), + dwFlags: 0, + }, + szDevice: [0; 32], + }; + unsafe { + GetMonitorInfoW( + self.as_raw_hmonitor(), + std::ptr::addr_of_mut!(monitor_info).cast(), + ) + }; + + Ok(String::from_utf16( + &monitor_info + .szDevice + .as_slice() + .iter() + .take_while(|ch| **ch != 0x0000) + .copied() + .collect::>(), + )?) } /// Get A List Of All Monitors - pub fn enumerate() -> Result, Box> { - let mut monitors: Vec = Vec::new(); + pub fn enumerate() -> Result, Box> { + let mut monitors: Vec = Vec::new(); unsafe { EnumDisplayMonitors( @@ -84,9 +114,9 @@ impl Monitor { _: *mut RECT, vec: LPARAM, ) -> BOOL { - let monitors = &mut *(vec.0 as *mut Vec); + let monitors = &mut *(vec.0 as *mut Vec); - monitors.push(monitor); + monitors.push(Self { monitor }); TRUE } diff --git a/windows-capture-python/Cargo.lock b/windows-capture-python/Cargo.lock index 3c6ba42..8f2cc24 100644 --- a/windows-capture-python/Cargo.lock +++ b/windows-capture-python/Cargo.lock @@ -131,7 +131,7 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ diff --git a/windows-capture-python/Cargo.toml b/windows-capture-python/Cargo.toml index 635e09f..1fe6c28 100644 --- a/windows-capture-python/Cargo.toml +++ b/windows-capture-python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-capture-python" -version = "1.0.36" +version = "1.0.37" authors = ["NiiightmareXD"] edition = "2021" description = "Fastest Windows Screen Capture Library For Python 🔥" diff --git a/windows-capture-python/pyproject.toml b/windows-capture-python/pyproject.toml index 36fba0e..99b8411 100644 --- a/windows-capture-python/pyproject.toml +++ b/windows-capture-python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "windows-capture" -version = "1.0.36" +version = "1.0.37" description = "Fastest Windows Screen Capture Library For Python 🔥" readme = "README.md" requires-python = ">=3.9"