Compare commits

..

3 Commits

Author SHA1 Message Date
German Lashevich
ae5a2c345d Fix build issues
- `std::copy_n` requires to #include <algorithm>
- `std::optional` requires C++17 or newer
2022-06-27 21:17:21 +02:00
Francesco Galizzi
eaa8a3ff3f Solve issue #35 2022-06-27 21:17:21 +02:00
a66f24888f Handle "move" workspace event 2021-12-04 13:40:29 +01:00
6 changed files with 22 additions and 50 deletions

8
.gitignore vendored
View File

@@ -1,8 +1,4 @@
build/
doc/
build
doc
*.sublime-workspace
*.log
.ccls*
*.o
compile_commands.*

View File

@@ -1,23 +1,15 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(i3ipc++)
string(TIMESTAMP I3IPCppBUILD_DATETIME "%Y-%m-%d %H:%M:%S")
option(I3IPCpp_WITH_TESTS "Build unit tests executables" OFF)
option(I3IPCpp_BUILD_EXAMPLES "Build example executables" OFF)
file(GLOB_RECURSE SRC src/*.cpp)
add_library(i3ipc++ ${SRC})
find_package(PkgConfig)
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
pkg_check_modules(SIGCPP sigc++-3.0)
if(SIGCPP_FOUND)
target_compile_definitions(i3ipc++
PUBLIC I3CPP_IPC_SIGCPP3=${SIGCPP_FOUND}
)
else()
pkg_check_modules(SIGCPP REQUIRED sigc++-2.0)
endif()
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
set(I3IPCpp_INCLUDE_DIRS
${SIGCPP_INCLUDE_DIRS}
@@ -41,6 +33,8 @@ set(I3IPCpp_LIBRARIES
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -DDEBUG")
# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
file(GLOB_RECURSE SRC src/*.cpp)
add_library(i3ipc++ ${SRC})
target_include_directories(i3ipc++
PUBLIC
@@ -66,6 +60,10 @@ target_compile_options(i3ipc++
PRIVATE -std=c++17 -Wall -Wextra -Wno-unused-parameter
)
target_compile_definitions(i3ipc++
PRIVATE I3IPC_BUILD_DATETIME="${I3IPCppBUILD_DATETIME}"
)
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
target_compile_options(i3ipc++
PUBLIC -g3

View File

@@ -10,7 +10,6 @@ An implementation of i3 IPC in C++11.
* C++11 compiler
* sigc++ 2.0
* jsoncpp
* i3 (for i3/ipc.h)
## Using
Yet the only way of using is to add this repo as a submodule

View File

@@ -287,8 +287,6 @@ public:
*/
bool send_command(const std::string& command) const;
bool send_command(const std::string& command, std::optional<std::string>& error_info) const;
/**
* Request a list of workspaces
* @return List of workspaces
@@ -372,21 +370,14 @@ public:
* Disconnect the event socket
*/
void disconnect_event_socket();
#ifdef I3CPP_IPC_SIGCPP3
sigc::signal<void(const workspace_event_t&)> signal_workspace_event; ///< Workspace event signal
sigc::signal<void()> signal_output_event; ///< Output event signal
sigc::signal<void(const mode_t&)> signal_mode_event; ///< Output mode event signal
sigc::signal<void(const window_event_t&)> signal_window_event; ///< Window event signal
sigc::signal<void(const bar_config_t&)> signal_barconfig_update_event; ///< Barconfig update event signal
sigc::signal<void(const binding_t&)> signal_binding_event; ///< Binding event signal
sigc::signal<void(EventType, const std::shared_ptr<const buf_t>&)> signal_event; ///< i3 event signal @note Default handler routes event to signal according to type
#else
sigc::signal<void, const workspace_event_t&> signal_workspace_event; ///< Workspace event signal
sigc::signal<void, const workspace_event_t&> signal_workspace_event; ///< Workspace event signal
sigc::signal<void> signal_output_event; ///< Output event signal
sigc::signal<void, const mode_t&> signal_mode_event; ///< Output mode event signal
sigc::signal<void, const window_event_t&> signal_window_event; ///< Window event signal
sigc::signal<void, const bar_config_t&> signal_barconfig_update_event; ///< Barconfig update event signal
#endif
sigc::signal<void, const binding_t&> signal_binding_event; ///< Binding event signal
sigc::signal<void, EventType, const std::shared_ptr<const buf_t>&> signal_event; ///< i3 event signal @note Default handler routes event to signal according to type
private:
const int32_t m_main_socket;
int32_t m_event_socket;

View File

@@ -325,7 +325,7 @@ std::string get_socketpath() {
pclose(in);
str = str_buf;
}
if (str.length() > 0 && str.back() == '\n') {
if (str.back() == '\n') {
str.pop_back();
}
return str;
@@ -632,7 +632,7 @@ std::shared_ptr<bar_config_t> connection::get_bar_config(const std::string& na
}
bool connection::send_command(const std::string& command, std::optional<std::string>& error_info) const {
bool connection::send_command(const std::string& command) const {
#define i3IPC_TYPE_STR "COMMAND"
auto buf = i3_msg(m_main_socket, ClientMessageType::COMMAND, command);
Json::Value root;
@@ -646,25 +646,13 @@ bool connection::send_command(const std::string& command, std::optional<std::st
} else {
Json::Value error = payload["error"];
if (!error.isNull()) {
error_info = error.asString();
} else {
error_info.reset();
I3IPC_ERR("Failed to execute command: " << error.asString())
}
return false;
}
#undef i3IPC_TYPE_STR
}
bool connection::send_command(const std::string& command) const {
std::optional<std::string> 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; }
@@ -675,7 +663,7 @@ const version_t& get_version() {
#define I3IPC_VERSION_MINOR 5
#define I3IPC_VERSION_PATCH 0
static version_t version = {
.human_readable = auss_t() << I3IPC_VERSION_MAJOR << '.' << I3IPC_VERSION_MINOR << '.' << I3IPC_VERSION_PATCH,
.human_readable = auss_t() << I3IPC_VERSION_MAJOR << '.' << I3IPC_VERSION_MINOR << '.' << I3IPC_VERSION_PATCH << " (built on " << I3IPC_BUILD_DATETIME << ")",
.loaded_config_file_name = std::string(),
.major = I3IPC_VERSION_MAJOR,
.minor = I3IPC_VERSION_MINOR,

View File

@@ -14,7 +14,7 @@ public:
auto buff = i3_pack(ClientMessageType::COMMAND, "exit");
auss_t auss;
auss << std::hex;
for (uint32_t i = 0; i < buff->data.size(); i++) {
for (uint32_t i = 0; i < buff->size; i++) {
if (buff->data[i] < 0x10) {
auss << '0';
}