@@ -113,7 +113,7 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
113113#undef i3IPC_TYPE_STR
114114}
115115
116- static workspace_t parse_workspace_from_json (const Json::Value& value) {
116+ static std::shared_ptr< workspace_t > parse_workspace_from_json (const Json::Value& value) {
117117 Json::Value num = value[" num" ];
118118 Json::Value name = value[" name" ];
119119 Json::Value visible = value[" visible" ];
@@ -122,29 +122,29 @@ static workspace_t parse_workspace_from_json(const Json::Value& value) {
122122 Json::Value rect = value[" rect" ];
123123 Json::Value output = value[" output" ];
124124
125- return {
126- . num = num.asInt (),
127- . name = name.asString (),
128- . visible = visible.asBool (),
129- . focused = focused.asBool (),
130- . urgent = urgent.asBool (),
131- . rect = parse_rect_from_json (rect),
132- . output = output.asString (),
133- } ;
125+ std::shared_ptr< workspace_t > p;
126+ p-> num = num.asInt ();
127+ p-> name = name.asString ();
128+ p-> visible = visible.asBool ();
129+ p-> focused = focused.asBool ();
130+ p-> urgent = urgent.asBool ();
131+ p-> rect = parse_rect_from_json (rect);
132+ p-> output = output.asString ();
133+ return p ;
134134}
135135
136- static output_t parse_output_from_json (const Json::Value& value) {
136+ static std::shared_ptr< output_t > parse_output_from_json (const Json::Value& value) {
137137 Json::Value name = value[" name" ];
138138 Json::Value active = value[" active" ];
139139 Json::Value current_workspace = value[" current_workspace" ];
140140 Json::Value rect = value[" rect" ];
141141
142- return {
143- . name = name.asString (),
144- . active = active.asBool (),
145- . current_workspace = (current_workspace.isNull () ? std::string () : current_workspace.asString ()),
146- . rect = parse_rect_from_json (rect),
147- } ;
142+ std::shared_ptr< output_t > p;
143+ p-> name = name.asString ();
144+ p-> active = active.asBool ();
145+ p-> current_workspace = (current_workspace.isNull () ? std::string () : current_workspace.asString ());
146+ p-> rect = parse_rect_from_json (rect);
147+ return p ;
148148}
149149
150150
@@ -176,25 +176,35 @@ connection::connection(const std::string& socket_path) : m_main_socket(i3_conne
176176 signal_event.connect ([this ](EventType event_type, const std::shared_ptr<const buf_t >& buf) {
177177 switch (event_type) {
178178 case ET_WORKSPACE: {
179- WorkspaceEventType type ;
179+ workspace_event_t ev ;
180180 Json::Value root;
181181 IPC_JSON_READ (root);
182182 std::string change = root[" change" ].asString ();
183183 if (change == " focus" ) {
184- type = WorkspaceEventType::FOCUS;
184+ ev. type = WorkspaceEventType::FOCUS;
185185 } else if (change == " init" ) {
186- type = WorkspaceEventType::INIT;
186+ ev. type = WorkspaceEventType::INIT;
187187 } else if (change == " empty" ) {
188- type = WorkspaceEventType::EMPTY;
188+ ev. type = WorkspaceEventType::EMPTY;
189189 } else if (change == " urgent" ) {
190- type = WorkspaceEventType::URGENT;
190+ ev. type = WorkspaceEventType::URGENT;
191191 } else {
192192 I3IPC_WARN (" Unknown workspace event type " << change)
193193 break ;
194194 }
195195 I3IPC_DEBUG (" WORKSPACE " << change)
196196
197- signal_workspace_event.emit (type);
197+ Json::Value current = root[" current" ];
198+ Json::Value old = root[" current" ];
199+
200+ if (!current.isNull ()) {
201+ ev.current = parse_workspace_from_json (current);
202+ }
203+ if (!old.isNull ()) {
204+ ev.old = parse_workspace_from_json (old);
205+ }
206+
207+ signal_workspace_event.emit (ev);
198208 break ;
199209 }
200210 case ET_OUTPUT:
@@ -206,30 +216,35 @@ connection::connection(const std::string& socket_path) : m_main_socket(i3_conne
206216 signal_mode_event.emit ();
207217 break ;
208218 case ET_WINDOW: {
209- WindowEventType type ;
219+ window_event_t ev ;
210220 Json::Value root;
211221 IPC_JSON_READ (root);
212222 std::string change = root[" change" ].asString ();
213223 if (change == " new" ) {
214- type = WindowEventType::NEW;
224+ ev. type = WindowEventType::NEW;
215225 } else if (change == " close" ) {
216- type = WindowEventType::CLOSE;
226+ ev. type = WindowEventType::CLOSE;
217227 } else if (change == " focus" ) {
218- type = WindowEventType::FOCUS;
228+ ev. type = WindowEventType::FOCUS;
219229 } else if (change == " title" ) {
220- type = WindowEventType::TITLE;
230+ ev. type = WindowEventType::TITLE;
221231 } else if (change == " fullscreen_mode" ) {
222- type = WindowEventType::FULLSCREEN_MODE;
232+ ev. type = WindowEventType::FULLSCREEN_MODE;
223233 } else if (change == " move" ) {
224- type = WindowEventType::MOVE;
234+ ev. type = WindowEventType::MOVE;
225235 } else if (change == " floating" ) {
226- type = WindowEventType::FLOATING;
236+ ev. type = WindowEventType::FLOATING;
227237 } else if (change == " urgent" ) {
228- type = WindowEventType::URGENT;
238+ ev. type = WindowEventType::URGENT;
229239 }
230240 I3IPC_DEBUG (" WINDOW " << change)
231241
232- signal_window_event.emit (type);
242+ Json::Value container = root[" container" ];
243+ if (!container.isNull ()) {
244+ ev.container = parse_container_from_json (container);
245+ }
246+
247+ signal_window_event.emit (ev);
233248 break ;
234249 }
235250 case ET_BARCONFIG_UPDATE:
@@ -332,14 +347,14 @@ std::shared_ptr<container_t> connection::get_tree() const {
332347}
333348
334349
335- std::vector<output_t > connection::get_outputs () const {
350+ std::vector< std::shared_ptr< output_t > > connection::get_outputs () const {
336351#define i3IPC_TYPE_STR " GET_OUTPUTS"
337352 auto buf = i3_msg (m_main_socket, ClientMessageType::GET_OUTPUTS);
338353 Json::Value root;
339354 IPC_JSON_READ (root)
340355 IPC_JSON_ASSERT_TYPE_ARRAY (root, " root" )
341356
342- std::vector<output_t > outputs;
357+ std::vector< std::shared_ptr< output_t > > outputs;
343358
344359 for (auto w : root) {
345360 outputs.push_back (parse_output_from_json (w));
@@ -350,14 +365,14 @@ std::vector<output_t> connection::get_outputs() const {
350365}
351366
352367
353- std::vector<workspace_t > connection::get_workspaces () const {
368+ std::vector< std::shared_ptr< workspace_t > > connection::get_workspaces () const {
354369#define i3IPC_TYPE_STR " GET_WORKSPACES"
355370 auto buf = i3_msg (m_main_socket, ClientMessageType::GET_WORKSPACES);
356371 Json::Value root;
357372 IPC_JSON_READ (root)
358373 IPC_JSON_ASSERT_TYPE_ARRAY (root, " root" )
359374
360- std::vector<workspace_t > workspaces;
375+ std::vector< std::shared_ptr< workspace_t > > workspaces;
361376
362377 for (auto w : root) {
363378 workspaces.push_back (parse_workspace_from_json (w));
0 commit comments