refactor: Do not redefine default bar values

This commit is contained in:
Michael Carlberg 2016-10-11 08:18:25 +02:00
parent 12bfa5c89f
commit bcb6894496
3 changed files with 19 additions and 19 deletions

View File

@ -92,7 +92,7 @@ class bar : public xpp::event::sink<evt::button_press> {
if (monitors.empty())
throw application_error("No monitors found");
auto monitor_name = m_conf.get<std::string>(bs, "monitor", "");
auto monitor_name = m_conf.get<string>(bs, "monitor", "");
if (monitor_name.empty())
monitor_name = monitors[0]->name;
@ -144,17 +144,16 @@ class bar : public xpp::event::sink<evt::button_press> {
// }}}
// Set size and position {{{
m_bar.dock = m_conf.get<decltype(m_bar.dock)>(bs, "dock", true);
m_bar.bottom = m_conf.get<decltype(m_bar.bottom)>(bs, "bottom", false);
m_bar.lineheight = m_conf.get<decltype(m_bar.lineheight)>(bs, "lineheight", 0);
m_bar.offset_x = m_conf.get<decltype(m_bar.offset_x)>(bs, "offset_x", 0);
m_bar.offset_y = m_conf.get<decltype(m_bar.offset_y)>(bs, "offset_y", 0);
m_bar.padding_left = m_conf.get<decltype(m_bar.padding_left)>(bs, "padding_left", 0);
m_bar.padding_right = m_conf.get<decltype(m_bar.padding_right)>(bs, "padding_right", 0);
m_bar.module_margin_left =
m_conf.get<decltype(m_bar.module_margin_left)>(bs, "module_margin_left", 0);
m_bar.module_margin_right =
m_conf.get<decltype(m_bar.module_margin_right)>(bs, "module_margin_right", 0);
GET_CONFIG_VALUE(m_bar.dock, "dock");
GET_CONFIG_VALUE(m_bar.bottom, "bottom");
GET_CONFIG_VALUE(m_bar.spacing, "spacing");
GET_CONFIG_VALUE(m_bar.lineheight, "lineheight");
GET_CONFIG_VALUE(m_bar.offset_x, "offset_x");
GET_CONFIG_VALUE(m_bar.offset_y, "offset_y");
GET_CONFIG_VALUE(m_bar.padding_left, "padding_left");
GET_CONFIG_VALUE(m_bar.padding_right, "padding_right");
GET_CONFIG_VALUE(m_bar.module_margin_left, "module_margin_left");
GET_CONFIG_VALUE(m_bar.module_margin_right, "module_margin_right");
auto w = m_conf.get<string>(bs, "width", "100%");
auto h = m_conf.get<string>(bs, "height", "24");

View File

@ -9,6 +9,8 @@
#include "utils/file.hpp"
#include "utils/string.hpp"
#define GET_CONFIG_VALUE(var, name) var = m_conf.get<decltype(var)>(bs, name, var)
LEMONBUDDY_NS
using ptree = boost::property_tree::ptree;
@ -104,7 +106,7 @@ class config {
auto val = m_ptree.get_optional<T>(build_path(section, key));
if (val == boost::none)
throw key_error("Missing property '" + key + "' in section [" + section + "]");
throw key_error("Missing parameter [" + section + "." + key + "]");
auto str_val = m_ptree.get<string>(build_path(section, key));
@ -147,7 +149,7 @@ class config {
}
if (vec.empty())
throw key_error("Missing property '" + key + "-0' in section [" + section + "]");
throw key_error("Missing parameter [" + section + "." + key + "-0]");
return vec;
}
@ -205,15 +207,14 @@ class config {
auto ref_path = build_path(ref_section, ref_key);
if ((n = path.find(".")) == string::npos)
throw value_error("Invalid variable " + ref_path + " => ${" + path + "}");
throw value_error("Invalid reference defined at [" + ref_path + "]");
auto section = string_util::replace(path.substr(0, n), "BAR", bar_section());
auto key = path.substr(n + 1, path.length() - n - 1);
auto val = m_ptree.get_optional<T>(build_path(section, key));
if (val == boost::none)
throw value_error("Variable defined at [" + ref_path +
"] points to a non existing parameter: [" + build_path(section, key) + "]");
throw value_error("Unexisting reference defined at [" + ref_path + "]");
auto str_val = m_ptree.get<string>(build_path(section, key));

View File

@ -27,8 +27,8 @@ struct bar_settings {
uint16_t padding_left{0};
uint16_t padding_right{0};
int16_t module_margin_left = 0;
int16_t module_margin_right = 2;
int16_t module_margin_left{0};
int16_t module_margin_right{2};
int16_t lineheight{0};
int16_t spacing{1};