Zijie He | 70fbbad | 2017-08-15 15:45:00 -0700 | [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" |
| 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | WindowFinderX11::WindowFinderX11(XAtomCache* cache) |
| 19 | : cache_(cache) { |
| 20 | RTC_DCHECK(cache_); |
| 21 | } |
| 22 | |
| 23 | WindowFinderX11::~WindowFinderX11() = default; |
| 24 | |
| 25 | WindowId WindowFinderX11::GetWindowUnderPoint(DesktopVector point) { |
| 26 | WindowId id = kNullWindowId; |
| 27 | GetWindowList(cache_, |
| 28 | [&id, this, point](::Window window) { |
| 29 | DesktopRect rect; |
| 30 | if (GetWindowRect(this->cache_->display(), window, &rect) && |
| 31 | rect.Contains(point)) { |
| 32 | id = window; |
| 33 | return false; |
| 34 | } |
| 35 | return true; |
| 36 | }); |
| 37 | return id; |
| 38 | } |
| 39 | |
| 40 | } // namespace webrtc |