WaylandOutputViewport.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #pragma once
  2. #ifdef ENABLE_WAYLAND
  3. #include <EGL/egl.h>
  4. #include <EGL/eglext.h>
  5. #include <GL/glew.h>
  6. #include <wayland-client.h>
  7. #include <wayland-cursor.h>
  8. #include <wayland-egl.h>
  9. #include <chrono>
  10. #include "../WaylandOpenGLDriver.h"
  11. #include "OutputViewport.h"
  12. #include <WallpaperEngine/Input/MouseInput.h>
  13. #include <glm/vec2.hpp>
  14. struct zwlr_layer_shell_v1;
  15. struct zwlr_layer_surface_v1;
  16. struct zxdg_output_v1;
  17. struct zxdg_output_manager_v1;
  18. struct wp_color_management_output_v1;
  19. struct wp_color_management_surface_v1;
  20. struct wp_fractional_scale_v1;
  21. struct wp_viewport;
  22. struct ext_image_capture_source_v1;
  23. struct ext_image_copy_capture_session_v1;
  24. struct ext_image_copy_capture_cursor_session_v1;
  25. struct xdg_surface;
  26. struct xdg_toplevel;
  27. #ifdef ENABLE_KDE_FEATURES
  28. struct org_kde_plasma_surface;
  29. #endif
  30. namespace WallpaperEngine::Render::Drivers {
  31. class WaylandOpenGLDriver;
  32. namespace Output {
  33. class OutputViewport;
  34. class WaylandOutputViewport final : public OutputViewport {
  35. public:
  36. WaylandOutputViewport (WaylandOpenGLDriver* driver, uint32_t waylandName, struct wl_registry* registry);
  37. WaylandOpenGLDriver* getDriver () const;
  38. wl_output* output = nullptr;
  39. glm::ivec2 size = {};
  40. uint32_t waylandName;
  41. int scale = 1;
  42. /** wp_fractional_scale_v1 preferred scale in 120ths, 0 until the compositor sent one */
  43. uint32_t preferredScale120 = 0;
  44. wp_viewport* surfaceViewport = nullptr;
  45. wp_fractional_scale_v1* fractionalScale = nullptr;
  46. bool initialized = false;
  47. bool rendering = false;
  48. /** layer surface closed or output removed, set during event dispatch and freed by the driver's main loop */
  49. bool closed = false;
  50. bool outputRemoved = false;
  51. /** reopen backoff after a closed shell surface, doubled per close */
  52. std::chrono::seconds reopenDelay { 0 };
  53. std::chrono::steady_clock::time_point reopenAt = {};
  54. bool reopenAtMaxLogged = false;
  55. wl_egl_window* eglWindow = nullptr;
  56. EGLSurface eglSurface = nullptr;
  57. wl_surface* surface = nullptr;
  58. zwlr_layer_surface_v1* layerSurface = nullptr;
  59. /** GNOME: toplevel the Shell extension turns into a desktop window */
  60. xdg_surface* xdgSurface = nullptr;
  61. xdg_toplevel* xdgToplevel = nullptr;
  62. /** 0 = ours to pick */
  63. glm::ivec2 pendingToplevelSize = {};
  64. bool toplevelConfigured = false;
  65. wl_callback* frameCallback = nullptr;
  66. #ifdef ENABLE_KDE_FEATURES
  67. org_kde_plasma_surface* plasmaSurface = nullptr;
  68. #endif
  69. glm::dvec2 mousePos = { 0, 0 };
  70. bool pointerEntered = false;
  71. WallpaperEngine::Input::MouseClickStatus leftClick = WallpaperEngine::Input::MouseClickStatus::Released;
  72. WallpaperEngine::Input::MouseClickStatus rightClick = WallpaperEngine::Input::MouseClickStatus::Released;
  73. bool inputPassthrough = false;
  74. wl_cursor* pointer = nullptr;
  75. wl_surface* cursorSurface = nullptr;
  76. wl_cursor_theme* cursorTheme = nullptr;
  77. bool callbackInitialized = false;
  78. std::chrono::steady_clock::time_point lastSwap = {};
  79. bool hasXdgLogicalPosition = false;
  80. zxdg_output_v1* xdgOutput = nullptr;
  81. ext_image_capture_source_v1* captureSource = nullptr;
  82. ext_image_copy_capture_session_v1* captureSession = nullptr;
  83. ext_image_copy_capture_cursor_session_v1* cursorSession = nullptr;
  84. glm::ivec2 captureSize = {};
  85. glm::ivec2 captureCursor = {};
  86. bool captureCursorInside = false;
  87. void setupCursorCapture ();
  88. [[nodiscard]] bool hasShellSurface () const { return this->layerSurface || this->xdgToplevel; }
  89. void setupLS ();
  90. void setupToplevel ();
  91. void setupXdgOutput (zxdg_output_manager_v1* manager);
  92. void setupColorManagement ();
  93. void queryOutputDescription ();
  94. void applyImageDescription ();
  95. [[nodiscard]] bool isOutputHDR () const { return this->outputHDR; }
  96. [[nodiscard]] bool isHDR () const override;
  97. void setWantsPointerButtons (bool wants) override;
  98. [[nodiscard]] glm::vec2 getHDRLuminance () const override { return this->outputLuminance; }
  99. wp_color_management_output_v1* colorOutput = nullptr;
  100. wp_color_management_surface_v1* colorSurface = nullptr;
  101. bool outputHDR = false;
  102. /** reference white and peak of the output's image description in nits */
  103. glm::vec2 outputLuminance = glm::vec2 (0.0f);
  104. struct {
  105. uint32_t tf = 0;
  106. uint32_t maxLuminance = 0;
  107. uint32_t referenceLuminance = 0;
  108. uint32_t targetMaxLuminance = 0;
  109. } pendingDescription;
  110. [[nodiscard]] double renderScale () const;
  111. [[nodiscard]] glm::ivec2 bufferSize () const;
  112. void updateBufferSize ();
  113. void makeCurrent () override;
  114. void renderFrame ();
  115. void swapOutput () override;
  116. void resize ();
  117. private:
  118. void prepareSurface ();
  119. void setInputRegion (bool everything);
  120. void setupFractionalScale ();
  121. void createEGLSurface ();
  122. WaylandOpenGLDriver* m_driver = nullptr;
  123. };
  124. }
  125. }
  126. #endif