i3ipc::I3Connection renamed to i3ipc::connection
This commit is contained in:
@@ -28,7 +28,7 @@ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) {
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
i3ipc::I3Connection conn;
|
i3ipc::connection conn;
|
||||||
for (auto& w : conn.get_workspaces()) {
|
for (auto& w : conn.get_workspaces()) {
|
||||||
std::cout << '#' << std::hex << w.num << std::dec
|
std::cout << '#' << std::hex << w.num << std::dec
|
||||||
<< "\n\tName: " << w.name
|
<< "\n\tName: " << w.name
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ enum EventType {
|
|||||||
ET_OUTPUT = (1 << 1), ///< Output event
|
ET_OUTPUT = (1 << 1), ///< Output event
|
||||||
ET_MODE = (1 << 2), ///< Output mode event
|
ET_MODE = (1 << 2), ///< Output mode event
|
||||||
ET_WINDOW = (1 << 3), ///< Window event
|
ET_WINDOW = (1 << 3), ///< Window event
|
||||||
ET_BARCONFIG_UPDATE = (1 << 4), ///< Bar config update event @attention Yet is not implemented as signal in I3Connection
|
ET_BARCONFIG_UPDATE = (1 << 4), ///< Bar config update event @attention Yet is not implemented as signal in connection
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,18 +153,23 @@ struct container_t {
|
|||||||
std::list< std::shared_ptr<container_t> > nodes;
|
std::list< std::shared_ptr<container_t> > nodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
typedef class connection I3Connection;
|
||||||
|
|
||||||
struct buf_t;
|
struct buf_t;
|
||||||
/**
|
/**
|
||||||
* Connection to the i3
|
* Connection to the i3
|
||||||
*/
|
*/
|
||||||
class I3Connection {
|
class connection {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Connect to the i3
|
* Connect to the i3
|
||||||
* @param socket_path path to a i3 IPC socket
|
* @param socket_path path to a i3 IPC socket
|
||||||
*/
|
*/
|
||||||
I3Connection(const std::string& socket_path = get_socketpath());
|
connection(const std::string& socket_path = get_socketpath());
|
||||||
~I3Connection();
|
~connection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a command to i3
|
* Send a command to i3
|
||||||
@@ -205,7 +210,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* @code{.cpp}
|
* @code{.cpp}
|
||||||
* I3Connection conn;
|
* connection conn;
|
||||||
* conn.subscribe(i3ipc::ipc::ET_WORKSPACE | i3ipc::ipc::ET_WINDOW);
|
* conn.subscribe(i3ipc::ipc::ET_WORKSPACE | i3ipc::ipc::ET_WINDOW);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
|
|||||||
20
src/ipc.cpp
20
src/ipc.cpp
@@ -171,7 +171,7 @@ std::string get_socketpath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_connect(socket_path)), m_event_socket(-1), m_subscriptions(0), m_socket_path(socket_path) {
|
connection::connection(const std::string& socket_path) : m_main_socket(i3_connect(socket_path)), m_event_socket(-1), m_subscriptions(0), m_socket_path(socket_path) {
|
||||||
#define i3IPC_TYPE_STR "i3's event"
|
#define i3IPC_TYPE_STR "i3's event"
|
||||||
signal_event.connect([this](EventType event_type, const std::shared_ptr<const buf_t>& buf) {
|
signal_event.connect([this](EventType event_type, const std::shared_ptr<const buf_t>& buf) {
|
||||||
switch (event_type) {
|
switch (event_type) {
|
||||||
@@ -240,18 +240,18 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c
|
|||||||
});
|
});
|
||||||
#undef i3IPC_TYPE_STR
|
#undef i3IPC_TYPE_STR
|
||||||
}
|
}
|
||||||
I3Connection::~I3Connection() {
|
connection::~connection() {
|
||||||
i3_disconnect(m_main_socket);
|
i3_disconnect(m_main_socket);
|
||||||
if (m_event_socket > 0)
|
if (m_event_socket > 0)
|
||||||
i3_disconnect(m_event_socket);
|
i3_disconnect(m_event_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void I3Connection::prepare_to_event_handling() {
|
void connection::prepare_to_event_handling() {
|
||||||
m_event_socket = i3_connect(m_socket_path);
|
m_event_socket = i3_connect(m_socket_path);
|
||||||
this->subscribe(m_subscriptions);
|
this->subscribe(m_subscriptions);
|
||||||
}
|
}
|
||||||
void I3Connection::handle_event() {
|
void connection::handle_event() {
|
||||||
if (m_event_socket <= 0) {
|
if (m_event_socket <= 0) {
|
||||||
throw std::runtime_error("event_socket_fd <= 0");
|
throw std::runtime_error("event_socket_fd <= 0");
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ void I3Connection::handle_event() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool I3Connection::subscribe(const int32_t events) {
|
bool connection::subscribe(const int32_t events) {
|
||||||
#define i3IPC_TYPE_STR "SUBSCRIBE"
|
#define i3IPC_TYPE_STR "SUBSCRIBE"
|
||||||
if (m_event_socket <= 0) {
|
if (m_event_socket <= 0) {
|
||||||
m_subscriptions |= events;
|
m_subscriptions |= events;
|
||||||
@@ -304,7 +304,7 @@ bool I3Connection::subscribe(const int32_t events) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
version_t I3Connection::get_version() const {
|
version_t connection::get_version() const {
|
||||||
#define i3IPC_TYPE_STR "GET_VERSION"
|
#define i3IPC_TYPE_STR "GET_VERSION"
|
||||||
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_VERSION);
|
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_VERSION);
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
@@ -322,7 +322,7 @@ version_t I3Connection::get_version() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<container_t> I3Connection::get_tree() const {
|
std::shared_ptr<container_t> connection::get_tree() const {
|
||||||
#define i3IPC_TYPE_STR "GET_TREE"
|
#define i3IPC_TYPE_STR "GET_TREE"
|
||||||
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_TREE);
|
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_TREE);
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
@@ -332,7 +332,7 @@ std::shared_ptr<container_t> I3Connection::get_tree() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<output_t> I3Connection::get_outputs() const {
|
std::vector<output_t> connection::get_outputs() const {
|
||||||
#define i3IPC_TYPE_STR "GET_OUTPUTS"
|
#define i3IPC_TYPE_STR "GET_OUTPUTS"
|
||||||
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_OUTPUTS);
|
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_OUTPUTS);
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
@@ -350,7 +350,7 @@ std::vector<output_t> I3Connection::get_outputs() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<workspace_t> I3Connection::get_workspaces() const {
|
std::vector<workspace_t> connection::get_workspaces() const {
|
||||||
#define i3IPC_TYPE_STR "GET_WORKSPACES"
|
#define i3IPC_TYPE_STR "GET_WORKSPACES"
|
||||||
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_WORKSPACES);
|
auto buf = i3_msg(m_main_socket, ClientMessageType::GET_WORKSPACES);
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
@@ -368,7 +368,7 @@ std::vector<workspace_t> I3Connection::get_workspaces() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool I3Connection::send_command(const std::string& command) const {
|
bool connection::send_command(const std::string& command) const {
|
||||||
#define i3IPC_TYPE_STR "COMMAND"
|
#define i3IPC_TYPE_STR "COMMAND"
|
||||||
auto buf = i3_msg(m_main_socket, ClientMessageType::COMMAND, command);
|
auto buf = i3_msg(m_main_socket, ClientMessageType::COMMAND, command);
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
|||||||
Reference in New Issue
Block a user