From 8882c4f43617d350ba2ae51bf72a56407bacc41b Mon Sep 17 00:00:00 2001 From: mox Date: Fri, 22 Apr 2016 10:39:01 +0200 Subject: [PATCH] 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: