Hyprland IPC improvements

Fixes IPC being blocked at shutdown
This commit is contained in:
zjeffer
2025-02-19 00:58:08 +01:00
parent c32d5e3883
commit 5b8839ab5c
12 changed files with 188 additions and 154 deletions

View File

@ -5,6 +5,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <utility>
#include "util/json.hpp"
@ -19,7 +20,9 @@ class EventHandler {
class IPC {
public:
IPC() { startIPC(); }
IPC();
~IPC();
static IPC& inst();
void registerForIPC(const std::string& ev, EventHandler* ev_handler);
void unregisterForIPC(EventHandler* handler);
@ -32,14 +35,16 @@ class IPC {
static std::filesystem::path socketFolder_;
private:
void startIPC();
void socketListener();
void parseIPC(const std::string&);
std::jthread ipcThread_;
std::mutex callbackMutex_;
util::JsonParser parser_;
std::list<std::pair<std::string, EventHandler*>> callbacks_;
int socketfd_; // the hyprland socket file descriptor
bool running_ = true;
};
inline std::unique_ptr<IPC> gIPC;
inline bool modulesReady = false;
}; // namespace waybar::modules::hyprland

View File

@ -37,6 +37,8 @@ class Language : public waybar::ALabel, public EventHandler {
util::JsonParser parser_;
Layout layout_;
IPC& m_ipc;
};
} // namespace waybar::modules::hyprland

View File

@ -28,6 +28,8 @@ class Submap : public waybar::ALabel, public EventHandler {
std::string submap_;
bool always_on_ = false;
std::string default_submap_ = "Default";
IPC& m_ipc;
};
} // namespace waybar::modules::hyprland

View File

@ -60,6 +60,8 @@ class Window : public waybar::AAppIconLabel, public EventHandler {
bool swallowing_;
bool fullscreen_;
bool focused_;
IPC& m_ipc;
};
} // namespace waybar::modules::hyprland

View File

@ -83,6 +83,7 @@ class Workspace {
Gtk::Button m_button;
Gtk::Box m_content;
Gtk::Label m_label;
IPC& m_ipc;
};
} // namespace waybar::modules::hyprland

View File

@ -150,6 +150,7 @@ class Workspaces : public AModule, public EventHandler {
std::mutex m_mutex;
const Bar& m_bar;
Gtk::Box m_box;
IPC& m_ipc;
};
} // namespace waybar::modules::hyprland