Inherit workspace informat

This commit is contained in:
Mike Wallio
2020-10-23 16:14:15 -04:00
parent edb1a864f0
commit 20e2cae81c
3 changed files with 30 additions and 3 deletions

View File

@@ -22,6 +22,9 @@ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) {
std::cout << prefix << "current_border_width = " << c.current_border_width << std::endl;
std::cout << prefix << "layout = \"" << c.layout_raw << "\"" << std::endl;
std::cout << prefix << "percent = " << c.percent << std::endl;
if (c.workspace.has_value()) {
std::cout << prefix << "current_workspace = " << c.workspace.value() << std::endl;
}
if (c.urgent) {
std::cout << prefix << "urgent" << std::endl;
}

View File

@@ -2,6 +2,7 @@
#include <cstdint>
#include <list>
#include <optional>
#include <string>
#include <memory>
#include <vector>
@@ -198,11 +199,14 @@ struct container_t {
rect_t geometry; ///< The original geometry the window specified when i3 mapped it. Used when switching a window to floating mode, for example
bool urgent;
bool focused;
std::optional<std::string> workspace;
window_properties_t window_properties; /// X11 window properties
std::list< std::shared_ptr<container_t> > nodes;
std::list< std::shared_ptr<container_t> > floating_nodes;
std::map<std::string, std::string> map;
};

View File

@@ -73,7 +73,7 @@ window_properties_t parse_window_props_from_json(const Json::Value& value) {
}
static std::shared_ptr<container_t> parse_container_from_json(const Json::Value& o) {
static std::shared_ptr<container_t> parse_container_from_json(const Json::Value& o, std::optional<std::string> workspace_name = std::nullopt) {
#define i3IPC_TYPE_STR "PARSE CONTAINER FROM JSON"
if (o.isNull())
return std::shared_ptr<container_t>();
@@ -128,11 +128,31 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
I3IPC_WARN("Got a unknown \"layout\" property: \"" << layout << "\". Perhaps its neccessary to update i3ipc++. If you are using latest, note maintainer about this")
}
for (auto& member : o.getMemberNames()) {
std::string value;
try {
value = o[member].asString();
} catch(const std::exception&) {
// Just collect what we can
continue;
}
container->map[member] = value;
}
if (Json::Value value{o["name"]}; container->type == "workspace" && !value.isNull()) {
container->workspace = value.asString();
} else {
// Inherit workspace if any
container->workspace = workspace_name;
}
Json::Value nodes = o["nodes"];
if (!nodes.isNull()) {
IPC_JSON_ASSERT_TYPE_ARRAY(nodes, "nodes")
for (Json::ArrayIndex i = 0; i < nodes.size(); i++) {
container->nodes.push_back(parse_container_from_json(nodes[i]));
container->nodes.push_back(parse_container_from_json(nodes[i], container->workspace));
}
}
@@ -140,7 +160,7 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
if (!floating_nodes.isNull()) {
IPC_JSON_ASSERT_TYPE_ARRAY(floating_nodes, "floating_nodes")
for (Json::ArrayIndex i = 0; i < floating_nodes.size(); i++) {
container->floating_nodes.push_back(parse_container_from_json(floating_nodes[i]));
container->floating_nodes.push_back(parse_container_from_json(floating_nodes[i], container->workspace));
}
}