Zijie He | b010a32 | 2017-08-07 15:25:01 -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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/desktop_capture/window_finder_win.h" |
Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 12 | |
| 13 | #include <windows.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/ptr_util.h" |
Zijie He | 77b7a1d | 2017-09-01 15:51:14 -0700 | [diff] [blame] | 16 | |
Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
Zijie He | 70fbbad | 2017-08-15 15:45:00 -0700 | [diff] [blame] | 19 | WindowFinderWin::WindowFinderWin() = default; |
| 20 | WindowFinderWin::~WindowFinderWin() = default; |
| 21 | |
| 22 | WindowId WindowFinderWin::GetWindowUnderPoint(DesktopVector point) { |
Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 23 | HWND window = WindowFromPoint(POINT { point.x(), point.y() }); |
| 24 | if (!window) { |
| 25 | return kNullWindowId; |
| 26 | } |
| 27 | |
| 28 | // The difference between GA_ROOTOWNER and GA_ROOT can be found at |
| 29 | // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/Hirr_DkuZdw. |
| 30 | // In short, we should use GA_ROOT, since we only care about the root window |
| 31 | // but not the owner. |
| 32 | window = GetAncestor(window, GA_ROOT); |
| 33 | if (!window) { |
| 34 | return kNullWindowId; |
| 35 | } |
| 36 | |
| 37 | return reinterpret_cast<WindowId>(window); |
| 38 | } |
| 39 | |
Zijie He | 77b7a1d | 2017-09-01 15:51:14 -0700 | [diff] [blame] | 40 | // static |
| 41 | std::unique_ptr<WindowFinder> WindowFinder::Create( |
| 42 | const WindowFinder::Options& options) { |
| 43 | return rtc::MakeUnique<WindowFinderWin>(); |
| 44 | } |
| 45 | |
Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 46 | } // namespace webrtc |