remote_desktop_portal_injector.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_HOST_LINUX_REMOTE_DESKTOP_PORTAL_INJECTOR_H_
  5. #define REMOTING_HOST_LINUX_REMOTE_DESKTOP_PORTAL_INJECTOR_H_
  6. #include <gio/gio.h>
  7. #include <memory>
  8. #include <string>
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/scoped_refptr.h"
  11. #include "base/sequence_checker.h"
  12. #include "third_party/webrtc/modules/desktop_capture/linux/wayland/screen_capture_portal_interface.h"
  13. #include "third_party/webrtc/modules/desktop_capture/linux/wayland/screencast_portal.h"
  14. #include "third_party/webrtc/modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h"
  15. #include "third_party/webrtc/modules/desktop_capture/linux/wayland/xdg_session_details.h"
  16. namespace remoting {
  17. namespace xdg_portal {
  18. // This class is used by the `ChromotingInputThread` to inject input into the
  19. // wayland remote host using XDG desktop portal APIs.
  20. class RemoteDesktopPortalInjector {
  21. public:
  22. enum ScrollType {
  23. VERTICAL_SCROLL = 0,
  24. HORIZONTAL_SCROLL = 1,
  25. };
  26. // Default constructor is used by input injector module.
  27. RemoteDesktopPortalInjector();
  28. RemoteDesktopPortalInjector(const RemoteDesktopPortalInjector&) = delete;
  29. RemoteDesktopPortalInjector& operator=(const RemoteDesktopPortalInjector&) =
  30. delete;
  31. ~RemoteDesktopPortalInjector();
  32. // This method populates the session details for this object. Session details
  33. // are borrowed from the wayland desktop capturer.
  34. void SetSessionDetails(webrtc::xdg_portal::SessionDetails session_details);
  35. // Methods related to input injection.
  36. void InjectMouseButton(int code, bool pressed);
  37. void InjectMouseScroll(int axis, int steps);
  38. void MovePointerTo(int x, int y);
  39. void MovePointerBy(int delta_x, int delta_y);
  40. void InjectKeyPress(int code, bool pressed, bool is_code = true);
  41. private:
  42. SEQUENCE_CHECKER(sequence_checker_);
  43. raw_ptr<GDBusConnection> connection_ GUARDED_BY_CONTEXT(sequence_checker_) =
  44. nullptr;
  45. raw_ptr<GDBusProxy> proxy_ GUARDED_BY_CONTEXT(sequence_checker_) = nullptr;
  46. raw_ptr<GCancellable> cancellable_ GUARDED_BY_CONTEXT(sequence_checker_) =
  47. nullptr;
  48. uint32_t pipewire_stream_node_id_ GUARDED_BY_CONTEXT(sequence_checker_);
  49. std::string session_handle_ GUARDED_BY_CONTEXT(sequence_checker_);
  50. };
  51. } // namespace xdg_portal
  52. } // namespace remoting
  53. #endif // REMOTING_HOST_LINUX_REMOTE_DESKTOP_PORTAL_INJECTOR_H_