Skip to content

Commit 88c350a

Browse files
committed
An example for get_tree()
1 parent 456c27b commit 88c350a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/workspaces.cpp

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

33
#include <i3ipc++/ipc.hpp>
44

5+
6+
void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) {
7+
std::cout << prefix << "ID: " << c.id << " (i3's; X11's - " << c.xwindow_id << ")" << std::endl;
8+
prefix.push_back('\t');
9+
std::cout << prefix << "name = \"" << c.name << "\"" << std::endl;
10+
std::cout << prefix << "type = \"" << c.type << "\"" << std::endl;
11+
std::cout << prefix << "border = \"" << c.border_raw << "\"" << std::endl;
12+
std::cout << prefix << "current_border_width = " << c.current_border_width << std::endl;
13+
std::cout << prefix << "layout = \"" << c.layout_raw << "\"" << std::endl;
14+
std::cout << prefix << "percent = " << c.percent << std::endl;
15+
if (c.urgent) {
16+
std::cout << prefix << "urgent" << std::endl;
17+
}
18+
if (c.focused) {
19+
std::cout << prefix << "focused" << std::endl;
20+
}
21+
prefix.push_back('\t');
22+
for (auto& n : c.nodes) {
23+
dump_tree_container(*n, prefix);
24+
}
25+
prefix.pop_back();
26+
prefix.pop_back();
27+
}
28+
29+
530
int main() {
631
i3ipc::I3Connection conn;
732
for (auto& w : conn.get_workspaces()) {
@@ -18,5 +43,8 @@ int main() {
1843
<< "\n\tOutput: " << w.output
1944
<< std::endl;
2045
}
46+
std::string prefix_buf;
47+
dump_tree_container(*conn.get_tree(), prefix_buf);
48+
2149
return 0;
2250
}

0 commit comments

Comments
 (0)