Skip to content

Commit

Permalink
Update Monitor Struct 🔥
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   README.md
	modified:   src/lib.rs
	modified:   src/monitor.rs
	modified:   windows-capture-python/Cargo.lock
	modified:   windows-capture-python/Cargo.toml
	modified:   windows-capture-python/pyproject.toml
  • Loading branch information
NiiightmareXD committed Nov 26, 2023
1 parent 6df8228 commit c4322f4
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 🔥"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
//! ```toml
//! [dependencies]
//! windows-capture = "1.0.36"
//! windows-capture = "1.0.37"
//! ```
//! or run this command
//!
Expand Down
44 changes: 37 additions & 7 deletions src/monitor.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down Expand Up @@ -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<String, Box<dyn Error + Send + Sync>> {
let mut monitor_info = MONITORINFOEXW {
monitorInfo: MONITORINFO {
cbSize: mem::size_of::<MONITORINFOEXW>() 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::<Vec<_>>(),
)?)
}

/// Get A List Of All Monitors
pub fn enumerate() -> Result<Vec<HMONITOR>, Box<dyn Error + Send + Sync>> {
let mut monitors: Vec<HMONITOR> = Vec::new();
pub fn enumerate() -> Result<Vec<Self>, Box<dyn Error + Send + Sync>> {
let mut monitors: Vec<Self> = Vec::new();

unsafe {
EnumDisplayMonitors(
Expand Down Expand Up @@ -84,9 +114,9 @@ impl Monitor {
_: *mut RECT,
vec: LPARAM,
) -> BOOL {
let monitors = &mut *(vec.0 as *mut Vec<HMONITOR>);
let monitors = &mut *(vec.0 as *mut Vec<Self>);

monitors.push(monitor);
monitors.push(Self { monitor });

TRUE
}
Expand Down
2 changes: 1 addition & 1 deletion windows-capture-python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion windows-capture-python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 🔥"
Expand Down
2 changes: 1 addition & 1 deletion windows-capture-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c4322f4

Please sign in to comment.