sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_ |
| 12 | #define MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_ |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 13 | |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "modules/desktop_capture/desktop_capture_types.h" |
| 17 | #include "modules/desktop_capture/desktop_geometry.h" |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 18 | #include "rtc_base/system/rtc_export.h" |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class DesktopCaptureOptions; |
| 23 | class DesktopFrame; |
| 24 | class MouseCursor; |
| 25 | |
| 26 | // Captures mouse shape and position. |
| 27 | class MouseCursorMonitor { |
| 28 | public: |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 29 | // Deprecated: CursorState will not be provided. |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 30 | enum CursorState { |
| 31 | // Cursor on top of the window including window decorations. |
| 32 | INSIDE, |
| 33 | |
| 34 | // Cursor is outside of the window. |
| 35 | OUTSIDE, |
| 36 | }; |
| 37 | |
| 38 | enum Mode { |
| 39 | // Capture only shape of the mouse cursor, but not position. |
| 40 | SHAPE_ONLY, |
| 41 | |
| 42 | // Capture both, mouse cursor shape and position. |
| 43 | SHAPE_AND_POSITION, |
| 44 | }; |
| 45 | |
| 46 | // Callback interface used to pass current mouse cursor position and shape. |
| 47 | class Callback { |
| 48 | public: |
| 49 | // Called in response to Capture() when the cursor shape has changed. Must |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 50 | // take ownership of `cursor`. |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 51 | virtual void OnMouseCursor(MouseCursor* cursor) = 0; |
| 52 | |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 53 | // Called in response to Capture(). `position` indicates cursor position |
| 54 | // relative to the `window` specified in the constructor. |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 55 | // Deprecated: use the following overload instead. |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 56 | virtual void OnMouseCursorPosition(CursorState state, |
Jamie Walch | 4b47dd3 | 2020-01-17 21:52:48 | [diff] [blame] | 57 | const DesktopVector& position) {} |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 58 | |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 59 | // Called in response to Capture(). `position` indicates cursor absolute |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 60 | // position on the system in fullscreen coordinate, i.e. the top-left |
| 61 | // monitor always starts from (0, 0). |
braveyao | 90394a4 | 2018-05-17 17:30:35 | [diff] [blame] | 62 | // The coordinates of the position is controlled by OS, but it's always |
| 63 | // consistent with DesktopFrame.rect().top_left(). |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 64 | // TODO(zijiehe): Ensure all implementations return the absolute position. |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 65 | // TODO(zijiehe): Current this overload works correctly only when capturing |
| 66 | // mouse cursor against fullscreen. |
| 67 | virtual void OnMouseCursorPosition(const DesktopVector& position) {} |
| 68 | |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 69 | protected: |
| 70 | virtual ~Callback() {} |
| 71 | }; |
| 72 | |
| 73 | virtual ~MouseCursorMonitor() {} |
| 74 | |
| 75 | // Creates a capturer that notifies of mouse cursor events while the cursor is |
| 76 | // over the specified window. |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 77 | // |
| 78 | // Deprecated: use Create() function. |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 79 | static MouseCursorMonitor* CreateForWindow( |
| 80 | const DesktopCaptureOptions& options, |
| 81 | WindowId window); |
| 82 | |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 83 | // Creates a capturer that monitors the mouse cursor shape and position over |
| 84 | // the specified screen. |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 85 | // |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 86 | // Deprecated: use Create() function. |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 87 | static RTC_EXPORT MouseCursorMonitor* CreateForScreen( |
jiayl@webrtc.org | 017b619 | 2014-01-14 18:26:37 | [diff] [blame] | 88 | const DesktopCaptureOptions& options, |
| 89 | ScreenId screen); |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 90 | |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 91 | // Creates a capturer that monitors the mouse cursor shape and position across |
| 92 | // the entire desktop. The capturer ensures that the top-left monitor starts |
| 93 | // from (0, 0). |
Salman | abb6416 | 2023-01-18 22:04:09 | [diff] [blame] | 94 | static RTC_EXPORT std::unique_ptr<MouseCursorMonitor> Create( |
Zijie He | cd66a77 | 2017-07-21 21:13:46 | [diff] [blame] | 95 | const DesktopCaptureOptions& options); |
| 96 | |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 97 | // Initializes the monitor with the `callback`, which must remain valid until |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 98 | // capturer is destroyed. |
| 99 | virtual void Init(Callback* callback, Mode mode) = 0; |
| 100 | |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 101 | // Captures current cursor shape and position (depending on the `mode` passed |
sergeyu@chromium.org | 2767b53 | 2013-10-16 02:42:38 | [diff] [blame] | 102 | // to Init()). Calls Callback::OnMouseCursor() if cursor shape has |
| 103 | // changed since the last call (or when Capture() is called for the first |
| 104 | // time) and then Callback::OnMouseCursorPosition() if mode is set to |
| 105 | // SHAPE_AND_POSITION. |
| 106 | virtual void Capture() = 0; |
| 107 | }; |
| 108 | |
| 109 | } // namespace webrtc |
| 110 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 111 | #endif // MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_ |