diff --git a/modules/desktop_capture/mac/window_list_utils.cc b/modules/desktop_capture/mac/window_list_utils.cc index d2fb20ed4c..3d2ab748f1 100644 --- a/modules/desktop_capture/mac/window_list_utils.cc +++ b/modules/desktop_capture/mac/window_list_utils.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "rtc_base/checks.h" @@ -84,73 +85,88 @@ bool GetWindowList(rtc::FunctionView on_window, bool ignore_minimized, bool only_zero_layer) { RTC_DCHECK(on_window); + std::set visited_windows; // Only get on screen, non-desktop windows. // According to // https://developer.apple.com/documentation/coregraphics/cgwindowlistoption/1454105-optiononscreenonly // , when kCGWindowListOptionOnScreenOnly is used, the order of windows are in // decreasing z-order. - CFArrayRef window_array = CGWindowListCopyWindowInfo( + CFArrayRef window_array_sorted = CGWindowListCopyWindowInfo( kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID); - if (!window_array) - return false; + + CFArrayRef window_array_all = CGWindowListCopyWindowInfo( + kCGWindowListExcludeDesktopElements, kCGNullWindowID); MacDesktopConfiguration desktop_config = MacDesktopConfiguration::GetCurrent( MacDesktopConfiguration::TopLeftOrigin); - // Check windows to make sure they have an id, title, and use window layer - // other than 0. - CFIndex count = CFArrayGetCount(window_array); - for (CFIndex i = 0; i < count; i++) { - CFDictionaryRef window = reinterpret_cast( - CFArrayGetValueAtIndex(window_array, i)); - if (!window) { - continue; - } + CFArrayRef window_arrays[2] = { window_array_sorted, window_array_all }; + for (size_t array = 0; array < 2; ++array) { + CFArrayRef window_array = window_arrays[array]; + // Check windows to make sure they have an id, title, and use window layer + // other than 0. + CFIndex count = CFArrayGetCount(window_array); + for (CFIndex i = 0; i < count; i++) { + CFDictionaryRef window = reinterpret_cast( + CFArrayGetValueAtIndex(window_array, i)); + if (!window) { + continue; + } - CFNumberRef window_id = reinterpret_cast( - CFDictionaryGetValue(window, kCGWindowNumber)); - if (!window_id) { - continue; - } + WindowId window_id = GetWindowId(window); + if (window_id == kNullWindowId) { + continue; + } + if (visited_windows.count(window_id)) { + printf(" found dupe!\n"); + continue; + } + visited_windows.insert(window_id); - CFNumberRef window_layer = reinterpret_cast( - CFDictionaryGetValue(window, kCGWindowLayer)); - if (!window_layer) { - continue; - } + CFNumberRef window_layer = reinterpret_cast( + CFDictionaryGetValue(window, kCGWindowLayer)); + if (!window_layer) { + continue; + } - // Skip windows with layer!=0 (menu, dock). - int layer; - if (!CFNumberGetValue(window_layer, kCFNumberIntType, &layer)) { - continue; - } - if (only_zero_layer && layer != 0) { - continue; - } + // Skip windows with layer!=0 (menu, dock). + int layer; + if (!CFNumberGetValue(window_layer, kCFNumberIntType, &layer)) { + continue; + } + if (only_zero_layer && layer != 0) { + continue; + } - // Skip windows that are minimized and not full screen. - if (ignore_minimized && !IsWindowOnScreen(window) && - !IsWindowFullScreen(desktop_config, window)) { - continue; - } +/* + // Skip windows that are minimized and not full screen. + if (ignore_minimized && !IsWindowOnScreen(window) && + !IsWindowFullScreen(desktop_config, window)) { + printf(" ignore minimized and not on screen..!\n"); + continue; + } - // If window title is empty, only consider it if it is either on screen or - // fullscreen. - CFStringRef window_title = reinterpret_cast( - CFDictionaryGetValue(window, kCGWindowName)); - if (!window_title && !IsWindowOnScreen(window) && - !IsWindowFullScreen(desktop_config, window)) { - continue; - } + // If window title is empty, only consider it if it is either on screen or + // fullscreen. + CFStringRef window_title = reinterpret_cast( + CFDictionaryGetValue(window, kCGWindowName)); + if (!window_title && !IsWindowOnScreen(window) && + !IsWindowFullScreen(desktop_config, window)) { + printf(" not on screen..!\n"); + continue; + } +*/ - if (!on_window(window)) { - break; + if (!on_window(window)) { + break; + } } } - CFRelease(window_array); + CFRelease(window_array_sorted); + CFRelease(window_array_all); return true; }