Skip to content

Commit 8882c4f

Browse files
committed
Added alterntive API that exposes the JSON event objects in the signals.
1 parent 54ba420 commit 8882c4f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

include/i3ipc++/ipc.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <memory>
66
#include <vector>
77

8+
#ifdef USE_FULL_SIGNALS
9+
#include <json/json.h>
10+
#endif
11+
812
#include <sigc++/sigc++.h>
913

1014
extern "C" {
@@ -78,6 +82,7 @@ enum EventType {
7882
ET_BARCONFIG_UPDATE = (1 << 4), /**< Bar config update event @attention Yet is not implemented as signal in I3Connection */
7983
};
8084

85+
#ifndef USE_FULL_SIGNALS
8186
/**
8287
* Types of workspace events
8388
*/
@@ -101,6 +106,7 @@ enum class WindowEventType : char {
101106
FLOATING = '_', /**< Window toggled floating mode */
102107
URGENT = 'u', /**< Window became urgent */
103108
};
109+
#endif
104110

105111
struct buf_t;
106112
/**
@@ -169,11 +175,16 @@ class I3Connection {
169175
*/
170176
void handle_event();
171177

172-
sigc::signal<void, WorkspaceEventType> signal_workspace_event; /**< Workspace event signal */
173178
sigc::signal<void> signal_output_event; /**< Output event signal */
174179
sigc::signal<void> signal_mode_event; /**< Output mode event signal */
175-
sigc::signal<void, WindowEventType> signal_window_event; /**< Window event signal */
176180
sigc::signal<void> signal_barconfig_update_event; /**< Barconfig update event signal */
181+
#ifdef USE_FULL_SIGNALS
182+
sigc::signal<void, const Json::Value&> signal_workspace_event; /**< Workspace event signal */
183+
sigc::signal<void, const Json::Value&> signal_window_event; /**< Window event signal */
184+
#else
185+
sigc::signal<void, WorkspaceEventType> signal_workspace_event; /**< Workspace event signal */
186+
sigc::signal<void, WindowEventType> signal_window_event; /**< Window event signal */
187+
#endif
177188
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 */
178189
private:
179190
const int32_t m_main_socket;

src/ipc.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c
7878
signal_event.connect([this](EventType event_type, const std::shared_ptr<const buf_t>& buf) {
7979
switch (event_type) {
8080
case ET_WORKSPACE: {
81-
WorkspaceEventType type;
8281
Json::Value root;
8382
IPC_JSON_READ(root);
83+
#ifdef USE_FULL_SIGNALS
84+
signal_workspace_event.emit(root);
85+
#else
86+
WorkspaceEventType type;
8487
std::string change = root["change"].asString();
8588
if (change == "focus") {
8689
type = WorkspaceEventType::FOCUS;
@@ -97,6 +100,7 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c
97100
I3IPC_DEBUG("WORKSPACE " << change)
98101

99102
signal_workspace_event.emit(type);
103+
#endif
100104
break;
101105
}
102106
case ET_OUTPUT:
@@ -108,9 +112,12 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c
108112
signal_mode_event.emit();
109113
break;
110114
case ET_WINDOW: {
111-
WindowEventType type;
112115
Json::Value root;
113116
IPC_JSON_READ(root);
117+
#ifdef USE_FULL_SIGNALS
118+
signal_window_event.emit(root);
119+
#else
120+
WindowEventType type;
114121
std::string change = root["change"].asString();
115122
if (change == "new") {
116123
type = WindowEventType::NEW;
@@ -132,6 +139,7 @@ I3Connection::I3Connection(const std::string& socket_path) : m_main_socket(i3_c
132139
I3IPC_DEBUG("WINDOW " << change)
133140

134141
signal_window_event.emit(type);
142+
#endif
135143
break;
136144
}
137145
case ET_BARCONFIG_UPDATE:

0 commit comments

Comments
 (0)