Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/modules/niri/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EventHandler {

class IPC {
public:
IPC() { startIPC(); }
IPC();

void registerForIPC(const std::string& ev, EventHandler* ev_handler);
void unregisterForIPC(EventHandler* handler);
Expand Down
18 changes: 6 additions & 12 deletions src/modules/niri/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

namespace waybar::modules::niri {

IPC::IPC() { startIPC(); }

int IPC::connectToSocket() {
const char* socket_path = getenv("NIRI_SOCKET");

if (socket_path == nullptr) {
spdlog::warn("Niri is not running, niri IPC will not be available.");
return -1;
throw std::runtime_error("Niri IPC: NIRI_SOCKET was not set! (Is Niri running?)");
}

struct sockaddr_un addr;
Expand Down Expand Up @@ -54,15 +55,9 @@ int IPC::connectToSocket() {
void IPC::startIPC() {
// will start IPC and relay events to parseIPC

std::thread([&]() {
int socketfd;
try {
socketfd = connectToSocket();
} catch (std::exception& e) {
spdlog::error("Niri IPC: failed to start, reason: {}", e.what());
return;
}
if (socketfd == -1) return;
int socketfd = connectToSocket();

std::thread([this, socketfd]() {

spdlog::info("Niri IPC starting");

Expand Down Expand Up @@ -242,7 +237,6 @@ void IPC::unregisterForIPC(EventHandler* ev_handler) {

Json::Value IPC::send(const Json::Value& request) {
int socketfd = connectToSocket();
if (socketfd == -1) throw std::runtime_error("Niri is not running");

auto unix_istream = Gio::UnixInputStream::create(socketfd, true);
auto unix_ostream = Gio::UnixOutputStream::create(socketfd, false);
Expand Down