Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: exclude ignored windows from monitor screenshots via SCK (#2899) (#2901)

Louis Beaumont61212c42989f
diff --git a/Cargo.lock b/Cargo.lock
index a637155ba..4e2f9a84d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1012,9 +1012,9 @@ dependencies = [
[[package]]
name = "cc"
-version = "1.2.59"
+version = "1.2.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7a4d3ec6524d28a329fc53654bbadc9bdd7b0431f5d65f1a56ffb28a1ee5283"
+checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1"
dependencies = [
"find-msvc-tools",
"jobserver",
@@ -1150,7 +1150,7 @@ dependencies = [
[[package]]
name = "cidre"
version = "0.15.0"
-source = "git+https://github.com/yury/cidre.git#ee0a48a2f8be4b4433e34db06bee46c3346a91a8"
+source = "git+https://github.com/yury/cidre.git#34638ae16c5226d3c349953fcdd46533e3379a17"
dependencies = [
"cc",
"cidre-macros 0.5.0",
@@ -1986,7 +1986,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users 0.5.2",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -2276,7 +2276,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -3242,7 +3242,7 @@ dependencies = [
"hyper",
"libc",
"pin-project-lite",
- "socket2 0.6.3",
+ "socket2 0.5.10",
"tokio",
"tower-service",
"tracing",
@@ -3592,7 +3592,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
dependencies = [
"hermit-abi",
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -4551,7 +4551,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -5801,7 +5801,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"
dependencies = [
"anyhow",
- "itertools 0.14.0",
+ "itertools 0.10.5",
"proc-macro2",
"quote",
"syn 2.0.117",
@@ -5878,7 +5878,7 @@ dependencies = [
"quinn-udp",
"rustc-hash 2.1.2",
"rustls 0.23.37",
- "socket2 0.6.3",
+ "socket2 0.5.10",
"thiserror 2.0.18",
"tokio",
"tracing",
@@ -5915,9 +5915,9 @@ dependencies = [
"cfg_aliases",
"libc",
"once_cell",
- "socket2 0.6.3",
+ "socket2 0.5.10",
"tracing",
- "windows-sys 0.60.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -6516,7 +6516,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -6702,7 +6702,7 @@ dependencies = [
[[package]]
name = "sck-rs"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/sck-rs#c088aedbba5c07dfbf5ac43870fbdf93fa401ca0"
+source = "git+https://github.com/screenpipe/sck-rs#8151b16b705f91716ed8c10c54fb42c94fce9b8d"
dependencies = [
"cidre 0.15.0",
"image",
@@ -8294,7 +8294,7 @@ dependencies = [
"getrandom 0.4.2",
"once_cell",
"rustix 1.1.4",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -9570,7 +9570,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.48.0",
]
[[package]]
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index adc8ffc8f..b16cd2983 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9670,7 +9670,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.3.50"
+version = "2.3.51"
dependencies = [
"anyhow",
"arboard",
diff --git a/crates/screenpipe-engine/src/event_driven_capture.rs b/crates/screenpipe-engine/src/event_driven_capture.rs
index 7d15f6914..5ff69352a 100644
--- a/crates/screenpipe-engine/src/event_driven_capture.rs
+++ b/crates/screenpipe-engine/src/event_driven_capture.rs
@@ -19,6 +19,7 @@ use screenpipe_db::DatabaseManager;
use screenpipe_screen::frame_comparison::{FrameComparer, FrameComparisonConfig};
use screenpipe_screen::monitor::SafeMonitor;
use screenpipe_screen::snapshot_writer::SnapshotWriter;
+use screenpipe_screen::capture_screenshot_by_window::{get_excluded_sck_window_ids, WindowFilters};
use screenpipe_screen::utils::capture_monitor_image;
use std::collections::HashMap;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -448,7 +449,7 @@ pub async fn event_driven_capture_loop(
{
last_visual_check = Instant::now();
if let Some(ref mut comparer) = frame_comparer {
- match capture_monitor_image(&monitor).await {
+ match capture_monitor_image(&monitor, &[]).await {
Ok((image, _dur)) => {
let diff = comparer.compare(&image);
if diff > visual_change_threshold {
@@ -767,8 +768,17 @@ async fn do_capture(
) -> Result<CaptureOutput> {
let captured_at = Utc::now();
- // Take screenshot
- let (image, capture_dur) = capture_monitor_image(params.monitor).await?;
+ // Resolve ignored windows to SCK window IDs so ScreenCaptureKit
+ // excludes them from the capture buffer (zero overhead, pixel-perfect).
+ let window_filters = WindowFilters::new(
+ &params.tree_walker_config.ignored_windows,
+ &params.tree_walker_config.included_windows,
+ &[],
+ );
+ let excluded_ids = get_excluded_sck_window_ids(&window_filters);
+
+ // Take screenshot (with ignored windows excluded at the OS level)
+ let (image, capture_dur) = capture_monitor_image(params.monitor, &excluded_ids).await?;
debug!(
"screenshot captured in {:?} for monitor {}",
capture_dur, params.monitor_id
diff --git a/crates/screenpipe-screen/src/capture_screenshot_by_window.rs b/crates/screenpipe-screen/src/capture_screenshot_by_window.rs
index 06ad58ccc..662000af7 100644
--- a/crates/screenpipe-screen/src/capture_screenshot_by_window.rs
+++ b/crates/screenpipe-screen/src/capture_screenshot_by_window.rs
@@ -959,6 +959,57 @@ fn get_all_windows() -> Result<Vec<WindowData>, Box<dyn Error>> {
.collect())
}
+/// Resolve ignored/included window filters to SCK window IDs (macOS only).
+///
+/// Enumerates all on-screen windows, checks each against `WindowFilters::is_valid()`,
+/// and returns the SCK window IDs of windows that should be excluded from capture.
+/// These IDs can be passed to `capture_image_excluding()` so ScreenCaptureKit
+/// never renders those windows into the capture buffer.
+///
+/// Returns an empty vec if no windows match the filters or on error.
+#[cfg(target_os = "macos")]
+pub fn get_excluded_sck_window_ids(window_filters: &WindowFilters) -> Vec<u32> {
+ if window_filters.ignore_set.is_empty() && window_filters.include_set.is_empty() {
+ return Vec::new();
+ }
+
+ let windows = match SckWindow::all() {
+ Ok(w) => w,
+ Err(e) => {
+ debug!("get_excluded_sck_window_ids: failed to enumerate windows: {}", e);
+ return Vec::new();
+ }
+ };
+
+ let mut excluded = Vec::new();
+ for w in &windows {
+ let app_name = w.app_name().unwrap_or_default();
+ let title = w.title().unwrap_or_default();
+
+ if app_name.is_empty() {
+ continue;
+ }
+
+ if !window_filters.is_valid(&app_name, &title) {
+ if let Ok(id) = w.id() {
+ excluded.push(id);
+ }
+ }
+ }
+
+ if !excluded.is_empty() {
+ debug!("resolved {} ignored window(s) to SCK IDs: {:?}", excluded.len(), excluded);
+ }
+
+ excluded
+}
+
+/// Non-macOS stub — SCK exclusion is not available.
+#[cfg(not(target_os = "macos"))]
+pub fn get_excluded_sck_window_ids(_window_filters: &WindowFilters) -> Vec<u32> {
+ Vec::new()
+}
+
pub async fn capture_all_visible_windows(
monitor: &SafeMonitor,
window_filters: &WindowFilters,
diff --git a/crates/screenpipe-screen/src/core.rs b/crates/screenpipe-screen/src/core.rs
index 317043927..bff3acce1 100644
--- a/crates/screenpipe-screen/src/core.rs
+++ b/crates/screenpipe-screen/src/core.rs
@@ -4,8 +4,7 @@
#[cfg(target_os = "macos")]
use crate::apple::perform_ocr_apple;
-use crate::capture_screenshot_by_window::CapturedWindow;
-use crate::capture_screenshot_by_window::WindowFilters;
+use crate::capture_screenshot_by_window::{get_excluded_sck_window_ids, CapturedWindow, WindowFilters};
use crate::custom_ocr::perform_ocr_custom;
use crate::frame_comparison::{FrameComparer, FrameComparisonConfig};
use crate::metrics::PipelineMetrics;
@@ -208,7 +207,7 @@ pub async fn continuous_capture(
let mut captured = None;
for attempt in 0..=MAX_CAPTURE_RETRIES {
- match capture_monitor_image(&monitor).await {
+ match capture_monitor_image(&monitor, &get_excluded_sck_window_ids(&window_filters)).await {
Ok(result) => {
if attempt > 0 {
debug!(
diff --git a/crates/screenpipe-screen/src/monitor.rs b/crates/screenpipe-screen/src/monitor.rs
index 0631270f8..f8882f289 100644
--- a/crates/screenpipe-screen/src/monitor.rs
+++ b/crates/screenpipe-screen/src/monitor.rs
@@ -295,6 +295,57 @@ impl SafeMonitor {
Ok(image)
}
+ /// Capture an image excluding the given SCK window IDs (macOS only).
+ /// The OS won't render excluded windows into the capture buffer.
+ #[cfg(target_os = "macos")]
+ pub async fn capture_image_excluding(
+ &self,
+ excluded_window_ids: &[u32],
+ ) -> Result<DynamicImage> {
+ if excluded_window_ids.is_empty() {
+ return self.capture_image().await;
+ }
+
+ let monitor_id = self.monitor_id;
+ let use_sck = self.use_sck;
+ let cached_sck = self.cached_sck.clone();
+ let ids = excluded_window_ids.to_vec();
+
+ let image = tokio::task::spawn_blocking(move || -> Result<DynamicImage> {
+ cidre::objc::ar_pool(|| -> Result<DynamicImage, String> {
+ if use_sck {
+ let monitor = match cached_sck {
+ Some(m) => m,
+ None => {
+ SckMonitor::all()
+ .map_err(|e| format!("{}", e))?
+ .into_iter()
+ .find(|m| m.id() == monitor_id)
+ .ok_or_else(|| "Monitor not found".to_string())?
+ }
+ };
+
+ if monitor.width().unwrap_or(0) == 0 || monitor.height().unwrap_or(0) == 0 {
+ return Err("Invalid monitor dimensions".to_string());
+ }
+
+ monitor
+ .capture_image_excluding(&ids)
+ .map_err(|e| format!("{}", e))
+ .map(DynamicImage::ImageRgba8)
+ } else {
+ // xcap fallback doesn't support exclusion — capture normally
+ Err("capture_image_excluding not supported on xcap path".to_string())
+ }
+ })
+ .map_err(|s| anyhow::anyhow!(s))
+ })
+ .await
+ .map_err(|e| anyhow::anyhow!("capture task panicked: {}", e))??;
+
+ Ok(image)
+ }
+
// Non-macOS: Use persistent WGC capture on Windows to avoid orange border flash.
// Falls back to per-frame xcap capture if persistent session fails.
#[cfg(not(target_os = "macos"))]
diff --git a/crates/screenpipe-screen/src/utils.rs b/crates/screenpipe-screen/src/utils.rs
index 4627dcf47..644866c5e 100644
--- a/crates/screenpipe-screen/src/utils.rs
+++ b/crates/screenpipe-screen/src/utils.rs
@@ -170,14 +170,33 @@ pub fn compare_images_ssim(image1: &DynamicImage, image2: &DynamicImage) -> f64
/// Capture only the monitor screenshot (no window capture, no hash).
/// Window capture is deferred until after frame comparison to avoid
/// expensive work on frames that will be skipped.
+///
+/// `excluded_window_ids` — SCK window IDs to exclude from the capture
+/// (macOS only). The OS won't render those windows into the buffer.
+/// Pass an empty slice to capture everything.
pub async fn capture_monitor_image(
monitor: &SafeMonitor,
+ #[allow(unused_variables)] excluded_window_ids: &[u32],
) -> Result<(DynamicImage, Duration), anyhow::Error> {
let capture_start = Instant::now();
+
+ #[cfg(target_os = "macos")]
+ let image = if excluded_window_ids.is_empty() {
+ monitor.capture_image().await
+ } else {
+ monitor.capture_image_excluding(excluded_window_ids).await
+ }
+ .map_err(|e| {
+ debug!("failed to capture monitor image: {}", e);
+ anyhow::anyhow!("monitor capture failed: {}", e)
+ })?;
+
+ #[cfg(not(target_os = "macos"))]
let image = monitor.capture_image().await.map_err(|e| {
debug!("failed to capture monitor image: {}", e);
anyhow::anyhow!("monitor capture failed: {}", e)
})?;
+
let capture_duration = capture_start.elapsed();
Ok((image, capture_duration))
}