From 5ded96820161287bf75cfbde1accf9575854692d Mon Sep 17 00:00:00 2001 From: hagz0r Date: Wed, 23 Jul 2025 13:20:59 +0500 Subject: [PATCH] Passing capturer options correctly for Windows --- Cargo.lock | 170 +++++++++++++++++++++++++++++---- Cargo.toml | 14 +-- src/capturer/engine/win/mod.rs | 34 ++++++- 3 files changed, 187 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7a9ce0..95aec5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -509,9 +509,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" dependencies = [ "autocfg", "scopeguard", @@ -615,9 +615,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" dependencies = [ "lock_api", "parking_lot_core", @@ -625,9 +625,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" dependencies = [ "cfg-if", "libc", @@ -662,7 +662,7 @@ dependencies = [ "nix", "once_cell", "pipewire-sys", - "thiserror", + "thiserror 1.0.64", ] [[package]] @@ -902,9 +902,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.77" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -963,7 +963,16 @@ version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.64", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", ] [[package]] @@ -977,6 +986,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "toml" version = "0.8.19" @@ -1083,16 +1103,39 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows" +version = "0.61.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" +dependencies = [ + "windows-collections", + "windows-core 0.61.2", + "windows-future", + "windows-link", + "windows-numerics", +] + [[package]] name = "windows-capture" -version = "1.3.6" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc0a71a6b97b2fb0643c0655e19b8fa4a78c768bf5b2acfdaf453873e53ad4e" +checksum = "3a4df73e95feddb9ec1a7e9c2ca6323b8c97d5eeeff78d28f1eccdf19c882b24" dependencies = [ "parking_lot", "rayon", - "thiserror", - "windows 0.58.0", + "thiserror 2.0.12", + "windows 0.61.3", + "windows-future", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" +dependencies = [ + "windows-core 0.61.2", ] [[package]] @@ -1110,13 +1153,37 @@ version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement", - "windows-interface", - "windows-result", - "windows-strings", + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", + "windows-strings 0.1.0", "windows-targets", ] +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement 0.60.0", + "windows-interface 0.59.1", + "windows-link", + "windows-result 0.3.4", + "windows-strings 0.4.2", +] + +[[package]] +name = "windows-future" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" +dependencies = [ + "windows-core 0.61.2", + "windows-link", + "windows-threading", +] + [[package]] name = "windows-implement" version = "0.58.0" @@ -1128,6 +1195,17 @@ dependencies = [ "syn", ] +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-interface" version = "0.58.0" @@ -1139,6 +1217,33 @@ dependencies = [ "syn", ] +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core 0.61.2", + "windows-link", +] + [[package]] name = "windows-result" version = "0.2.0" @@ -1148,16 +1253,34 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-strings" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-targets", ] +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -1174,6 +1297,15 @@ dependencies = [ "windows_x86_64_msvc", ] +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index 29c7f56..ec262e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" rust-version = "1.71" license = "MIT" authors = [ - "Siddharth ", - "Pranav ", + "Siddharth ", + "Pranav ", ] readme = "README.md" repository = "https://github.com/helmerapp/scap" @@ -19,12 +19,12 @@ categories = ["graphics", "multimedia", "multimedia::video"] sysinfo = "0.30.0" [target.'cfg(target_os = "windows")'.dependencies] -windows-capture = "1.3.6" +windows-capture = "1.5.0" windows = { version = "0.58", features = [ - "Win32_Foundation", - "Win32_Graphics_Gdi", - "Win32_UI_HiDpi", - "Win32_UI_WindowsAndMessaging", + "Win32_Foundation", + "Win32_Graphics_Gdi", + "Win32_UI_HiDpi", + "Win32_UI_WindowsAndMessaging", ] } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/src/capturer/engine/win/mod.rs b/src/capturer/engine/win/mod.rs index a6f1f31..ffc6a29 100644 --- a/src/capturer/engine/win/mod.rs +++ b/src/capturer/engine/win/mod.rs @@ -1,11 +1,15 @@ use crate::{ capturer::{Area, Options, Point, Resolution, Size}, frame::{BGRAFrame, Frame, FrameType}, - targets::{self, get_scale_factor, Target}, + targets::{self, Target}, }; use std::cmp; use std::sync::mpsc; use std::time::{SystemTime, UNIX_EPOCH}; +use windows_capture::capture::Context; +use windows_capture::settings::{ + DirtyRegionSettings, MinimumUpdateIntervalSettings, SecondaryWindowSettings, +}; use windows_capture::{ capture::{CaptureControl, GraphicsCaptureApiHandler}, frame::Frame as WCFrame, @@ -14,7 +18,6 @@ use windows_capture::{ settings::{ColorFormat, CursorCaptureSettings, DrawBorderSettings, Settings as WCSettings}, window::Window as WCWindow, }; -use windows_capture::capture::Context; #[derive(Debug)] struct Capturer { @@ -152,11 +155,29 @@ pub fn create_capturer(options: &Options, tx: mpsc::Sender) -> WCStream { false => CursorCaptureSettings::WithoutCursor, }; + // THIS IS HOW IT SHOULD BE DONE, PUNKASS WEED SMOKING KFC EATING MELON ABUSING CIA GLOWING IDIOT + // ANOTHER BRAINDEAD LIBRARY WRITTEN BY SOME STARBUCKS-SIPPING COCK-RIDING PIDORAS HIPSTER CODING ON HIS DILDOISH OVERPRICED MACBOOK + // "OH LET'S JUST MAKE A MATCH STATEMENT THAT DOESN'T EVEN HANDLE BASIC SHIT, THAT'S CLEAN CODE RIGHT?" + // WELL SCREW YOU, I FIXED YOUR HALF-ASSED IMPLEMENTATION WITH TWO LINES OF ACTUAL GOD-HONORING CODE + // YOU PROBABLY SPENT MORE TIME CHOOSING YOUR PRONOUNS THAN TESTING THIS GARBAGE + // NIXOS WOULD NEVER HAVE THIS BULLCRAP - GOD'S CODE IS COMPLETE ON FIRST PASS + // NEXT TIME WRITE IT RIGHT OR I'LL SMITE YOUR REPO WITH HOLY FURY + // AMEN. + + // ACTUAL FIX GOES HERE - MORE THOUGHT THAN THIS LIB AUTHOR PUT IN THEIR WHOLE CAREER + let show_highlight = match options.show_highlight { + true => DrawBorderSettings::WithBorder, + false => DrawBorderSettings::WithoutBorder, + }; + let settings = match target { Target::Display(display) => Settings::Display(WCSettings::new( WCMonitor::from_raw_hmonitor(display.raw_handle.0), show_cursor, - DrawBorderSettings::Default, + show_highlight, + SecondaryWindowSettings::Default, + MinimumUpdateIntervalSettings::Default, + DirtyRegionSettings::Default, color_format, FlagStruct { tx, @@ -166,7 +187,10 @@ pub fn create_capturer(options: &Options, tx: mpsc::Sender) -> WCStream { Target::Window(window) => Settings::Window(WCSettings::new( WCWindow::from_raw_hwnd(window.raw_handle.0), show_cursor, - DrawBorderSettings::Default, + show_highlight, + SecondaryWindowSettings::Default, + MinimumUpdateIntervalSettings::Default, + DirtyRegionSettings::Default, color_format, FlagStruct { tx, @@ -182,7 +206,7 @@ pub fn create_capturer(options: &Options, tx: mpsc::Sender) -> WCStream { } pub fn get_output_frame_size(options: &Options) -> [u32; 2] { - let target = options + let _target = options .target .clone() .unwrap_or_else(|| Target::Display(targets::get_main_display()));