polybar/src/modules/text.cpp

57 lines
1.5 KiB
C++
Raw Normal View History

2016-11-02 19:22:45 +00:00
#include "modules/text.hpp"
2016-11-20 22:04:31 +00:00
#include "modules/meta/base.inl"
#include "modules/meta/static_module.inl"
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-11-02 19:22:45 +00:00
namespace modules {
2016-11-20 22:04:31 +00:00
template class module<text_module>;
template class static_module<text_module>;
2016-11-02 19:22:45 +00:00
void text_module::setup() {
m_formatter->add("content", "", {});
2016-11-25 12:55:15 +00:00
if (m_formatter->get("content")->value.empty()) {
2016-11-02 19:22:45 +00:00
throw module_error(name() + ".content is empty or undefined");
2016-11-25 12:55:15 +00:00
}
2016-11-02 19:22:45 +00:00
m_formatter->get("content")->value =
string_util::replace_all(m_formatter->get("content")->value, " ", BUILDER_SPACE_TOKEN);
}
string text_module::get_format() const {
return "content";
}
string text_module::get_output() {
auto click_left = m_conf.get<string>(name(), "click-left", "");
auto click_middle = m_conf.get<string>(name(), "click-middle", "");
auto click_right = m_conf.get<string>(name(), "click-right", "");
auto scroll_up = m_conf.get<string>(name(), "scroll-up", "");
auto scroll_down = m_conf.get<string>(name(), "scroll-down", "");
2016-11-25 12:55:15 +00:00
if (!click_left.empty()) {
2016-11-02 19:22:45 +00:00
m_builder->cmd(mousebtn::LEFT, click_left);
2016-11-25 12:55:15 +00:00
}
if (!click_middle.empty()) {
2016-11-02 19:22:45 +00:00
m_builder->cmd(mousebtn::MIDDLE, click_middle);
2016-11-25 12:55:15 +00:00
}
if (!click_right.empty()) {
2016-11-02 19:22:45 +00:00
m_builder->cmd(mousebtn::RIGHT, click_right);
2016-11-25 12:55:15 +00:00
}
if (!scroll_up.empty()) {
2016-11-02 19:22:45 +00:00
m_builder->cmd(mousebtn::SCROLL_UP, scroll_up);
2016-11-25 12:55:15 +00:00
}
if (!scroll_down.empty()) {
2016-11-02 19:22:45 +00:00
m_builder->cmd(mousebtn::SCROLL_DOWN, scroll_down);
2016-11-25 12:55:15 +00:00
}
2016-11-02 19:22:45 +00:00
m_builder->append(module::get_output());
2016-11-02 19:22:45 +00:00
return m_builder->flush();
}
}
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END