From bcb68944968574d3ed1dfadf826da5eb4978a16b Mon Sep 17 00:00:00 2001
From: Michael Carlberg <c@rlberg.se>
Date: Tue, 11 Oct 2016 08:18:25 +0200
Subject: [PATCH] refactor: Do not redefine default bar values

---
 include/components/bar.hpp    | 23 +++++++++++------------
 include/components/config.hpp | 11 ++++++-----
 include/components/types.hpp  |  4 ++--
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/include/components/bar.hpp b/include/components/bar.hpp
index b8763e19..b6230c8d 100644
--- a/include/components/bar.hpp
+++ b/include/components/bar.hpp
@@ -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");
diff --git a/include/components/config.hpp b/include/components/config.hpp
index bfe5530f..fb635a0f 100644
--- a/include/components/config.hpp
+++ b/include/components/config.hpp
@@ -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));
 
diff --git a/include/components/types.hpp b/include/components/types.hpp
index 58869f23..8312cd9d 100644
--- a/include/components/types.hpp
+++ b/include/components/types.hpp
@@ -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};