1 /* 2 * Copyright (c) 2022 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/wayland/mouse_cursor_monitor_pipewire.h" 12 13 #include <utility> 14 15 #include "modules/desktop_capture/desktop_capture_options.h" 16 #include "modules/desktop_capture/desktop_capturer.h" 17 #include "rtc_base/checks.h" 18 #include "rtc_base/logging.h" 19 20 namespace webrtc { 21 MouseCursorMonitorPipeWire(const DesktopCaptureOptions & options)22MouseCursorMonitorPipeWire::MouseCursorMonitorPipeWire( 23 const DesktopCaptureOptions& options) 24 : options_(options) { 25 sequence_checker_.Detach(); 26 } 27 ~MouseCursorMonitorPipeWire()28MouseCursorMonitorPipeWire::~MouseCursorMonitorPipeWire() {} 29 Init(Callback * callback,Mode mode)30void MouseCursorMonitorPipeWire::Init(Callback* callback, Mode mode) { 31 RTC_DCHECK_RUN_ON(&sequence_checker_); 32 RTC_DCHECK(!callback_); 33 RTC_DCHECK(callback); 34 35 callback_ = callback; 36 mode_ = mode; 37 } 38 Capture()39void MouseCursorMonitorPipeWire::Capture() { 40 RTC_DCHECK_RUN_ON(&sequence_checker_); 41 RTC_DCHECK(callback_); 42 43 std::unique_ptr<MouseCursor> mouse_cursor = 44 options_.screencast_stream()->CaptureCursor(); 45 46 if (mouse_cursor && mouse_cursor->image()->data()) { 47 callback_->OnMouseCursor(mouse_cursor.release()); 48 } 49 50 if (mode_ == SHAPE_AND_POSITION) { 51 absl::optional<DesktopVector> mouse_cursor_position = 52 options_.screencast_stream()->CaptureCursorPosition(); 53 if (mouse_cursor_position) { 54 callback_->OnMouseCursorPosition(mouse_cursor_position.value()); 55 } 56 } 57 } 58 59 } // namespace webrtc 60