From 20ef07959f70f85940ecbeb8d767e3f39351e76a Mon Sep 17 00:00:00 2001 From: Sergey Naumov Date: Tue, 6 Sep 2016 21:19:12 +0300 Subject: [PATCH] Example "bar-config.cpp" --- examples/CMakeLists.txt | 3 +++ examples/bar-configs.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/bar-configs.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f7b7de7..d1a8285 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,3 +18,6 @@ target_link_libraries(workspaces ${I3IPCpp_LIBRARIES}) add_executable(events events.cpp) target_link_libraries(events ${I3IPCpp_LIBRARIES}) + +add_executable(bar-configs bar-configs.cpp) +target_link_libraries(bar-configs ${I3IPCpp_LIBRARIES}) diff --git a/examples/bar-configs.cpp b/examples/bar-configs.cpp new file mode 100644 index 0000000..f61ab04 --- /dev/null +++ b/examples/bar-configs.cpp @@ -0,0 +1,43 @@ +/** + * This program dumps all available barconfigs + */ + +#include + +#include + + +static void dump_bar_config(const i3ipc::bar_config_t& bc) { + std::cout << '"' << bc.id << '"' << std::endl + << "\tmode = " << static_cast(bc.mode) << std::endl + << "\tposition = " << static_cast(bc.position) << std::endl + << "\tstatus_command = \"" << bc.status_command << '"' << std::endl + << "\tfont = \"" << bc.font << '"' << std::endl + << "\tworkspace_buttons = " << (bc.workspace_buttons ? "true" : "false") << std::endl + << "\tbinding_mode_indicator = " << (bc.binding_mode_indicator ? "true" : "false") << std::endl + << "\tverbose = " << (bc.verbose ? "true" : "false") << std::endl + << "\tcolors:" << std::endl; + + std::cout << std::hex; + for (auto iter = bc.colors.begin(); iter != bc.colors.end(); iter++) { + std::cout << "\t\t\"" << iter->first << "\" = #" << iter->second << std::endl; + } + std::cout << std::dec; +} + + +int main() { + // First of all needs to create a connection + i3ipc::connection conn; + + // Then request a list of barconfigs + std::vector bar_configs = conn.get_bar_configs_list(); + + // And dump 'em all!!!!! + for (auto& name : bar_configs) { + std::shared_ptr bc = conn.get_bar_config(name); + dump_bar_config(*bc); + } + + return 0; +}