From f2ef2b803b92468d99ed07557caa3bd3f0f75ad8 Mon Sep 17 00:00:00 2001 From: Sergey Naumov Date: Tue, 6 Sep 2016 18:48:23 +0300 Subject: [PATCH] Some comments in the examples --- examples/events.cpp | 13 +++++++++++++ examples/workspaces.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/examples/events.cpp b/examples/events.cpp index 4c39951..7509fe4 100644 --- a/examples/events.cpp +++ b/examples/events.cpp @@ -1,18 +1,30 @@ +/** + * This programs handle events and dump them to console + */ + #include #include int main() { + // First of all we need to connect to an i3 process i3ipc::connection conn; + + // Then we subscribing on events (see i3ipc::EVENT_TYPE) conn.subscribe(i3ipc::ET_WORKSPACE | i3ipc::ET_WINDOW | i3ipc::ET_BINDING); + // Handler of workspace_event conn.signal_workspace_event.connect([](const i3ipc::workspace_event_t& ev) { std::cout << "workspace_event: " << (char)ev.type << std::endl; }); + + // Handler of window_event conn.signal_window_event.connect([](const i3ipc::window_event_t& ev) { std::cout << "window_event: " << (char)ev.type << std::endl; }); + + // Handler of binding event conn.signal_binding_event.connect([](const i3ipc::binding_t& b) { std::cout << "binding_event:" << std::endl << "\tcommand = \"" << b.command << '"' << std::endl @@ -25,6 +37,7 @@ int main() { } }); + // And starting an event-handling loop while (true) { conn.handle_event(); } diff --git a/examples/workspaces.cpp b/examples/workspaces.cpp index 174914c..58ea242 100644 --- a/examples/workspaces.cpp +++ b/examples/workspaces.cpp @@ -1,8 +1,17 @@ +/** + * This program dumps a tree of windows and workspaces to console + */ + #include #include +/** + * Reqursively dump containers of a tree + * @param c a root container + * @param prefix an alignment + */ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) { std::cout << prefix << "ID: " << c.id << " (i3's; X11's - " << c.xwindow_id << ")" << std::endl; prefix.push_back('\t'); @@ -28,7 +37,10 @@ void dump_tree_container(const i3ipc::container_t& c, std::string& prefix) { int main() { + // First of all needs to create a connection i3ipc::connection conn; + + // Then we dump workspaces for (auto& w : conn.get_workspaces()) { std::cout << '#' << std::hex << w->num << std::dec << "\n\tName: " << w->name @@ -43,6 +55,8 @@ int main() { << "\n\tOutput: " << w->output << std::endl; } + + // Then we dump the tree std::string prefix_buf; dump_tree_container(*conn.get_tree(), prefix_buf);