• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 *  Copyright (c) 2017 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 "modules/desktop_capture/window_finder_mac.h"
12
13#include <CoreFoundation/CoreFoundation.h>
14
15#include <memory>
16#include <utility>
17
18#include "modules/desktop_capture/mac/desktop_configuration.h"
19#include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
20#include "modules/desktop_capture/mac/window_list_utils.h"
21
22namespace webrtc {
23
24WindowFinderMac::WindowFinderMac(
25    rtc::scoped_refptr<DesktopConfigurationMonitor> configuration_monitor)
26    : configuration_monitor_(std::move(configuration_monitor)) {}
27WindowFinderMac::~WindowFinderMac() = default;
28
29WindowId WindowFinderMac::GetWindowUnderPoint(DesktopVector point) {
30  WindowId id = kNullWindowId;
31  GetWindowList(
32      [&id, point](CFDictionaryRef window) {
33        DesktopRect bounds;
34        bounds = GetWindowBounds(window);
35        if (bounds.Contains(point)) {
36          id = GetWindowId(window);
37          return false;
38        }
39        return true;
40      },
41      true,
42      true);
43  return id;
44}
45
46// static
47std::unique_ptr<WindowFinder> WindowFinder::Create(
48    const WindowFinder::Options& options) {
49  return std::make_unique<WindowFinderMac>(options.configuration_monitor);
50}
51
52}  // namespace webrtc
53