polybar/src/modules/text.cpp

82 lines
2.1 KiB
C++
Raw Normal View History

2016-11-02 19:22:45 +00:00
#include "modules/text.hpp"
#include "drawtypes/label.hpp"
2016-11-20 22:04:31 +00:00
#include "modules/meta/base.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>;
text_module::text_module(const bar_settings& bar, string name_) : static_module<text_module>(bar, move(name_)) {
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL});
m_formatter->add_optional("content", {});
2016-11-02 19:22:45 +00:00
if (m_formatter->has_format("content")) {
m_conf.warn_deprecated(name(), "content", "format");
if (m_formatter->get("content")->value.empty()) {
throw module_error(name() + ".content is empty or undefined");
}
m_format = "content";
} else {
m_format = DEFAULT_FORMAT;
if (m_formatter->has(TAG_LABEL, DEFAULT_FORMAT)) {
m_label = load_label(m_conf, name(), TAG_LABEL);
}
2016-11-25 12:55:15 +00:00
}
2016-11-02 19:22:45 +00:00
}
string text_module::get_format() const {
return m_format;
2016-11-02 19:22:45 +00:00
}
string text_module::get_output() {
2016-12-05 04:32:10 +00:00
// Get the module output early so that
// the format prefix/suffix also gets wrapper
// with the cmd handlers
string output{module::get_output()};
auto click_left = m_conf.get(name(), "click-left", ""s);
auto click_middle = m_conf.get(name(), "click-middle", ""s);
auto click_right = m_conf.get(name(), "click-right", ""s);
auto scroll_up = m_conf.get(name(), "scroll-up", ""s);
auto scroll_down = m_conf.get(name(), "scroll-down", ""s);
2016-11-02 19:22:45 +00:00
2016-11-25 12:55:15 +00:00
if (!click_left.empty()) {
m_builder->action(mousebtn::LEFT, click_left);
2016-11-25 12:55:15 +00:00
}
if (!click_middle.empty()) {
m_builder->action(mousebtn::MIDDLE, click_middle);
2016-11-25 12:55:15 +00:00
}
if (!click_right.empty()) {
m_builder->action(mousebtn::RIGHT, click_right);
2016-11-25 12:55:15 +00:00
}
if (!scroll_up.empty()) {
m_builder->action(mousebtn::SCROLL_UP, scroll_up);
2016-11-25 12:55:15 +00:00
}
if (!scroll_down.empty()) {
m_builder->action(mousebtn::SCROLL_DOWN, scroll_down);
2016-11-25 12:55:15 +00:00
}
2016-11-02 19:22:45 +00:00
m_builder->node(output);
2016-11-02 19:22:45 +00:00
return m_builder->flush();
}
bool text_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL) {
builder->node(m_label);
} else {
return false;
}
return true;
}
} // namespace modules
2016-11-02 19:22:45 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END