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