From b112daf4cb3bb7e8a7b886ed28015ce5c4e773ef Mon Sep 17 00:00:00 2001 From: BigRedEye Date: Fri, 16 Nov 2018 02:25:28 +0300 Subject: [PATCH] Add window_properties processing --- examples/workspaces.cpp | 1 + include/i3ipc++/ipc.hpp | 14 ++++++++++++++ src/ipc.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/examples/workspaces.cpp b/examples/workspaces.cpp index 58ea242..46f850b 100644 --- a/examples/workspaces.cpp +++ b/examples/workspaces.cpp @@ -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; diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index 0d76a4d..b66b38b 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -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 > nodes; }; diff --git a/src/ipc.cpp b/src/ipc.cpp index 8af9ba0..eeab110 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -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 parse_container_from_json(const Json::Value& o) { #define i3IPC_TYPE_STR "PARSE CONTAINER FROM JSON" @@ -113,6 +136,8 @@ static std::shared_ptr parse_container_from_json(const Json::Value } } + container->window_properties = parse_window_props_from_json(o["window_properties"]); + return container; #undef i3IPC_TYPE_STR }