diff --git a/Cargo.lock b/Cargo.lock index 85dd1a5..cc7f587 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -548,7 +548,7 @@ dependencies = [ [[package]] name = "windows-capture" -version = "1.0.42" +version = "1.0.44" dependencies = [ "image", "log", @@ -560,7 +560,7 @@ dependencies = [ [[package]] name = "windows-capture-python" -version = "1.0.42" +version = "1.0.44" dependencies = [ "pyo3", "windows", diff --git a/Cargo.toml b/Cargo.toml index 2f7bb72..3041b7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 🔥" diff --git a/README.md b/README.md index 0944692..54bd3ee 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/capture.rs b/src/capture.rs index bba4504..a003bae 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -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)?)); @@ -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(); @@ -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)?)); @@ -272,6 +278,7 @@ pub trait WindowsCaptureHandler: Sized { settings.capture_cursor, settings.draw_border, settings.color_format, + thread_id, )?; capture.start_capture()?; @@ -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(); diff --git a/src/graphics_capture_api.rs b/src/graphics_capture_api.rs index 09cd2bb..c7e6763 100644 --- a/src/graphics_capture_api.rs +++ b/src/graphics_capture_api.rs @@ -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}, }, }; @@ -89,6 +90,7 @@ impl GraphicsCaptureApi { capture_cursor: Option, draw_border: Option, color_format: ColorFormat, + thread_id: u32, ) -> Result> { // Check Support if !ApiInformation::IsApiContractPresentByMajor( @@ -136,9 +138,6 @@ 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(); @@ -146,6 +145,16 @@ impl GraphicsCaptureApi { .replace(Some(result)) .expect("Failed To Replace RESULT"); + // To Stop Messge Loop + unsafe { + PostThreadMessageW( + thread_id, + WM_QUIT, + WPARAM::default(), + LPARAM::default(), + )?; + }; + Result::Ok(()) } }), @@ -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(()) diff --git a/src/lib.rs b/src/lib.rs index f8a75ba..eeeb99f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ //! //! ```toml //! [dependencies] -//! windows-capture = "1.0.42" +//! windows-capture = "1.0.44" //! ``` //! or run this command //! diff --git a/src/window.rs b/src/window.rs index 195168b..f493a56 100644 --- a/src/window.rs +++ b/src/window.rs @@ -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()); diff --git a/windows-capture-python/Cargo.lock b/windows-capture-python/Cargo.lock index d205620..d1f8c96 100644 --- a/windows-capture-python/Cargo.lock +++ b/windows-capture-python/Cargo.lock @@ -131,7 +131,7 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.42" +version = "1.0.44" 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 782be72..706a197 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.42" +version = "1.0.44" 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 9f0f36d..0a4ba7b 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.42" +version = "1.0.44" description = "Fastest Windows Screen Capture Library For Python 🔥" readme = "README.md" requires-python = ">=3.9" diff --git a/windows-capture-python/windows_capture/windows_capture.cp311-win_amd64.pyd b/windows-capture-python/windows_capture/windows_capture.cp311-win_amd64.pyd index bfd8c57..1dbb362 100644 Binary files a/windows-capture-python/windows_capture/windows_capture.cp311-win_amd64.pyd and b/windows-capture-python/windows_capture/windows_capture.cp311-win_amd64.pyd differ