From 224ffa97c117eeddd396b076dbac2081b9652c35 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sun, 21 Jan 2018 17:54:15 -0500 Subject: [PATCH] feat(config): Support fractional size and offset Fixes #953. --- src/components/bar.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/bar.cpp b/src/components/bar.cpp index b5e6a030..e874fad5 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -248,17 +248,24 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const auto offsetx = m_conf.get(m_conf.section(), "offset-x", ""s); auto offsety = m_conf.get(m_conf.section(), "offset-y", ""s); - if ((m_opts.size.w = atoi(w.c_str())) && w.find('%') != string::npos) { - m_opts.size.w = math_util::percentage_to_value(m_opts.size.w, m_opts.monitor->w); + m_opts.size.w = atoi(w.c_str()); + m_opts.size.h = atoi(h.c_str()); + m_opts.offset.x = atoi(offsetx.c_str()); + m_opts.offset.y = atoi(offsety.c_str()); + + // Evaluate percentages + double tmp; + if ((tmp = atof(w.c_str())) && w.find('%') != string::npos) { + m_opts.size.w = math_util::percentage_to_value(tmp, m_opts.monitor->w); } - if ((m_opts.size.h = atoi(h.c_str())) && h.find('%') != string::npos) { - m_opts.size.h = math_util::percentage_to_value(m_opts.size.h, m_opts.monitor->h); + if ((tmp = atof(h.c_str())) && h.find('%') != string::npos) { + m_opts.size.h = math_util::percentage_to_value(tmp, m_opts.monitor->h); } - if ((m_opts.offset.x = atoi(offsetx.c_str())) != 0 && offsetx.find('%') != string::npos) { - m_opts.offset.x = math_util::percentage_to_value(m_opts.offset.x, m_opts.monitor->w); + if ((tmp = atof(offsetx.c_str())) != 0 && offsetx.find('%') != string::npos) { + m_opts.offset.x = math_util::percentage_to_value(tmp, m_opts.monitor->w); } - if ((m_opts.offset.y = atoi(offsety.c_str())) != 0 && offsety.find('%') != string::npos) { - m_opts.offset.y = math_util::percentage_to_value(m_opts.offset.y, m_opts.monitor->h); + if ((tmp = atof(offsety.c_str())) != 0 && offsety.find('%') != string::npos) { + m_opts.offset.y = math_util::percentage_to_value(tmp, m_opts.monitor->h); } // Apply offsets