Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: webrtc/modules/desktop_capture/mac/window_list_utils.cc

Issue 2202883003: Icon Capture For Window Capturer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix windows crash Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h"
12
13 #include <ApplicationServices/ApplicationServices.h>
14
15 #include "webrtc/base/macutils.h"
16
17 namespace webrtc {
18
19 bool GetWindowList(WindowCapturer::WindowList* windows) {
20 // Only get on screen, non-desktop windows.
21 CFArrayRef window_array = CGWindowListCopyWindowInfo(
22 kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements,
23 kCGNullWindowID);
24 if (!window_array)
25 return false;
26
27 // Check windows to make sure they have an id, title, and use window layer
28 // other than 0.
29 CFIndex count = CFArrayGetCount(window_array);
30 for (CFIndex i = 0; i < count; ++i) {
31 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
32 CFArrayGetValueAtIndex(window_array, i));
33 CFStringRef window_title = reinterpret_cast<CFStringRef>(
34 CFDictionaryGetValue(window, kCGWindowName));
35 CFNumberRef window_id = reinterpret_cast<CFNumberRef>(
36 CFDictionaryGetValue(window, kCGWindowNumber));
37 CFNumberRef window_layer = reinterpret_cast<CFNumberRef>(
38 CFDictionaryGetValue(window, kCGWindowLayer));
39 if (window_title && window_id && window_layer) {
40 // Skip windows with layer=0 (menu, dock).
41 int layer;
42 CFNumberGetValue(window_layer, kCFNumberIntType, &layer);
43 if (layer != 0)
44 continue;
45
46 int id;
47 CFNumberGetValue(window_id, kCFNumberIntType, &id);
48 WindowCapturer::Window window;
49 window.id = id;
50 if (!rtc::ToUtf8(window_title, &(window.title)) ||
51 window.title.empty()) {
52 continue;
53 }
54 windows->push_back(window);
55 }
56 }
57
58 CFRelease(window_array);
59 return true;
60 }
61
62 // Returns true if the window is occupying a full screen.
63 bool IsWindowFullScreen(
64 const MacDesktopConfiguration& desktop_config,
65 CFDictionaryRef window) {
66 bool fullscreen = false;
67 CFDictionaryRef bounds_ref = reinterpret_cast<CFDictionaryRef>(
68 CFDictionaryGetValue(window, kCGWindowBounds));
69
70 CGRect bounds;
71 if (bounds_ref &&
72 CGRectMakeWithDictionaryRepresentation(bounds_ref, &bounds)) {
73 for (MacDisplayConfigurations::const_iterator it =
74 desktop_config.displays.begin();
75 it != desktop_config.displays.end(); ++it) {
76 if (it->bounds.equals(DesktopRect::MakeXYWH(bounds.origin.x,
77 bounds.origin.y,
78 bounds.size.width,
79 bounds.size.height))) {
80 fullscreen = true;
81 break;
82 }
83 }
84 }
85
86 return fullscreen;
87 }
88
89 // Returns true if the window is minimized.
90 bool IsWindowMinimized(CGWindowID id) {
91 CFArrayRef window_id_array =
92 CFArrayCreate(NULL, reinterpret_cast<const void **>(&id), 1, NULL);
93 CFArrayRef window_array =
94 CGWindowListCreateDescriptionFromArray(window_id_array);
95 bool minimized = false;
96
97 if (window_array && CFArrayGetCount(window_array)) {
98 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
99 CFArrayGetValueAtIndex(window_array, 0));
100 CFBooleanRef on_screen = reinterpret_cast<CFBooleanRef>(
101 CFDictionaryGetValue(window, kCGWindowIsOnscreen));
102
103 minimized = !on_screen;
104 }
105
106 CFRelease(window_id_array);
107 CFRelease(window_array);
108
109 return minimized;
110 }
111
112
113
114 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698