Skip to content

Commit 20e2cae

Browse files
committed
Inherit workspace informat
1 parent edb1a86 commit 20e2cae

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

examples/workspaces.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) {
2222
std::cout << prefix << "current_border_width = " << c.current_border_width << std::endl;
2323
std::cout << prefix << "layout = \"" << c.layout_raw << "\"" << std::endl;
2424
std::cout << prefix << "percent = " << c.percent << std::endl;
25+
if (c.workspace.has_value()) {
26+
std::cout << prefix << "current_workspace = " << c.workspace.value() << std::endl;
27+
}
2528
if (c.urgent) {
2629
std::cout << prefix << "urgent" << std::endl;
2730
}

include/i3ipc++/ipc.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdint>
44
#include <list>
5+
#include <optional>
56
#include <string>
67
#include <memory>
78
#include <vector>
@@ -198,11 +199,14 @@ struct container_t {
198199
rect_t geometry; ///< The original geometry the window specified when i3 mapped it. Used when switching a window to floating mode, for example
199200
bool urgent;
200201
bool focused;
202+
std::optional<std::string> workspace;
201203

202204
window_properties_t window_properties; /// X11 window properties
203205

204206
std::list< std::shared_ptr<container_t> > nodes;
205207
std::list< std::shared_ptr<container_t> > floating_nodes;
208+
209+
std::map<std::string, std::string> map;
206210
};
207211

208212

src/ipc.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ window_properties_t parse_window_props_from_json(const Json::Value& value) {
7373
}
7474

7575

76-
static std::shared_ptr<container_t> parse_container_from_json(const Json::Value& o) {
76+
static std::shared_ptr<container_t> parse_container_from_json(const Json::Value& o, std::optional<std::string> workspace_name = std::nullopt) {
7777
#define i3IPC_TYPE_STR "PARSE CONTAINER FROM JSON"
7878
if (o.isNull())
7979
return std::shared_ptr<container_t>();
@@ -128,19 +128,39 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
128128
I3IPC_WARN("Got a unknown \"layout\" property: \"" << layout << "\". Perhaps its neccessary to update i3ipc++. If you are using latest, note maintainer about this")
129129
}
130130

131+
for (auto& member : o.getMemberNames()) {
132+
std::string value;
133+
try {
134+
value = o[member].asString();
135+
} catch(const std::exception&) {
136+
// Just collect what we can
137+
continue;
138+
}
139+
140+
container->map[member] = value;
141+
}
142+
143+
if (Json::Value value{o["name"]}; container->type == "workspace" && !value.isNull()) {
144+
container->workspace = value.asString();
145+
} else {
146+
// Inherit workspace if any
147+
container->workspace = workspace_name;
148+
}
149+
150+
131151
Json::Value nodes = o["nodes"];
132152
if (!nodes.isNull()) {
133153
IPC_JSON_ASSERT_TYPE_ARRAY(nodes, "nodes")
134154
for (Json::ArrayIndex i = 0; i < nodes.size(); i++) {
135-
container->nodes.push_back(parse_container_from_json(nodes[i]));
155+
container->nodes.push_back(parse_container_from_json(nodes[i], container->workspace));
136156
}
137157
}
138158

139159
Json::Value floating_nodes = o["floating_nodes"];
140160
if (!floating_nodes.isNull()) {
141161
IPC_JSON_ASSERT_TYPE_ARRAY(floating_nodes, "floating_nodes")
142162
for (Json::ArrayIndex i = 0; i < floating_nodes.size(); i++) {
143-
container->floating_nodes.push_back(parse_container_from_json(floating_nodes[i]));
163+
container->floating_nodes.push_back(parse_container_from_json(floating_nodes[i], container->workspace));
144164
}
145165
}
146166

0 commit comments

Comments
 (0)