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 #ifndef MODULES_DESKTOP_CAPTURE_MAC_WINDOW_LIST_UTILS_H_
12 #define MODULES_DESKTOP_CAPTURE_MAC_WINDOW_LIST_UTILS_H_
13 
14 #include <ApplicationServices/ApplicationServices.h>
15 
16 #include <string>
17 #include "api/function_view.h"
18 #include "modules/desktop_capture/desktop_capture_types.h"
19 #include "modules/desktop_capture/desktop_capturer.h"
20 #include "modules/desktop_capture/desktop_geometry.h"
21 #include "modules/desktop_capture/mac/desktop_configuration.h"
22 
23 namespace webrtc {
24 
25 // Iterates all on-screen windows in decreasing z-order and sends them
26 // one-by-one to |on_window| function. If |on_window| returns false, this
27 // function returns immediately. GetWindowList() returns false if native APIs
28 // failed. Menus, dock (if |only_zero_layer|), minimized windows (if
29 // |ignore_minimized| is true) and any windows which do not have a valid window
30 // id or title will be ignored.
31 bool GetWindowList(rtc::FunctionView<bool(CFDictionaryRef)> on_window,
32                    bool ignore_minimized,
33                    bool only_zero_layer);
34 
35 // Another helper function to get the on-screen windows.
36 bool GetWindowList(DesktopCapturer::SourceList* windows,
37                    bool ignore_minimized,
38                    bool only_zero_layer);
39 
40 // Returns true if the window is occupying a full screen.
41 bool IsWindowFullScreen(const MacDesktopConfiguration& desktop_config,
42                         CFDictionaryRef window);
43 
44 // Returns true if the window is occupying a full screen.
45 bool IsWindowFullScreen(const MacDesktopConfiguration& desktop_config,
46                         CGWindowID id);
47 
48 // Returns true if the |window| is on screen. This function returns false if
49 // native APIs fail.
50 bool IsWindowOnScreen(CFDictionaryRef window);
51 
52 // Returns true if the window is on screen. This function returns false if
53 // native APIs fail or |id| cannot be found.
54 bool IsWindowOnScreen(CGWindowID id);
55 
56 // Returns utf-8 encoded title of |window|. If |window| is not a window or no
57 // valid title can be retrieved, this function returns an empty string.
58 std::string GetWindowTitle(CFDictionaryRef window);
59 
60 // Returns utf-8 encoded title of window |id|. If |id| cannot be found or no
61 // valid title can be retrieved, this function returns an empty string.
62 std::string GetWindowTitle(CGWindowID id);
63 
64 // Returns utf-8 encoded owner name of |window|. If |window| is not a window or
65 // if no valid owner name can be retrieved, returns an empty string.
66 std::string GetWindowOwnerName(CFDictionaryRef window);
67 
68 // Returns utf-8 encoded owner name of the given window |id|. If |id| cannot be
69 // found or if no valid owner name can be retrieved, returns an empty string.
70 std::string GetWindowOwnerName(CGWindowID id);
71 
72 // Returns id of |window|. If |window| is not a window or the window id cannot
73 // be retrieved, this function returns kNullWindowId.
74 WindowId GetWindowId(CFDictionaryRef window);
75 
76 // Returns the pid of the process owning |window|. Return 0 if |window| is not
77 // a window or no valid owner can be retrieved.
78 int GetWindowOwnerPid(CFDictionaryRef window);
79 
80 // Returns the pid of the process owning the window |id|. Return 0 if |id|
81 // cannot be found or no valid owner can be retrieved.
82 int GetWindowOwnerPid(CGWindowID id);
83 
84 // Returns the DIP to physical pixel scale at |position|. |position| is in
85 // *unscaled* system coordinate, i.e. it's device-independent and the primary
86 // monitor starts from (0, 0). If |position| is out of the system display, this
87 // function returns 1.
88 float GetScaleFactorAtPosition(const MacDesktopConfiguration& desktop_config,
89                                DesktopVector position);
90 
91 // Returns the DIP to physical pixel scale factor of the window with |id|.
92 // The bounds of the window with |id| is in DIP coordinates and |size| is the
93 // CGImage size of the window with |id| in physical coordinates. Comparing them
94 // can give the current scale factor.
95 // If the window overlaps multiple monitors, OS will decide on which monitor the
96 // window is displayed and use its scale factor to the window. So this method
97 // still works.
98 float GetWindowScaleFactor(CGWindowID id, DesktopSize size);
99 
100 // Returns the bounds of |window|. If |window| is not a window or the bounds
101 // cannot be retrieved, this function returns an empty DesktopRect. The returned
102 // DesktopRect is in system coordinate, i.e. the primary monitor always starts
103 // from (0, 0).
104 // Deprecated: This function should be avoided in favor of the overload with
105 // MacDesktopConfiguration.
106 DesktopRect GetWindowBounds(CFDictionaryRef window);
107 
108 // Returns the bounds of window with |id|. If |id| does not represent a window
109 // or the bounds cannot be retrieved, this function returns an empty
110 // DesktopRect. The returned DesktopRect is in system coordinates.
111 // Deprecated: This function should be avoided in favor of the overload with
112 // MacDesktopConfiguration.
113 DesktopRect GetWindowBounds(CGWindowID id);
114 
115 }  // namespace webrtc
116 
117 #endif  // MODULES_DESKTOP_CAPTURE_MAC_WINDOW_LIST_UTILS_H_
118