diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2025-04-06 17:31:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-06 17:31:58 +0200 |
| commit | 3c128679ee8c86bbbeb5ae38621f6de622525cf1 (patch) | |
| tree | 08a920819d766099d7a3d7fde9a8f968992c3a2c /src/helpers/AsyncDialogBox.hpp | |
| parent | e96b8ce4cc5e5856b6da653f1d92af856b5e72c9 (diff) | |
helpers: Add an async dialog box impl (#9919)
Adds an async dialog box, way safer than our previous local solution for ANR
Diffstat (limited to 'src/helpers/AsyncDialogBox.hpp')
| -rw-r--r-- | src/helpers/AsyncDialogBox.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/helpers/AsyncDialogBox.hpp b/src/helpers/AsyncDialogBox.hpp new file mode 100644 index 00000000..d3cc242c --- /dev/null +++ b/src/helpers/AsyncDialogBox.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "../macros.hpp" +#include "./memory/Memory.hpp" + +#include <vector> +#include <functional> + +#include <hyprutils/os/Process.hpp> +#include <hyprutils/os/FileDescriptor.hpp> + +struct wl_event_source; + +class CAsyncDialogBox { + public: + static SP<CAsyncDialogBox> create(const std::string& title, const std::string& description, std::vector<std::string> buttons); + + CAsyncDialogBox(const CAsyncDialogBox&) = delete; + CAsyncDialogBox(CAsyncDialogBox&&) = delete; + CAsyncDialogBox& operator=(const CAsyncDialogBox&) = delete; + CAsyncDialogBox& operator=(CAsyncDialogBox&&) = delete; + + void open(std::function<void(std::string)> onResolution); + void kill(); + bool isRunning() const; + + void onWrite(int fd, uint32_t mask); + + private: + CAsyncDialogBox(const std::string& title, const std::string& description, std::vector<std::string> buttons); + + pid_t m_dialogPid = 0; + wl_event_source* m_readEventSource = nullptr; + std::function<void(std::string)> m_onResolution; + Hyprutils::OS::CFileDescriptor m_pipeReadFd; + std::string m_stdout = ""; + + const std::string m_title; + const std::string m_description; + const std::vector<std::string> m_buttons; + + // WARNING: cyclic reference. This will be removed once the event source is removed to avoid dangling pointers + SP<CAsyncDialogBox> m_selfReference; + WP<CAsyncDialogBox> m_selfWeakReference; +};
\ No newline at end of file |
