blob: 3096217e5bae4db952a0677a40250936942329f0 [file] [log] [blame]
Zijie He70fbbad2017-08-15 15:45:00 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/desktop_capture/window_finder_x11.h"
Zijie He70fbbad2017-08-15 15:45:00 -070012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/desktop_capture/x11/window_list_utils.h"
14#include "rtc_base/checks.h"
15#include "rtc_base/ptr_util.h"
Zijie He70fbbad2017-08-15 15:45:00 -070016
17namespace webrtc {
18
19WindowFinderX11::WindowFinderX11(XAtomCache* cache)
20 : cache_(cache) {
21 RTC_DCHECK(cache_);
22}
23
24WindowFinderX11::~WindowFinderX11() = default;
25
26WindowId WindowFinderX11::GetWindowUnderPoint(DesktopVector point) {
27 WindowId id = kNullWindowId;
28 GetWindowList(cache_,
29 [&id, this, point](::Window window) {
30 DesktopRect rect;
31 if (GetWindowRect(this->cache_->display(), window, &rect) &&
32 rect.Contains(point)) {
33 id = window;
34 return false;
35 }
36 return true;
37 });
38 return id;
39}
40
Zijie He77b7a1d2017-09-01 15:51:14 -070041// static
42std::unique_ptr<WindowFinder> WindowFinder::Create(
43 const WindowFinder::Options& options) {
44 if (options.cache == nullptr) {
45 return nullptr;
46 }
47
48 return rtc::MakeUnique<WindowFinderX11>(options.cache);
49}
50
Zijie He70fbbad2017-08-15 15:45:00 -070051} // namespace webrtc