Skip to content

Commit

Permalink
Update Dependencies ⭐
Browse files Browse the repository at this point in the history
  • Loading branch information
NiiightmareXD committed Apr 21, 2024
1 parent f845ee8 commit 62a313f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
34 changes: 22 additions & 12 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,23 @@ impl<T: GraphicsCaptureApiHandler + Send + 'static, E> CaptureControl<T, E> {

#[derive(thiserror::Error, Eq, PartialEq, Clone, Debug)]
pub enum GraphicsCaptureApiError<E> {
#[error("Failed To Join Thread")]
#[error("Failed to join thread")]
FailedToJoinThread,
#[error("Failed To Initialize WinRT")]
#[error("Failed to initialize WinRT")]
FailedToInitWinRT,
#[error("Failed To Create Dispatcher Queue Controller")]
#[error("Failed to translate message")]
FailedToTranslateMessage,
#[error("Failed to create dispatcher queue controller")]
FailedToCreateDispatcherQueueController,
#[error("Failed To Shutdown Dispatcher Queue")]
#[error("Failed to shutdown dispatcher queue")]
FailedToShutdownDispatcherQueue,
#[error("Failed To Set Dispatcher Queue Completed Handler")]
#[error("Failed to set dispatcher queue completed handler")]
FailedToSetDispatcherQueueCompletedHandler,
#[error("Graphics Capture Error")]
#[error("Graphics capture error")]
GraphicsCaptureApiError(graphics_capture_api::Error),
#[error("New Handler Error")]
#[error("New handler error")]
NewHandlerError(E),
#[error("Frame Handler Error")]
#[error("Frame handler error")]
FrameHandlerError(E),
}

