From 2995da845d75b0807ea757833605a4a14ecdc1ea Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 10 Mar 2019 10:34:56 +0100 Subject: [PATCH] fix: config per output --- src/bar.cpp | 97 ++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/src/bar.cpp b/src/bar.cpp index 71540839..466f29b2 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -37,7 +37,54 @@ waybar::Bar::Bar(const Client& client, void waybar::Bar::initBar() { - std::size_t layer_top = config_["layer"] == "top" + // Converting string to button code rn as to avoid doing it later + auto setupAltFormatKeyForModule = [this](const std::string& module_name){ + if (config_.isMember(module_name)) { + Json::Value& module = config_[module_name]; + if (module.isMember("format-alt")) { + if (module.isMember("format-alt-click")) { + Json::Value& click = module["format-alt-click"]; + if (click.isString()) { + std::string str_click = click.asString(); + + if (str_click == "click-right") { + module["format-alt-click"] = 3u; + } else if (str_click == "click-middle") { + module["format-alt-click"] = 2u; + } else if (str_click == "click-backward") { + module["format-alt-click"] = 8u; + } else if (str_click == "click-forward") { + module["format-alt-click"] = 9u; + } else { + module["format-alt-click"] = 1u; // default click-left + } + } else { + module["format-alt-click"] = 1u; + } + } else { + module["format-alt-click"] = 1u; + } + + } + } + }; + + auto setupAltFormatKeyForModuleList = [this, &setupAltFormatKeyForModule](const char* module_list_name) { + if (config_.isMember(module_list_name)) { + Json::Value& modules = config_[module_list_name]; + for (const Json::Value& module_name : modules) { + if (module_name.isString()) { + setupAltFormatKeyForModule(module_name.asString()); + } + } + } + }; + + // Convert to button code for every module that is used. + setupAltFormatKeyForModuleList("modules-left"); + setupAltFormatKeyForModuleList("modules-right"); + setupAltFormatKeyForModuleList("modules-center"); + std::size_t layer_top = config_["layer"] == "top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; layer_surface = zwlr_layer_shell_v1_get_layer_surface( client.layer_shell, surface, *output, layer_top, "waybar"); @@ -196,54 +243,6 @@ auto waybar::Bar::setupConfig() -> void std::istreambuf_iterator()); util::JsonParser parser; config_ = parser.parse(str); - - // Converting string to button code rn as to avoid doing it later - auto setupAltFormatKeyForModule = [this](const std::string& module_name){ - if (config_.isMember(module_name)) { - Json::Value& module = config_[module_name]; - if (module.isMember("format-alt")) { - if (module.isMember("format-alt-click")) { - Json::Value& click = module["format-alt-click"]; - if (click.isString()) { - std::string str_click = click.asString(); - - if (str_click == "click-right") { - module["format-alt-click"] = 3u; - } else if (str_click == "click-middle") { - module["format-alt-click"] = 2u; - } else if (str_click == "click-backward") { - module["format-alt-click"] = 8u; - } else if (str_click == "click-forward") { - module["format-alt-click"] = 9u; - } else { - module["format-alt-click"] = 1u; // default click-left - } - } else { - module["format-alt-click"] = 1u; - } - } else { - module["format-alt-click"] = 1u; - } - - } - } - }; - - auto setupAltFormatKeyForModuleList = [this, &setupAltFormatKeyForModule](const char* module_list_name) { - if (config_.isMember(module_list_name)) { - Json::Value& modules = config_[module_list_name]; - for (const Json::Value& module_name : modules) { - if (module_name.isString()) { - setupAltFormatKeyForModule(module_name.asString()); - } - } - } - }; - - // Convert to button code for every module that is used. - setupAltFormatKeyForModuleList("modules-left"); - setupAltFormatKeyForModuleList("modules-right"); - setupAltFormatKeyForModuleList("modules-center"); } auto waybar::Bar::setupCss() -> void