diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index 98ea2cd..1268743 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -287,6 +287,8 @@ public: */ bool send_command(const std::string& command) const; + bool send_command(const std::string& command, std::optional& error_info) const; + /** * Request a list of workspaces * @return List of workspaces diff --git a/src/ipc.cpp b/src/ipc.cpp index 941aa9b..02af414 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -632,7 +632,7 @@ std::shared_ptr connection::get_bar_config(const std::string& na } -bool connection::send_command(const std::string& command) const { +bool connection::send_command(const std::string& command, std::optional& error_info) const { #define i3IPC_TYPE_STR "COMMAND" auto buf = i3_msg(m_main_socket, ClientMessageType::COMMAND, command); Json::Value root; @@ -646,13 +646,25 @@ bool connection::send_command(const std::string& command) const { } else { Json::Value error = payload["error"]; if (!error.isNull()) { - I3IPC_ERR("Failed to execute command: " << error.asString()) + error_info = error.asString(); + } else { + error_info.reset(); } return false; } #undef i3IPC_TYPE_STR } + +bool connection::send_command(const std::string& command) const { + std::optional error_info{}; + bool result = send_command(command, error_info); + if (!error_info.has_value()) { + I3IPC_ERR("Failed to execute command: " << error_info.value()); + } + return result; +} + int32_t connection::get_main_socket_fd() { return m_main_socket; } int32_t connection::get_event_socket_fd() { return m_event_socket; }