Add window_properties processing

This commit is contained in:
BigRedEye
2018-11-16 02:25:28 +03:00
parent b9d5a59ab8
commit b112daf4cb
3 changed files with 40 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) {
prefix.push_back('\t');
std::cout << prefix << "name = \"" << c.name << "\"" << std::endl;
std::cout << prefix << "type = \"" << c.type << "\"" << std::endl;
std::cout << prefix << "class = \"" << c.window_properties.xclass << "\"" << std::endl;
std::cout << prefix << "border = \"" << c.border_raw << "\"" << std::endl;
std::cout << prefix << "current_border_width = " << c.current_border_width << std::endl;
std::cout << prefix << "layout = \"" << c.layout_raw << "\"" << std::endl;

View File

@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <list>
#include <string>
#include <memory>
#include <vector>
@@ -165,6 +166,17 @@ enum class Position : char {
};
/**
* X11 window properties
*/
struct window_properties_t {
std::string xclass; /// X11 Window class (WM_CLASS class)
std::string instance; ///X11 Window class instance (WM_CLASS instance)
std::string window_role; /// X11 Window role (WM_WINDOW_ROLE)
std::string title; /// X11 UTF8 window title (_NET_WM_NAME)
uint64_t transient_for; /// Logical top-level window. Nonzero value is an X11 window ID of the parent window (WM_TRANSIENT_FOR)
};
/**
* A node of tree of windows
*/
@@ -186,6 +198,8 @@ struct container_t {
bool urgent;
bool focused;
window_properties_t window_properties; /// X11 window properties
std::list< std::shared_ptr<container_t> > nodes;
};

View File

@@ -49,6 +49,29 @@ inline rect_t parse_rect_from_json(const Json::Value& value) {
};
}
window_properties_t parse_window_props_from_json(const Json::Value& value) {
if (value.isNull()) {
window_properties_t result;
result.transient_for = 0ull;
return result;
}
window_properties_t result {
value["class"].asString(),
value["instance"].asString(),
value["window_role"].asString(),
value["title"].asString(),
0ull
};
const Json::Value transient_for = value["transient_for"];
if (!transient_for.isNull()) {
result.transient_for = transient_for.asUInt64();
}
return result;
}
static std::shared_ptr<container_t> parse_container_from_json(const Json::Value& o) {
#define i3IPC_TYPE_STR "PARSE CONTAINER FROM JSON"
@@ -113,6 +136,8 @@ static std::shared_ptr<container_t> parse_container_from_json(const Json::Value
}
}
container->window_properties = parse_window_props_from_json(o["window_properties"]);
return container;
#undef i3IPC_TYPE_STR
}