GnomeShell.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <dbus/dbus.h>
  3. #include <glm/vec2.hpp>
  4. #include <string>
  5. #include <vector>
  6. #include "WindowState.h"
  7. namespace WallpaperEngine::Desktop {
  8. bool isGnomeSession ();
  9. /**
  10. * Client of our GNOME Shell extension: it makes our toplevels desktop windows and reports the pointer and window
  11. * states Mutter hides from Wayland clients. Read only from the render thread via dispatch ().
  12. */
  13. class GnomeShell {
  14. public:
  15. static constexpr const char* BUS_NAME = "org.linuxwallpaperengine.Shell";
  16. static constexpr const char* OBJECT_PATH = "/org/linuxwallpaperengine/Shell";
  17. static constexpr const char* INTERFACE = "org.linuxwallpaperengine.Shell";
  18. static constexpr const char* TITLE_PREFIX = "linux-wallpaperengine wallpaper ";
  19. static constexpr const char* APP_ID = "linux-wallpaperengine";
  20. static constexpr uint32_t API_VERSION = 1;
  21. using Window = WindowState;
  22. struct Pointer {
  23. std::string output;
  24. /** fraction of the window, from its top left */
  25. glm::dvec2 position;
  26. };
  27. GnomeShell ();
  28. ~GnomeShell ();
  29. GnomeShell (const GnomeShell&) = delete;
  30. GnomeShell& operator= (const GnomeShell&) = delete;
  31. [[nodiscard]] bool isAvailable () const { return this->m_available; }
  32. [[nodiscard]] const std::string& reason () const { return this->m_reason; }
  33. [[nodiscard]] bool vanished () const { return this->m_vanished; }
  34. /** GNOME 45-48: needs a Shell-spawned connection, see openWaylandSocket */
  35. [[nodiscard]] bool needsHelper () const { return this->m_needsHelper; }
  36. // the extension spawns the helper via Meta.WaylandClient, returns its connection or -1; Mutter drops the client
  37. // when the helper exits
  38. [[nodiscard]] int openWaylandSocket ();
  39. void dispatch ();
  40. [[nodiscard]] const std::vector<Pointer>& pointer () const { return this->m_pointer; }
  41. [[nodiscard]] const std::vector<Window>& windows () const { return this->m_windows; }
  42. [[nodiscard]] bool desktopLeftDown () const { return this->m_desktopLeftDown; }
  43. private:
  44. bool connect ();
  45. bool queryState ();
  46. static DBusHandlerResult filter (DBusConnection* connection, DBusMessage* message, void* data);
  47. void handleSignal (DBusMessage* message);
  48. DBusConnection* m_connection = nullptr;
  49. std::string m_owner;
  50. std::string m_reason;
  51. bool m_available = false;
  52. bool m_vanished = false;
  53. bool m_needsHelper = false;
  54. bool m_filterAdded = false;
  55. bool m_desktopLeftDown = false;
  56. int m_helperConnection = -1;
  57. std::vector<Pointer> m_pointer;
  58. std::vector<Window> m_windows;
  59. };
  60. }