diff options
Diffstat (limited to 'src/helpers/MainLoopExecutor.hpp')
| -rw-r--r-- | src/helpers/MainLoopExecutor.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/helpers/MainLoopExecutor.hpp b/src/helpers/MainLoopExecutor.hpp new file mode 100644 index 00000000..b33148f0 --- /dev/null +++ b/src/helpers/MainLoopExecutor.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <functional> +#include <hyprutils/os/FileDescriptor.hpp> +#include <wayland-server-core.h> + +class CMainLoopExecutor { + public: + /* + MainLoopExecutor + + Executes a function on the main thread once the writeFd() has some data written to it, + then destroys itself. + + Needs to be kept owned, otherwise will die and kill the fds. + */ + + CMainLoopExecutor(std::function<void()>&& callback); + ~CMainLoopExecutor(); + + // Call from your worker thread: signals to the main thread. Destroy afterwards. + void signal(); + + // do not call + void onFired(); + + private: + Hyprutils::OS::CFileDescriptor m_readFd, m_writeFd; + wl_event_source* m_event = nullptr; + std::function<void()> m_fn; +}; |
