Skip to main content

capture_window_impl

Function capture_window_impl 

Source
pub(crate) fn capture_window_impl(
    title_contains: Option<&str>,
    index: Option<usize>,
    pid: Option<u32>,
    resolved: &mut Option<(CaptureTier, String)>,
) -> Result<CaptureOutcome>
Expand description

The actual CaptureWindow logic — window enumeration, own-instance and third-party-app exclusion, targeting (by pid or by title), capture, and save. Extracted to its own function (rather than living inline in the "CaptureWindow" => match arm) so its Result can be captured once and unconditionally audit-logged by the caller before propagating — see audit_log_capture_window.

index: None with more than one title_contains match is an error listing every candidate, NOT a silent pick of match 0 — see docs/reports/REPORT_AGENT_SCREENSHOT_WINDOW_CONTROL_BLOCKERS_2026_08_24.md §1 for the real incident (an ambiguous match silently captured an unrelated, sensitive window) this specifically fixes. index: Some(i) is still honored directly against whatever matched, unchanged from the original behavior, for callers who already disambiguate explicitly.