KWinScript.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <chrono>
  3. #include <dbus/dbus.h>
  4. #include <filesystem>
  5. #include <string>
  6. #include <vector>
  7. namespace WallpaperEngine::Desktop {
  8. /** A KWin script loaded over D-Bus for the lifetime of this object. Its source file stays locked while this process
  9. * lives, so whatever the process leaves behind when it is killed can be told from the scripts of live engines */
  10. class KWinScript {
  11. public:
  12. KWinScript (DBusConnection* connection, std::string pluginName, const std::string& source);
  13. ~KWinScript ();
  14. KWinScript (const KWinScript&) = delete;
  15. KWinScript& operator= (const KWinScript&) = delete;
  16. [[nodiscard]] bool isLoaded () const { return this->m_running; }
  17. /** Plugin names of the scripts in directory whose engine is gone: the file is not locked by anyone, not new (a
  18. * starting engine creates and locks it a moment later) and its pid, where the name has one, is not running */
  19. [[nodiscard]] static std::vector<std::string>
  20. findStale (const std::filesystem::path& directory, std::chrono::seconds minimumAge = std::chrono::seconds (2));
  21. /** Unloads those from KWin and removes their files. A killed engine's script goes on calling its dead D-Bus
  22. * service at every cursor move otherwise */
  23. static void unloadStale (DBusConnection* connection);
  24. private:
  25. DBusConnection* m_connection;
  26. std::string m_pluginName;
  27. std::string m_path;
  28. int m_lock = -1;
  29. std::vector<std::string> m_loadedNames;
  30. bool m_running = false;
  31. };
  32. }