Skip to content

Commit

Permalink
Bug Fix 🐛
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   README.md
	modified:   src/capture.rs
	modified:   src/graphics_capture_api.rs
	modified:   src/lib.rs
	modified:   src/window.rs
	modified:   windows-capture-python/Cargo.lock
	modified:   windows-capture-python/Cargo.toml
	modified:   windows-capture-python/pyproject.toml
  • Loading branch information
NiiightmareXD committed Dec 4, 2023
1 parent df9c1d4 commit c153723
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 20 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.42"
version = "1.0.44"
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.42"
windows-capture = "1.0.44"
```
or run this command

Expand Down
16 changes: 10 additions & 6 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ pub trait WindowsCaptureHandler: Sized {
};
let controller = unsafe { CreateDispatcherQueueController(options)? };

// Debug Thread ID
let thread_id = unsafe { GetCurrentThreadId() };
debug!("Thread ID: {thread_id}");

// Start Capture
info!("Starting Capture Thread");
let callback = Arc::new(Mutex::new(Self::new(settings.flags)?));
Expand All @@ -185,12 +189,10 @@ pub trait WindowsCaptureHandler: Sized {
settings.capture_cursor,
settings.draw_border,
settings.color_format,
thread_id,
)?;
capture.start_capture()?;

// Debug Thread ID
debug!("Thread ID: {}", unsafe { GetCurrentThreadId() });

// Message Loop
trace!("Entering Message Loop");
let mut message = MSG::default();
Expand Down Expand Up @@ -263,6 +265,10 @@ pub trait WindowsCaptureHandler: Sized {
};
let controller = unsafe { CreateDispatcherQueueController(options)? };

// Debug Thread ID
let thread_id = unsafe { GetCurrentThreadId() };
debug!("Thread ID: {thread_id}");

// Start Capture
info!("Starting Capture Thread");
let callback = Arc::new(Mutex::new(Self::new(settings.flags)?));
Expand All @@ -272,6 +278,7 @@ pub trait WindowsCaptureHandler: Sized {
settings.capture_cursor,
settings.draw_border,
settings.color_format,
thread_id,
)?;
capture.start_capture()?;

Expand All @@ -284,9 +291,6 @@ pub trait WindowsCaptureHandler: Sized {
trace!("Sending Callback");
callback_sender.send(callback)?;

// Debug Thread ID
debug!("Thread ID: {}", unsafe { GetCurrentThreadId() });

// Message Loop
trace!("Entering Message Loop");
let mut message = MSG::default();
Expand Down
26 changes: 21 additions & 5 deletions src/graphics_capture_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ use windows::{
DirectX::{Direct3D11::IDirect3DDevice, DirectXPixelFormat},
},
Win32::{
Foundation::{LPARAM, WPARAM},
Graphics::Direct3D11::{
ID3D11Device, ID3D11DeviceContext, ID3D11Texture2D, D3D11_TEXTURE2D_DESC,
},
System::WinRT::Direct3D11::IDirect3DDxgiInterfaceAccess,
UI::WindowsAndMessaging::PostQuitMessage,
UI::WindowsAndMessaging::{PostThreadMessageW, WM_QUIT},
},
};

Expand Down Expand Up @@ -89,6 +90,7 @@ impl GraphicsCaptureApi {
capture_cursor: Option<bool>,
draw_border: Option<bool>,
color_format: ColorFormat,
thread_id: u32,
) -> Result<Self, Box<dyn Error + Send + Sync>> {
// Check Support
if !ApiInformation::IsApiContractPresentByMajor(
Expand Down Expand Up @@ -136,16 +138,23 @@ impl GraphicsCaptureApi {
move |_, _| {
halt_closed.store(true, atomic::Ordering::Relaxed);

// To Stop Messge Loop
unsafe { PostQuitMessage(0) };

// Notify The Struct That The Capture Session Is Closed
let result = callback_closed.lock().on_closed();

let _ = RESULT
.replace(Some(result))
.expect("Failed To Replace RESULT");

// To Stop Messge Loop
unsafe {
PostThreadMessageW(
thread_id,
WM_QUIT,
WPARAM::default(),
LPARAM::default(),
)?;
};

Result::Ok(())
}
}),
Expand Down Expand Up @@ -245,7 +254,14 @@ impl GraphicsCaptureApi {
halt_frame_pool.store(true, atomic::Ordering::Relaxed);

// To Stop Messge Loop
unsafe { PostQuitMessage(0) };
unsafe {
PostThreadMessageW(
thread_id,
WM_QUIT,
WPARAM::default(),
LPARAM::default(),
)?;
};
}

Result::Ok(())
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.42"
//! windows-capture = "1.0.44"
//! ```
//! or run this command
//!
Expand Down
2 changes: 1 addition & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Window {
let len = unsafe { GetWindowTextLengthW(self.window) };

let mut name = vec![0u16; len as usize + 1];
if len > 1 {
if len >= 1 {
let copied = unsafe { GetWindowTextW(self.window, &mut name) };
if copied == 0 {
return Ok(String::new());
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.42"
version = "1.0.44"
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.42"
version = "1.0.44"
description = "Fastest Windows Screen Capture Library For Python 🔥"
readme = "README.md"
requires-python = ">=3.9"
Expand Down
Binary file not shown.

0 comments on commit c153723

Please sign in to comment.