From 01149abcb74b8901c017cbed59bd4f9974769ddd Mon Sep 17 00:00:00 2001 From: 2fckinactive <2fckinactive@gmail.com> Date: Mon, 31 Aug 2026 00:12:11 +0700 Subject: [PATCH] fix(scap-targets): enumerate top-level windows instead of desktop children 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 #2164 Co-authored-by: Cursor --- crates/scap-targets/src/platform/win.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/crates/scap-targets/src/platform/win.rs b/crates/scap-targets/src/platform/win.rs index e5f3f2764a1..58b298c9083 100644 --- a/crates/scap-targets/src/platform/win.rs +++ b/crates/scap-targets/src/platform/win.rs @@ -36,14 +36,13 @@ use windows::{ SHGetFileInfoW, }, WindowsAndMessaging::{ - DI_FLAGS, DestroyIcon, DrawIconEx, EnumChildWindows, EnumWindows, GCLP_HICON, - GW_HWNDNEXT, GWL_EXSTYLE, GWL_STYLE, GetClassLongPtrW, GetClassNameW, - GetClientRect, GetCursorPos, GetDesktopWindow, GetIconInfo, - GetLayeredWindowAttributes, GetWindow, GetWindowLongPtrW, GetWindowLongW, - GetWindowRect, GetWindowTextLengthW, GetWindowTextW, GetWindowThreadProcessId, - HICON, ICONINFO, IsIconic, IsWindowVisible, PrivateExtractIconsW, SendMessageW, - WM_GETICON, WS_CHILD, WS_EX_LAYERED, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, - WS_EX_TRANSPARENT, WindowFromPoint, + DI_FLAGS, DestroyIcon, DrawIconEx, EnumWindows, GCLP_HICON, GW_HWNDNEXT, + GWL_EXSTYLE, GWL_STYLE, GetClassLongPtrW, GetClassNameW, GetClientRect, + GetCursorPos, GetIconInfo, GetLayeredWindowAttributes, GetWindow, + GetWindowLongPtrW, GetWindowLongW, GetWindowRect, GetWindowTextLengthW, + GetWindowTextW, GetWindowThreadProcessId, HICON, ICONINFO, IsIconic, + IsWindowVisible, PrivateExtractIconsW, SendMessageW, WM_GETICON, WS_CHILD, + WS_EX_LAYERED, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_EX_TRANSPARENT, WindowFromPoint, }, }, }, @@ -329,8 +328,7 @@ impl WindowImpl { }; unsafe { - let _ = EnumChildWindows( - Some(GetDesktopWindow()), + let _ = EnumWindows( Some(enum_windows_proc), LPARAM(std::ptr::addr_of_mut!(context) as isize), );