1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

Added support for mixed percent/pixel geometry.

This commit is contained in:
lukediamond 2018-05-02 21:38:40 -04:00 committed by Patrick Ziegler
parent 0dddb0be4a
commit c2ac93db55
2 changed files with 21 additions and 19 deletions

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <cstdlib>
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
@ -8,6 +9,7 @@
#include "errors.hpp" #include "errors.hpp"
#include "events/signal_fwd.hpp" #include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp" #include "events/signal_receiver.hpp"
#include "utils/math.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "x11/types.hpp" #include "x11/types.hpp"
#include "x11/window.hpp" #include "x11/window.hpp"
@ -25,6 +27,21 @@ class taskqueue;
class tray_manager; 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<double>(strtof(a.c_str(), nullptr), max) + strtof(b.c_str(), nullptr);
} else {
if (str.find('%') != std::string::npos) {
return math_util::percentage_to_value<double>(strtof(str.c_str(), nullptr), max);
} else {
return strtof(str.c_str(), nullptr);
}
}
}
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify, class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify,
evt::leave_notify, evt::motion_notify, evt::destroy_notify, evt::client_message>, evt::leave_notify, evt::motion_notify, evt::destroy_notify, evt::client_message>,
public signal_receiver<SIGN_PRIORITY_BAR, signals::eventqueue::start, signals::ui::tick, public signal_receiver<SIGN_PRIORITY_BAR, signals::eventqueue::start, signals::ui::tick,

View file

@ -248,25 +248,10 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
auto offsetx = m_conf.get(m_conf.section(), "offset-x", ""s); auto offsetx = m_conf.get(m_conf.section(), "offset-x", ""s);
auto offsety = m_conf.get(m_conf.section(), "offset-y", ""s); auto offsety = m_conf.get(m_conf.section(), "offset-y", ""s);
m_opts.size.w = std::strtol(w.c_str(), nullptr, 10); m_opts.size.w = geom_format_to_pixels(w, m_opts.monitor->w);
m_opts.size.h = std::strtol(h.c_str(), nullptr, 10); m_opts.size.h = geom_format_to_pixels(h, m_opts.monitor->h);;
m_opts.offset.x = std::strtol(offsetx.c_str(), nullptr, 10); m_opts.offset.x = geom_format_to_pixels(offsetx, m_opts.monitor->w);
m_opts.offset.y = std::strtol(offsety.c_str(), nullptr, 10); m_opts.offset.y = geom_format_to_pixels(offsety, m_opts.monitor->h);
// Evaluate percentages
double tmp;
if ((tmp = strtof(w.c_str(), nullptr)) && w.find('%') != string::npos) {
m_opts.size.w = math_util::percentage_to_value<double>(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<double>(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<double>(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<double>(tmp, m_opts.monitor->h);
}
// Apply offsets // Apply offsets
m_opts.pos.x = m_opts.offset.x + m_opts.monitor->x; m_opts.pos.x = m_opts.offset.x + m_opts.monitor->x;