waybar/include/modules/sway/ipc/client.hpp
2019-04-19 11:09:06 +02:00

45 lines
1.0 KiB
C++

#pragma once
#include <sigc++/sigc++.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
#include "ipc.hpp"
namespace waybar::modules::sway {
class Ipc {
public:
Ipc();
~Ipc();
struct ipc_response {
uint32_t size;
uint32_t type;
std::string payload;
};
sigc::signal<void, const struct ipc_response> signal_event;
sigc::signal<void, const struct ipc_response> signal_cmd;
void sendCmd(uint32_t type, const std::string &payload = "") const;
void subscribe(const std::string &payload) const;
void handleEvent() const;
protected:
static inline const std::string ipc_magic_ = "i3-ipc";
static inline const size_t ipc_header_size_ = ipc_magic_.size() + 8;
const std::string getSocketPath() const;
int open(const std::string &) const;
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "") const;
struct ipc_response recv(int fd) const;
int fd_;
int fd_event_;
};
} // namespace waybar::modules::sway