From 8882c4f43617d350ba2ae51bf72a56407bacc41b Mon Sep 17 00:00:00 2001 From: mox Date: Fri, 22 Apr 2016 10:39:01 +0200 Subject: [PATCH 1/3] Added alterntive API that exposes the JSON event objects in the signals. --- include/i3ipc++/ipc.hpp | 15 +++++++++++++-- src/ipc.cpp | 12 ++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index 38ed4a2..9ccfe80 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -5,6 +5,10 @@ #include #include +#ifdef USE_FULL_SIGNALS +#include +#endif + #include extern "C" { @@ -78,6 +82,7 @@ enum EventType { ET_BARCONFIG_UPDATE = (1 << 4), /**< Bar config update event @attention Yet is not implemented as signal in I3Connection */ }; +#ifndef USE_FULL_SIGNALS /** * Types of workspace events */ @@ -101,6 +106,7 @@ enum class WindowEventType : char { FLOATING = '_', /**< Window toggled floating mode */ URGENT = 'u', /**< Window became urgent */ }; +#endif struct buf_t; /** @@ -169,11 +175,16 @@ public: */ void handle_event(); - sigc::signal signal_workspace_event; /**< Workspace event signal */ sigc::signal signal_output_event; /**< Output event signal */ sigc::signal signal_mode_event; /**< Output mode event signal */ - sigc::signal signal_window_event; /**< Window event signal */ sigc::signal signal_barconfig_update_event; /**< Barconfig update event signal */ +#ifdef USE_FULL_SIGNALS + sigc::signal signal_workspace_event; /**< Workspace event signal */ + sigc::signal signal_window_event; /**< Window event signal */ +#else + sigc::signal signal_workspace_event; /**< Workspace event signal */ + sigc::signal signal_window_event; /**< Window event signal */ +#endif sigc::signal&> signal_event; /**< i3 event signal @note Default handler routes event to signal according to type */ private: const int32_t m_main_socket; diff --git a/src/ipc.cpp b/src/ipc.cpp index 9974e62..10c6089 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -78,9 +78,12 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c signal_event.connect([this](EventType event_type, const std::shared_ptr& buf) { switch (event_type) { case ET_WORKSPACE: { - WorkspaceEventType type; Json::Value root; IPC_JSON_READ(root); +#ifdef USE_FULL_SIGNALS + signal_workspace_event.emit(root); +#else + WorkspaceEventType type; std::string change = root["change"].asString(); if (change == "focus") { type = WorkspaceEventType::FOCUS; @@ -97,6 +100,7 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c I3IPC_DEBUG("WORKSPACE " << change) signal_workspace_event.emit(type); +#endif break; } case ET_OUTPUT: @@ -108,9 +112,12 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c signal_mode_event.emit(); break; case ET_WINDOW: { - WindowEventType type; Json::Value root; IPC_JSON_READ(root); +#ifdef USE_FULL_SIGNALS + signal_window_event.emit(root); +#else + WindowEventType type; std::string change = root["change"].asString(); if (change == "new") { type = WindowEventType::NEW; @@ -132,6 +139,7 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c I3IPC_DEBUG("WINDOW " << change) signal_window_event.emit(type); +#endif break; } case ET_BARCONFIG_UPDATE: From 439740abc3561aceceadb0966d6bf19b26912970 Mon Sep 17 00:00:00 2001 From: mox Date: Fri, 22 Apr 2016 12:10:07 +0200 Subject: [PATCH 2/3] Added the neccessary CMake magic to optionally change the API. --- CMakeLists.txt | 11 ++++++++++- include/i3ipc++/ipc.hpp | 8 +++++--- src/ipc.cpp | 6 ++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 931a762..430cf84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(i3ipc++) option(I3IPCpp_WITH_TESTS "Build unit tests executables" OFF) option(I3IPCpp_BUILD_EXAMPLES "Build example executables" OFF) +option(I3IPCpp_USE_FULL_SIGNALS "Provide full JSON event object with the signals for workspace_event and window_event. !!CHANGES API!!" OFF) set(BUILD_STATIC_LIBS ON) set(BUILD_SHARED_LIBS OFF) @@ -13,7 +14,14 @@ UNSET(BUILD_SHARED_LIBS) find_package(PkgConfig) pkg_check_modules(SIGCPP REQUIRED sigc++-2.0) +# configure a header file to pass some settings to the source code +configure_file ( + "${PROJECT_SOURCE_DIR}/include/i3ipc++/i3ipc++_config.hpp.in" + "${PROJECT_BINARY_DIR}/include/i3ipc++_config.hpp" + ) + include_directories( + ${PROJECT_BINARY_DIR}/include ${SIGCPP_INCLUDE_DIRS} 3rd/jsoncpp/include 3rd/auss/include @@ -40,7 +48,8 @@ set(I3IPCpp_INCLUDE_DIRS set(I3IPCpp_LIBRARIES i3ipc++_static ${SIGCPP_LIBRARIES} jsoncpp_lib_static) set(I3IPCpp_LIBRARY_DIRS ${I3IPCpp_LIBRARY_DIRS} PARENT_SCOPE) -set(I3IPCpp_INCLUDE_DIRS ${I3IPCpp_INCLUDE_DIRS} PARENT_SCOPE) +set(I3IPCpp_INCLUDE_DIRS ${I3IPCpp_INCLUDE_DIRS}) +set(I3IPCpp_INCLUDE_DIRS ${I3IPCpp_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/include PARENT_SCOPE) set(I3IPCpp_LIBRARIES ${I3IPCpp_LIBRARIES} PARENT_SCOPE) if(I3IPCpp_BUILD_EXAMPLES) diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index 9ccfe80..4e25e59 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -5,7 +5,9 @@ #include #include -#ifdef USE_FULL_SIGNALS +#include "i3ipc++_config.hpp" + +#ifdef I3IPCpp_USE_FULL_SIGNALS #include #endif @@ -82,7 +84,7 @@ enum EventType { ET_BARCONFIG_UPDATE = (1 << 4), /**< Bar config update event @attention Yet is not implemented as signal in I3Connection */ }; -#ifndef USE_FULL_SIGNALS +#ifndef I3IPCpp_USE_FULL_SIGNALS /** * Types of workspace events */ @@ -178,7 +180,7 @@ public: sigc::signal signal_output_event; /**< Output event signal */ sigc::signal signal_mode_event; /**< Output mode event signal */ sigc::signal signal_barconfig_update_event; /**< Barconfig update event signal */ -#ifdef USE_FULL_SIGNALS +#ifdef I3IPCpp_USE_FULL_SIGNALS sigc::signal signal_workspace_event; /**< Workspace event signal */ sigc::signal signal_window_event; /**< Window event signal */ #else diff --git a/src/ipc.cpp b/src/ipc.cpp index 10c6089..abad402 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -4,7 +4,9 @@ #include #include +#ifndef I3IPCpp_USE_FULL_SIGNALS #include +#endif #include "log.hpp" #include "ipc-util.hpp" @@ -80,7 +82,7 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c case ET_WORKSPACE: { Json::Value root; IPC_JSON_READ(root); -#ifdef USE_FULL_SIGNALS +#ifdef I3IPCpp_USE_FULL_SIGNALS signal_workspace_event.emit(root); #else WorkspaceEventType type; @@ -114,7 +116,7 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c case ET_WINDOW: { Json::Value root; IPC_JSON_READ(root); -#ifdef USE_FULL_SIGNALS +#ifdef I3IPCpp_USE_FULL_SIGNALS signal_window_event.emit(root); #else WindowEventType type; From 99c7bd76accc41487675d1b584966431fd6e3ec6 Mon Sep 17 00:00:00 2001 From: mox Date: Sat, 11 Jun 2016 17:23:11 +0200 Subject: [PATCH 3/3] Removing remaining modification from CMakefileLists.txt, fixing error message for unknown border style: "W: Got a unknown "border" property: "pixel". Perhaps its neccessary to update i3ipc++. If you are using latest, note maintainer about this" caused by setting "new window pixel 1" in the i3config." --- CMakeLists.txt | 11 +---------- include/i3ipc++/ipc.hpp | 9 +-------- src/ipc.cpp | 5 +++-- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5981260..d956298 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ project(i3ipc++) option(I3IPCpp_WITH_TESTS "Build unit tests executables" OFF) option(I3IPCpp_BUILD_EXAMPLES "Build example executables" OFF) -option(I3IPCpp_USE_FULL_SIGNALS "Provide full JSON event object with the signals for workspace_event and window_event. !!CHANGES API!!" OFF) set(BUILD_STATIC_LIBS ON) set(BUILD_SHARED_LIBS OFF) @@ -14,14 +13,7 @@ UNSET(BUILD_SHARED_LIBS) find_package(PkgConfig) pkg_check_modules(SIGCPP REQUIRED sigc++-2.0) -# configure a header file to pass some settings to the source code -configure_file ( - "${PROJECT_SOURCE_DIR}/include/i3ipc++/i3ipc++_config.hpp.in" - "${PROJECT_BINARY_DIR}/include/i3ipc++_config.hpp" - ) - include_directories( - ${PROJECT_BINARY_DIR}/include ${SIGCPP_INCLUDE_DIRS} 3rd/jsoncpp/include 3rd/auss/include @@ -49,8 +41,7 @@ set(I3IPCpp_INCLUDE_DIRS set(I3IPCpp_LIBRARIES i3ipc++_static ${SIGCPP_LIBRARIES} jsoncpp_lib_static) set(I3IPCpp_LIBRARY_DIRS ${I3IPCpp_LIBRARY_DIRS} PARENT_SCOPE) -set(I3IPCpp_INCLUDE_DIRS ${I3IPCpp_INCLUDE_DIRS}) -set(I3IPCpp_INCLUDE_DIRS ${I3IPCpp_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/include PARENT_SCOPE) +set(I3IPCpp_INCLUDE_DIRS ${I3IPCpp_INCLUDE_DIRS} PARENT_SCOPE) set(I3IPCpp_LIBRARIES ${I3IPCpp_LIBRARIES} PARENT_SCOPE) if(I3IPCpp_BUILD_EXAMPLES) diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index b8c25b9..3edc8b5 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -5,12 +5,6 @@ #include #include -#include "i3ipc++_config.hpp" - -#ifdef I3IPCpp_USE_FULL_SIGNALS -#include -#endif - #include extern "C" { @@ -85,7 +79,6 @@ enum EventType { ET_BARCONFIG_UPDATE = (1 << 4), ///< Bar config update event @attention Yet is not implemented as signal in connection }; -#ifndef I3IPCpp_USE_FULL_SIGNALS /** * Types of workspace events */ @@ -118,6 +111,7 @@ enum class BorderStyle : char { UNKNOWN = '?', //< If got an unknown border style in reply NONE = 'N', NORMAL = 'n', + PIXEL = 'P', ONE_PIXEL = '1', }; @@ -159,7 +153,6 @@ struct container_t { std::list< std::shared_ptr > nodes; }; -#endif /** diff --git a/src/ipc.cpp b/src/ipc.cpp index 37e30b6..a94a220 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -4,9 +4,7 @@ #include #include -#ifndef I3IPCpp_USE_FULL_SIGNALS #include -#endif #include "log.hpp" #include "ipc-util.hpp" @@ -78,6 +76,8 @@ static std::shared_ptr parse_container_from_json(const Json::Value container->border = BorderStyle::NORMAL; } else if (border == "none") { container->border = BorderStyle::NONE; + } else if (border == "pixel") { + container->border = BorderStyle::PIXEL; } else if (border == "1pixel") { container->border = BorderStyle::ONE_PIXEL; } else { @@ -178,6 +178,7 @@ std::string get_socketpath() { return str; } + 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" signal_event.connect([this](EventType event_type, const std::shared_ptr& buf) {