diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 8e5d1762..8efab743 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -8,6 +9,7 @@ #include "errors.hpp" #include "events/signal_fwd.hpp" #include "events/signal_receiver.hpp" +#include "utils/math.hpp" #include "settings.hpp" #include "x11/types.hpp" #include "x11/window.hpp" @@ -25,6 +27,21 @@ class taskqueue; class tray_manager; // }}} +inline double geom_format_to_pixels(std::string str, double max) { + size_t i; + if ((i = str.find(':')) != std::string::npos) { + std::string a = str.substr(0, i - 1); + std::string b = str.substr(i + 1); + return math_util::percentage_to_value(strtof(a.c_str(), nullptr), max) + strtof(b.c_str(), nullptr); + } else { + if (str.find('%') != std::string::npos) { + return math_util::percentage_to_value(strtof(str.c_str(), nullptr), max); + } else { + return strtof(str.c_str(), nullptr); + } + } +} + class bar : public xpp::event::sink, public signal_receiver(tmp, m_opts.monitor->w); - } - if ((tmp = strtof(h.c_str(), nullptr)) && h.find('%') != string::npos) { - m_opts.size.h = math_util::percentage_to_value(tmp, m_opts.monitor->h); - } - if ((tmp = strtof(offsetx.c_str(), nullptr)) != 0 && offsetx.find('%') != string::npos) { - m_opts.offset.x = math_util::percentage_to_value(tmp, m_opts.monitor->w); - } - if ((tmp = strtof(offsety.c_str(), nullptr)) != 0 && offsety.find('%') != string::npos) { - m_opts.offset.y = math_util::percentage_to_value(tmp, m_opts.monitor->h); - } + m_opts.size.w = geom_format_to_pixels(w, m_opts.monitor->w); + m_opts.size.h = geom_format_to_pixels(h, m_opts.monitor->h);; + m_opts.offset.x = geom_format_to_pixels(offsetx, m_opts.monitor->w); + m_opts.offset.y = geom_format_to_pixels(offsety, m_opts.monitor->h); // Apply offsets m_opts.pos.x = m_opts.offset.x + m_opts.monitor->x;