blob: d929460eca4372929a88ccca92bb205ff240b882 [file] [log] [blame]
Zijie Head9e2382017-08-15 22:45:001/*
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 "webrtc/modules/desktop_capture/window_finder_x11.h"
12
13#include "webrtc/modules/desktop_capture/x11/window_list_utils.h"
14#include "webrtc/rtc_base/checks.h"
Zijie He45288b72017-09-01 22:51:1415#include "webrtc/rtc_base/ptr_util.h"
Zijie Head9e2382017-08-15 22:45:0016
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 He45288b72017-09-01 22:51:1441// 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 Head9e2382017-08-15 22:45:0051} // namespace webrtc