blob: ad134df36d4aa03bd41b7b746e90f141fac00077 [file] [log] [blame]
sergeyu@chromium.org2767b532013-10-16 02:42:381/*
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 Bonadei92ea95e2017-09-15 04:47:3111#ifndef MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
12#define MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
sergeyu@chromium.org2767b532013-10-16 02:42:3813
Zijie Hecd66a772017-07-21 21:13:4614#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "modules/desktop_capture/desktop_capture_types.h"
17#include "modules/desktop_capture/desktop_geometry.h"
Mirko Bonadei66e76792019-04-02 09:33:5918#include "rtc_base/system/rtc_export.h"
sergeyu@chromium.org2767b532013-10-16 02:42:3819
20namespace webrtc {
21
22class DesktopCaptureOptions;
23class DesktopFrame;
24class MouseCursor;
25
26// Captures mouse shape and position.
27class MouseCursorMonitor {
28 public:
Zijie Hecd66a772017-07-21 21:13:4629 // Deprecated: CursorState will not be provided.
sergeyu@chromium.org2767b532013-10-16 02:42:3830 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 Titovcec43432021-07-28 21:35:3950 // take ownership of `cursor`.
sergeyu@chromium.org2767b532013-10-16 02:42:3851 virtual void OnMouseCursor(MouseCursor* cursor) = 0;
52
Artem Titovcec43432021-07-28 21:35:3953 // Called in response to Capture(). `position` indicates cursor position
54 // relative to the `window` specified in the constructor.
Zijie Hecd66a772017-07-21 21:13:4655 // Deprecated: use the following overload instead.
sergeyu@chromium.org2767b532013-10-16 02:42:3856 virtual void OnMouseCursorPosition(CursorState state,
Jamie Walch4b47dd32020-01-17 21:52:4857 const DesktopVector& position) {}
sergeyu@chromium.org2767b532013-10-16 02:42:3858
Artem Titovcec43432021-07-28 21:35:3959 // Called in response to Capture(). `position` indicates cursor absolute
Zijie Hecd66a772017-07-21 21:13:4660 // position on the system in fullscreen coordinate, i.e. the top-left
61 // monitor always starts from (0, 0).
braveyao90394a42018-05-17 17:30:3562 // The coordinates of the position is controlled by OS, but it's always
63 // consistent with DesktopFrame.rect().top_left().
Zijie Hecd66a772017-07-21 21:13:4664 // TODO(zijiehe): Ensure all implementations return the absolute position.
Zijie Hecd66a772017-07-21 21:13:4665 // 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.org2767b532013-10-16 02:42:3869 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 Hecd66a772017-07-21 21:13:4677 //
78 // Deprecated: use Create() function.
sergeyu@chromium.org2767b532013-10-16 02:42:3879 static MouseCursorMonitor* CreateForWindow(
80 const DesktopCaptureOptions& options,
81 WindowId window);
82
Zijie Hecd66a772017-07-21 21:13:4683 // Creates a capturer that monitors the mouse cursor shape and position over
84 // the specified screen.
sergeyu@chromium.org2767b532013-10-16 02:42:3885 //
Zijie Hecd66a772017-07-21 21:13:4686 // Deprecated: use Create() function.
Mirko Bonadei66e76792019-04-02 09:33:5987 static RTC_EXPORT MouseCursorMonitor* CreateForScreen(
jiayl@webrtc.org017b6192014-01-14 18:26:3788 const DesktopCaptureOptions& options,
89 ScreenId screen);
sergeyu@chromium.org2767b532013-10-16 02:42:3890
Zijie Hecd66a772017-07-21 21:13:4691 // 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).
Salmanabb64162023-01-18 22:04:0994 static RTC_EXPORT std::unique_ptr<MouseCursorMonitor> Create(
Zijie Hecd66a772017-07-21 21:13:4695 const DesktopCaptureOptions& options);
96
Artem Titovcec43432021-07-28 21:35:3997 // Initializes the monitor with the `callback`, which must remain valid until
sergeyu@chromium.org2767b532013-10-16 02:42:3898 // capturer is destroyed.
99 virtual void Init(Callback* callback, Mode mode) = 0;
100
Artem Titovcec43432021-07-28 21:35:39101 // Captures current cursor shape and position (depending on the `mode` passed
sergeyu@chromium.org2767b532013-10-16 02:42:38102 // 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 Bonadei92ea95e2017-09-15 04:47:31111#endif // MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_