Expand Down Expand Up @@ -271,7 +273,9 @@ pub trait GraphicsCaptureApiHandler: Sized {
let mut message = MSG::default();
unsafe {
while GetMessageW(&mut message, None, 0, 0).as_bool() {
TranslateMessage(&message);
TranslateMessage(&message)
.ok()
.map_err(|_| GraphicsCaptureApiError::FailedToTranslateMessage)?;
DispatchMessageW(&message);
}
}
Expand All @@ -293,7 +297,9 @@ pub trait GraphicsCaptureApiHandler: Sized {
let mut message = MSG::default();
unsafe {
while GetMessageW(&mut message, None, 0, 0).as_bool() {
TranslateMessage(&message);
TranslateMessage(&message)
.ok()
.map_err(|_| GraphicsCaptureApiError::FailedToTranslateMessage)?;
DispatchMessageW(&message);
}
}
Expand Down Expand Up @@ -384,7 +390,9 @@ pub trait GraphicsCaptureApiHandler: Sized {
let mut message = MSG::default();
unsafe {
while GetMessageW(&mut message, None, 0, 0).as_bool() {
TranslateMessage(&message);
TranslateMessage(&message)
.ok()
.map_err(|_| GraphicsCaptureApiError::FailedToTranslateMessage)?;
DispatchMessageW(&message);
}
}
Expand All @@ -409,7 +417,9 @@ pub trait GraphicsCaptureApiHandler: Sized {
let mut message = MSG::default();
unsafe {
while GetMessageW(&mut message, None, 0, 0).as_bool() {
TranslateMessage(&message);
TranslateMessage(&message)
.ok()
.map_err(|_| GraphicsCaptureApiError::FailedToTranslateMessage)?;
DispatchMessageW(&message);
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Monitor {
};
if unsafe {
!GetMonitorInfoW(
self.as_raw_hmonitor(),
HMONITOR(self.as_raw_hmonitor()),
std::ptr::addr_of_mut!(monitor_info).cast(),
)
.as_bool()
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Monitor {
};
if unsafe {
!GetMonitorInfoW(
self.as_raw_hmonitor(),
HMONITOR(self.as_raw_hmonitor()),
std::ptr::addr_of_mut!(monitor_info).cast(),
)
.as_bool()
Expand Down Expand Up @@ -280,7 +280,7 @@ impl Monitor {
};
if unsafe {
!GetMonitorInfoW(
self.as_raw_hmonitor(),
HMONITOR(self.as_raw_hmonitor()),
std::ptr::addr_of_mut!(monitor_info).cast(),
)
.as_bool()
Expand Down Expand Up @@ -422,16 +422,18 @@ impl Monitor {
///
/// # Arguments
///
/// * `monitor` - The raw HMONITOR.
/// * `hmonitor` - The raw HMONITOR.
#[must_use]
pub const fn from_raw_hmonitor(monitor: HMONITOR) -> Self {
Self { monitor }
pub const fn from_raw_hmonitor(monitor: isize) -> Self {
Self {
monitor: HMONITOR(monitor),
}
}

/// Returns the raw HMONITOR of the monitor.
#[must_use]
pub const fn as_raw_hmonitor(&self) -> HMONITOR {
self.monitor
pub const fn as_raw_hmonitor(&self) -> isize {
self.monitor.0
}

// Callback Used For Enumerating All Monitors
Expand All @@ -454,7 +456,7 @@ impl TryFrom<Monitor> for GraphicsCaptureItem {
type Error = Error;

fn try_from(value: Monitor) -> Result<Self, Self::Error> {
let monitor = value.as_raw_hmonitor();
let monitor = HMONITOR(value.as_raw_hmonitor());

let interop = windows::core::factory::<Self, IGraphicsCaptureItemInterop>()?;
Ok(unsafe { interop.CreateForMonitor(monitor)? })
Expand Down
24 changes: 10 additions & 14 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,36 +148,32 @@ impl Window {
if monitor.is_invalid() {
None
} else {
Some(Monitor::from_raw_hmonitor(monitor))
Some(Monitor::from_raw_hmonitor(monitor.0))
}
}

/// Checks if the window is a valid window.
///
/// # Arguments
///
/// * `window` - The window handle to check.
///
/// # Returns
///
/// Returns `true` if the window is valid, `false` otherwise.
#[must_use]
pub fn is_window_valid(window: HWND) -> bool {
if !unsafe { IsWindowVisible(window).as_bool() } {
pub fn is_valid(&self) -> bool {
if !unsafe { IsWindowVisible(self.window).as_bool() } {
return false;
}

let mut id = 0;
unsafe { GetWindowThreadProcessId(window, Some(&mut id)) };
unsafe { GetWindowThreadProcessId(self.window, Some(&mut id)) };
if id == unsafe { GetCurrentProcessId() } {
return false;
}

let mut rect = RECT::default();
let result = unsafe { GetClientRect(window, &mut rect) };
let result = unsafe { GetClientRect(self.window, &mut rect) };
if result.is_ok() {
let styles = unsafe { GetWindowLongPtrW(window, GWL_STYLE) };
let ex_styles = unsafe { GetWindowLongPtrW(window, GWL_EXSTYLE) };
let styles = unsafe { GetWindowLongPtrW(self.window, GWL_STYLE) };
let ex_styles = unsafe { GetWindowLongPtrW(self.window, GWL_EXSTYLE) };

if (ex_styles & isize::try_from(WS_EX_TOOLWINDOW.0).unwrap()) != 0 {
return false;
Expand Down Expand Up @@ -216,10 +212,10 @@ impl Window {
///
/// # Arguments
///
/// * `hwnd` - The hwnd.
/// * `hwnd` - The raw HWND.
#[must_use]
pub const fn from_raw_hwnd(hwnd: isize) -> Self {
Self { window: HWND(hwnd)}
Self { window: HWND(hwnd) }
}

/// Returns the raw HWND of the window.
Expand All @@ -232,7 +228,7 @@ impl Window {
unsafe extern "system" fn enum_windows_callback(window: HWND, vec: LPARAM) -> BOOL {
let windows = &mut *(vec.0 as *mut Vec<Self>);

if Self::is_window_valid(window) {
if Self::from_raw_hwnd(window.0).is_valid() {
windows.push(Self { window });
}

Expand Down

0 comments on commit 62a313f

Please sign in to comment.