fix(scap-targets): enumerate top-level windows instead of desktop children - #2173
Closed
matthewdonsemail-lab wants to merge 1 commit into
Closed
Conversation
…ldren WindowImpl::list() used EnumChildWindows(Some(GetDesktopWindow()), ...), which enumerates child windows beneath the desktop. Top-level application windows are not children of the desktop in the sense EnumChildWindows traverses, so cap targets windows --json returned [] even with a visible eligible window open. Switch to EnumWindows, matching the existing pattern in get_topmost_at_cursor_fallback(). The callback signature, validity filters, and LPARAM context passing are unchanged. Remove the now-unused EnumChildWindows and GetDesktopWindow imports. Fixes CapSoftware#2164 Co-authored-by: Cursor <cursoragent@cursor.com>
Manage your Superagent protectionSuperagent has paused scans for this repository because this unlinked GitHub App installation has used all three included PR scans. You have 0 of 3 included PR scans remaining. Create a free account to continue protection, manage scan settings, review security history, and control which repositories are protected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cap targets windows --jsonreturning[]on Windows even when a visible eligible top-level application window is open.WindowImpl::list()incrates/scap-targets/src/platform/win.rswas callingEnumChildWindows(Some(GetDesktopWindow()), ...), which enumerates child windows beneath the desktop rather than top-level application windows. Top-level application windows are not discovered this way, so the list came back empty.EnumWindows, matching the pattern already used byget_topmost_at_cursor_fallback()in the same file. The callback signature (enum_windows_proc), validity filters (visibility, child/tool-window exclusion, ignored executables, Cap-owned window exclusion), andLPARAMcontext-passing are unchanged.EnumChildWindowsandGetDesktopWindowimports.Fixes #2164
Research
A subagent investigation of the Rust coding conventions in this codebase confirmed the fix follows project style:
windows::modules grouped by hierarchy. Unused imports should be removed (nouse windows::Win32::*glob imports).//line comments are used. This change adds none.unsafe { ... }blocks withlet _ = ApiCall(...)for discardedBOOLresults — the existing call site already follows this and is preserved.cargo fmt --allandcargo check -p scap-targetsboth pass clean after the change.Diff
WindowsAndMessaging::{ - DI_FLAGS, DestroyIcon, DrawIconEx, EnumChildWindows, EnumWindows, GCLP_HICON, - GW_HWNDNEXT, GWL_EXSTYLE, GWL_STYLE, GetClassLongPtrW, GetClassNameW, - GetClientRect, GetCursorPos, GetDesktopWindow, GetIconInfo, + DI_FLAGS, DestroyIcon, DrawIconEx, EnumWindows, GCLP_HICON, GW_HWNDNEXT, + GWL_EXSTYLE, GWL_STYLE, GetClassLongPtrW, GetClassNameW, GetClientRect, + GetCursorPos, GetIconInfo, GetLayeredWindowAttributes, GetWindow, ... unsafe { - let _ = EnumChildWindows( - Some(GetDesktopWindow()), + let _ = EnumWindows( Some(enum_windows_proc), LPARAM(std::ptr::addr_of_mut!(context) as isize), );Test plan
cap targets windows --jsonreturns at least one target instead of[].HWNDrepresentation used bycrates/scap-targets/src/platform/win.rs.cap record start --window <id>without requiringpywin32in the consuming application.cargo fmt --all -- --checkpasses.cargo check -p scap-targetspasses with no warnings.Greptile Summary
This PR fixes Windows capture-target discovery by replacing desktop-child enumeration with top-level window enumeration while preserving the existing eligibility callback and filters.
EnumWindowsto discover top-level application windows.EnumChildWindowsandGetDesktopWindowimports.LPARAMcontext-passing behavior unchanged.Confidence Score: 5/5
The PR appears safe to merge, with no actionable regressions identified in the changed Windows enumeration path.
The new API enumerates the top-level windows required by target listing, while existing downstream validation preserves the intended eligibility constraints.
Important Files Changed
WindowImpl::list()to top-level window enumeration; downstream validation continues to exclude invalid, child, tool, cloaked, system, and Cap-owned targets.Reviews (1): Last reviewed commit: "fix(scap-targets): enumerate top-level w..." | Re-trigger Greptile