From 738fc2a216e045df28924a9cf3145c2a9cc277c9 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 31 Oct 2016 04:01:33 +0100 Subject: [PATCH] feat: Offset window position using % --- include/components/bar.hpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 0b5535e2..8d9a9686 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -145,8 +145,6 @@ class bar : public xpp::event::sink(bs, "width", "100%"); auto h = m_conf.get(bs, "height", "24"); - m_bar.width = std::atoi(w.c_str()); - if (w.find("%") != string::npos) - m_bar.width = m_bar.monitor->w * (m_bar.width / 100.0) + 0.5f; + auto offsetx = m_conf.get(bs, "offset-x", ""); + auto offsety = m_conf.get(bs, "offset-y", ""); - m_bar.height = std::atoi(h.c_str()); - if (h.find("%") != string::npos) - m_bar.height = m_bar.monitor->h * (m_bar.height / 100.0) + 0.5f; + // look for user-defined width + if ((m_bar.width = std::atoi(w.c_str())) && w.find("%") != string::npos) { + m_bar.width = math_util::percentage_to_value(m_bar.width, m_bar.monitor->w); + } + + // look for user-defined height + if ((m_bar.height = std::atoi(h.c_str())) && h.find("%") != string::npos) { + m_bar.height = math_util::percentage_to_value(m_bar.height, m_bar.monitor->h); + } + + // look for user-defined offset-x + if ((m_bar.offset_x = std::atoi(offsetx.c_str())) != 0 && offsetx.find("%") != string::npos) { + m_bar.offset_x = math_util::percentage_to_value(m_bar.offset_x, m_bar.monitor->w); + } + + // look for user-defined offset-y + if ((m_bar.offset_y = std::atoi(offsety.c_str())) != 0 && offsety.find("%") != string::npos) { + m_bar.offset_y = math_util::percentage_to_value(m_bar.offset_y, m_bar.monitor->h); + } // apply offsets m_bar.x = m_bar.offset_x + m_bar.monitor->x;