From 3c128679ee8c86bbbeb5ae38621f6de622525cf1 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 6 Apr 2025 17:31:58 +0200 Subject: helpers: Add an async dialog box impl (#9919) Adds an async dialog box, way safer than our previous local solution for ANR --- src/helpers/AsyncDialogBox.hpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/helpers/AsyncDialogBox.hpp (limited to 'src/helpers/AsyncDialogBox.hpp') 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 +#include + +#include +#include + +struct wl_event_source; + +class CAsyncDialogBox { + public: + static SP create(const std::string& title, const std::string& description, std::vector buttons); + + CAsyncDialogBox(const CAsyncDialogBox&) = delete; + CAsyncDialogBox(CAsyncDialogBox&&) = delete; + CAsyncDialogBox& operator=(const CAsyncDialogBox&) = delete; + CAsyncDialogBox& operator=(CAsyncDialogBox&&) = delete; + + void open(std::function 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 buttons); + + pid_t m_dialogPid = 0; + wl_event_source* m_readEventSource = nullptr; + std::function m_onResolution; + Hyprutils::OS::CFileDescriptor m_pipeReadFd; + std::string m_stdout = ""; + + const std::string m_title; + const std::string m_description; + const std::vector m_buttons; + + // WARNING: cyclic reference. This will be removed once the event source is removed to avoid dangling pointers + SP m_selfReference; + WP m_selfWeakReference; +}; \ No newline at end of file -- cgit v1.2.3