diff --git a/examples/workspaces.cpp b/examples/workspaces.cpp index 46f850b..bfaa701 100644 --- a/examples/workspaces.cpp +++ b/examples/workspaces.cpp @@ -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; } diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index 2ae412f..51e080c 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -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 workspace; window_properties_t window_properties; /// X11 window properties std::list< std::shared_ptr > nodes; std::list< std::shared_ptr > floating_nodes; + + std::map map; }; diff --git a/src/ipc.cpp b/src/ipc.cpp index e4f06bd..8581877 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -73,7 +73,7 @@ window_properties_t parse_window_props_from_json(const Json::Value& value) { } -static std::shared_ptr parse_container_from_json(const Json::Value& o) { +static std::shared_ptr parse_container_from_json(const Json::Value& o, std::optional workspace_name = std::nullopt) { #define i3IPC_TYPE_STR "PARSE CONTAINER FROM JSON" if (o.isNull()) return std::shared_ptr(); @@ -128,11 +128,31 @@ static std::shared_ptr 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 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)); } }