Added alterntive API that exposes the JSON event objects in the signals.

This commit is contained in:
mox
2016-04-22 10:39:01 +02:00
parent 54ba4205e6
commit 8882c4f436
2 changed files with 23 additions and 4 deletions

View File

@@ -5,6 +5,10 @@
#include <memory>
#include <vector>
#ifdef USE_FULL_SIGNALS
#include <json/json.h>
#endif
#include <sigc++/sigc++.h>
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<void, WorkspaceEventType> signal_workspace_event; /**< Workspace event signal */
sigc::signal<void> signal_output_event; /**< Output event signal */
sigc::signal<void> signal_mode_event; /**< Output mode event signal */
sigc::signal<void, WindowEventType> signal_window_event; /**< Window event signal */
sigc::signal<void> signal_barconfig_update_event; /**< Barconfig update event signal */
#ifdef USE_FULL_SIGNALS
sigc::signal<void, const Json::Value&> signal_workspace_event; /**< Workspace event signal */
sigc::signal<void, const Json::Value&> signal_window_event; /**< Window event signal */
#else
sigc::signal<void, WorkspaceEventType> signal_workspace_event; /**< Workspace event signal */
sigc::signal<void, WindowEventType> signal_window_event; /**< Window event signal */
#endif
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;

View File

@@ -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<const buf_t>& 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: