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/linux/window_finder_x11.h" 12 13 #include <X11/X.h> 14 15 #include <memory> 16 17 #include "modules/desktop_capture/linux/window_list_utils.h" 18 #include "rtc_base/checks.h" 19 20 namespace webrtc { 21 WindowFinderX11(XAtomCache * cache)22WindowFinderX11::WindowFinderX11(XAtomCache* cache) : cache_(cache) { 23 RTC_DCHECK(cache_); 24 } 25 26 WindowFinderX11::~WindowFinderX11() = default; 27 GetWindowUnderPoint(DesktopVector point)28WindowId WindowFinderX11::GetWindowUnderPoint(DesktopVector point) { 29 WindowId id = kNullWindowId; 30 GetWindowList(cache_, [&id, this, point](::Window window) { 31 DesktopRect rect; 32 if (GetWindowRect(this->cache_->display(), window, &rect) && 33 rect.Contains(point)) { 34 id = window; 35 return false; 36 } 37 return true; 38 }); 39 return id; 40 } 41 42 // static Create(const WindowFinder::Options & options)43std::unique_ptr<WindowFinder> WindowFinder::Create( 44 const WindowFinder::Options& options) { 45 if (options.cache == nullptr) { 46 return nullptr; 47 } 48 49 return std::make_unique<WindowFinderX11>(options.cache); 50 } 51 52 } // namespace webrtc 53