Zijie He | ad9e238 | 2017-08-15 22:45:00 | [diff] [blame] | 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 "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 He | 45288b7 | 2017-09-01 22:51:14 | [diff] [blame] | 15 | #include "webrtc/rtc_base/ptr_util.h" |
Zijie He | ad9e238 | 2017-08-15 22:45:00 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | WindowFinderX11::WindowFinderX11(XAtomCache* cache) |
| 20 | : cache_(cache) { |
| 21 | RTC_DCHECK(cache_); |
| 22 | } |
| 23 | |
| 24 | WindowFinderX11::~WindowFinderX11() = default; |
| 25 | |
| 26 | WindowId 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 He | 45288b7 | 2017-09-01 22:51:14 | [diff] [blame] | 41 | // static |
| 42 | std::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 He | ad9e238 | 2017-08-15 22:45:00 | [diff] [blame] | 51 | } // namespace webrtc |