Skip to content

Commit

Permalink
Add CPU write flag 🎯
Browse files Browse the repository at this point in the history
  • Loading branch information
NiiightmareXD committed Nov 1, 2024
1 parent c9b9cc0 commit ef1b4c0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 52 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "windows-capture"
version = "1.4.0"
version = "1.4.1"
authors = ["NiiightmareXD"]
edition = "2021"
description = "Fastest Windows Screen Capture Library For Rust 🔥"
Expand Down Expand Up @@ -52,7 +52,7 @@ parking_lot = "0.12.3"
rayon = "1.10.0"

# Error handling
thiserror = "1.0.65"
thiserror = "1.0.66"
clap = { version = "4.5.20", features = ["derive"] }
ctrlc = "3.4.5"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add this dependency to your `Cargo.toml`:

```toml
[dependencies]
windows-capture = "1.4.0"
windows-capture = "1.4.1"
```

or run this command
Expand Down
24 changes: 12 additions & 12 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use windows_capture::{
settings::{ColorFormat, CursorCaptureSettings, DrawBorderSettings, Settings},
};

// This struct will be used to handle the capture events.
// Handles capture events.
struct Capture {
// The video encoder that will be used to encode the frames.
encoder: Option<VideoEncoder>,
Expand All @@ -24,12 +24,12 @@ impl GraphicsCaptureApiHandler for Capture {
// The type of flags used to get the values from the settings.
type Flags = String;

// The type of error that can occur during capture, the error will be returned from `CaptureControl` and `start` functions.
// The type of error that can be returned from `CaptureControl` and `start` functions.
type Error = Box<dyn std::error::Error + Send + Sync>;

// Function that will be called to create the struct. The flags can be passed from settings.
// Function that will be called to create a new instance. The flags can be passed from settings.
fn new(ctx: Context<Self::Flags>) -> Result<Self, Self::Error> {
println!("Got The Flag: {}", ctx.flags);
println!("Created with Flags: {}", ctx.flags);

let encoder = VideoEncoder::new(
VideoSettingsBuilder::new(1920, 1080),
Expand Down Expand Up @@ -59,7 +59,7 @@ impl GraphicsCaptureApiHandler for Capture {
// Send the frame to the video encoder
self.encoder.as_mut().unwrap().send_frame(frame)?;

// Note: The frame has other uses too for example you can save a single for to a file like this:
// Note: The frame has other uses too, for example, you can save a single frame to a file, like this:
// frame.save_as_image("frame.png", ImageFormat::Png)?;
// Or get the raw data like this so you have full control:
// let data = frame.buffer()?;
Expand All @@ -80,30 +80,30 @@ impl GraphicsCaptureApiHandler for Capture {

// Optional handler called when the capture item (usually a window) closes.
fn on_closed(&mut self) -> Result<(), Self::Error> {
println!("Capture Session Closed");
println!("Capture session ended");

Ok(())
}
}

fn main() {
// Gets The Foreground Window, Checkout The Docs For Other Capture Items
// Gets the foreground window, refer to the docs for other capture items
let primary_monitor = Monitor::primary().expect("There is no primary monitor");

let settings = Settings::new(
// Item To Captue
// Item to capture
primary_monitor,
// Capture Cursor Settings
// Capture cursor settings
CursorCaptureSettings::Default,
// Draw Borders Settings
// Draw border settings
DrawBorderSettings::Default,
// The desired color format for the captured frame.
ColorFormat::Rgba8,
// Additional flags for the capture settings that will be passed to user defined `new` function.
"Yea This Works".to_string(),
"Yea this works".to_string(),
);

// Starts the capture and takes control of the current thread.
// The errors from handler trait will end up here
Capture::start(settings).expect("Screen Capture Failed");
Capture::start(settings).expect("Screen capture failed");
}
54 changes: 28 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
//! ```toml
//! [dependencies]
//! windows-capture = "1.4.0"
//! windows-capture = "1.4.1"
//! ```
//! or run this command
//!
Expand All @@ -47,7 +47,7 @@
//! settings::{ColorFormat, CursorCaptureSettings, DrawBorderSettings, Settings},
//! };
//!
//! // This struct will be used to handle the capture events.
//! // Handles capture events.
//! struct Capture {
//! // The video encoder that will be used to encode the frames.
//! encoder: Option<VideoEncoder>,
Expand All @@ -59,12 +59,12 @@
//! // The type of flags used to get the values from the settings.
//! type Flags = String;
//!
//! // The type of error that can occur during capture, the error will be returned from `CaptureControl` and `start` functions.
//! // The type of error that can be returned from `CaptureControl` and `start` functions.
//! type Error = Box<dyn std::error::Error + Send + Sync>;
//!
//! // Function that will be called to create the struct. The flags can be passed from settings.
//! // Function that will be called to create a new instance. The flags can be passed from settings.
//! fn new(ctx: Context<Self::Flags>) -> Result<Self, Self::Error> {
//! println!("Got The Flag: {}", ctx.flags);
//! println!("Created with Flags: {}", ctx.flags);
//!
//! let encoder = VideoEncoder::new(
//! VideoSettingsBuilder::new(1920, 1080),
Expand Down Expand Up @@ -94,7 +94,7 @@
//! // Send the frame to the video encoder
//! self.encoder.as_mut().unwrap().send_frame(frame)?;
//!
//! // Note: The frame has other uses too for example you can save a single for to a file like this:
//! // Note: The frame has other uses too, for example, you can save a single frame to a file, like this:
//! // frame.save_as_image("frame.png", ImageFormat::Png)?;
//! // Or get the raw data like this so you have full control:
//! // let data = frame.buffer()?;
Expand All @@ -115,31 +115,33 @@
//!
//! // Optional handler called when the capture item (usually a window) closes.
//! fn on_closed(&mut self) -> Result<(), Self::Error> {
//! println!("Capture Session Closed");
//! println!("Capture session ended");
//!
//! Ok(())
//! }
//! }
//!
//! // Gets The Foreground Window, Checkout The Docs For Other Capture Items
//! let primary_monitor = Monitor::primary().expect("There is no primary monitor");
//!
//! let settings = Settings::new(
//! // Item To Captue
//! primary_monitor,
//! // Capture Cursor Settings
//! CursorCaptureSettings::Default,
//! // Draw Borders Settings
//! DrawBorderSettings::Default,
//! // The desired color format for the captured frame.
//! ColorFormat::Rgba8,
//! // Additional flags for the capture settings that will be passed to user defined `new` function.
//! "Yea This Works".to_string(),
//! );
//!
//! // Starts the capture and takes control of the current thread.
//! // The errors from handler trait will end up here
//! Capture::start(settings).expect("Screen Capture Failed");
//! fn main() {
//! // Gets the foreground window, refer to the docs for other capture items
//! let primary_monitor = Monitor::primary().expect("There is no primary monitor");
//!
//! let settings = Settings::new(
//! // Item to capture
//! primary_monitor,
//! // Capture cursor settings
//! CursorCaptureSettings::Default,
//! // Draw border settings
//! DrawBorderSettings::Default,
//! // The desired color format for the captured frame.
//! ColorFormat::Rgba8,
//! // Additional flags for the capture settings that will be passed to user defined `new` function.
//! "Yea this works".to_string(),
//! );
//!
//! // Starts the capture and takes control of the current thread.
//! // The errors from handler trait will end up here
//! Capture::start(settings).expect("Screen capture failed");
//! }
//! ```
#![warn(clippy::nursery)]
#![warn(clippy::cargo)]
Expand Down
4 changes: 2 additions & 2 deletions 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.4.0"
version = "1.4.1"
authors = ["NiiightmareXD"]
edition = "2021"
description = "Fastest Windows Screen Capture Library For Python 🔥"
Expand All @@ -27,5 +27,5 @@ pyo3 = { version = "0.22.5", features = [
"abi3",
"abi3-py39",
] }
thiserror = "1.0.65"
thiserror = "1.0.66"
windows-capture = { path = ".." }
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.4.0"
version = "1.4.1"
description = "Fastest Windows Screen Capture Library For Python 🔥"
readme = "README-Python.md"
requires-python = ">=3.9"
Expand Down

0 comments on commit ef1b4c0

Please sign in to comment.