WaylandMouseInput.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #ifdef ENABLE_WAYLAND
  3. #include "WallpaperEngine/Input/MouseInput.h"
  4. #include <chrono>
  5. #include <glm/vec2.hpp>
  6. #include <optional>
  7. #ifdef ENABLE_KDE_EXPERIMENTAL_FEATURES
  8. #include "KDECursorInput.h"
  9. #endif /* ENABLE_KDE_EXPERIMENTAL_FEATURES */
  10. namespace WallpaperEngine::Render::Drivers {
  11. namespace Output {
  12. class WaylandOutputViewport;
  13. }
  14. class WaylandOpenGLDriver;
  15. };
  16. namespace WallpaperEngine::Input::Drivers {
  17. /**
  18. * Handles mouse input for the background
  19. */
  20. class WaylandMouseInput final : public MouseInput {
  21. public:
  22. explicit WaylandMouseInput (const WallpaperEngine::Render::Drivers::WaylandOpenGLDriver& driver);
  23. /**
  24. * Takes current mouse position and updates it
  25. */
  26. void update () override;
  27. /**
  28. * The virtual pointer's position
  29. */
  30. [[nodiscard]] glm::dvec2 position () const override;
  31. /**
  32. * @return The status of the mouse's left click
  33. */
  34. [[nodiscard]] MouseClickStatus leftClick () const override;
  35. /**
  36. * @return The status of the mouse's right click
  37. */
  38. [[nodiscard]] MouseClickStatus rightClick () const override;
  39. private:
  40. [[nodiscard]] const Render::Drivers::Output::WaylandOutputViewport* getActiveOutputViewport () const;
  41. [[nodiscard]] std::optional<glm::dvec2> queryHyprlandCursorPosition () const;
  42. #ifdef ENABLE_X11
  43. /**
  44. * Fallback for compositors without a compositor-specific IPC (KDE, GNOME, ...): asks XWayland
  45. * for the pointer position on the root window, which tracks the real Wayland cursor
  46. */
  47. [[nodiscard]] std::optional<glm::dvec2> queryX11CursorPosition () const;
  48. #endif /* ENABLE_X11 */
  49. /**
  50. * Converts a global (compositor-space) cursor position into local viewport coordinates and
  51. * stores it into m_pos if it falls within one of the tracked outputs
  52. */
  53. bool matchViewport (const glm::dvec2& globalCursor, const char* source, bool shouldLog);
  54. /**
  55. * Wayland: Driver
  56. */
  57. const WallpaperEngine::Render::Drivers::WaylandOpenGLDriver& m_waylandDriver;
  58. glm::dvec2 m_pos = {};
  59. std::chrono::steady_clock::time_point m_lastGlobalCursorQuery = {};
  60. #ifdef ENABLE_KDE_EXPERIMENTAL_FEATURES
  61. KDECursorInput m_kdeCursor;
  62. #endif /* ENABLE_KDE_EXPERIMENTAL_FEATURES */
  63. };
  64. } // namespace WallpaperEngine::Input::Drivers
  65. #endif /* ENABLE_WAYLAND */