2017-01-01 21:28:28 +01:00
|
|
|
#if DEBUG
|
|
|
|
#include "modules/systray.hpp"
|
2021-01-04 10:25:52 +01:00
|
|
|
|
2017-01-01 21:28:28 +01:00
|
|
|
#include "drawtypes/label.hpp"
|
2021-01-04 10:25:52 +01:00
|
|
|
#include "modules/meta/base.inl"
|
2017-01-01 21:28:28 +01:00
|
|
|
#include "x11/connection.hpp"
|
|
|
|
#include "x11/tray_manager.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
namespace modules {
|
|
|
|
template class module<systray_module>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct module
|
|
|
|
*/
|
|
|
|
systray_module::systray_module(const bar_settings& bar, string name_)
|
|
|
|
: static_module<systray_module>(bar, move(name_)), m_connection(connection::make()) {
|
2021-01-04 10:25:52 +01:00
|
|
|
m_router->register_action(EVENT_TOGGLE, &systray_module::action_toggle);
|
|
|
|
|
2017-01-01 21:28:28 +01:00
|
|
|
// Add formats and elements
|
|
|
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_TOGGLE, {TAG_LABEL_TOGGLE, TAG_TRAY_CLIENTS});
|
|
|
|
|
|
|
|
if (m_formatter->has(TAG_LABEL_TOGGLE)) {
|
|
|
|
m_label = load_label(m_conf, name(), TAG_LABEL_TOGGLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update
|
|
|
|
*/
|
|
|
|
void systray_module::update() {
|
|
|
|
if (m_label) {
|
|
|
|
m_label->reset_tokens();
|
|
|
|
m_label->replace_token("%title%", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcast();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build output
|
|
|
|
*/
|
|
|
|
bool systray_module::build(builder* builder, const string& tag) const {
|
|
|
|
if (tag == TAG_LABEL_TOGGLE) {
|
2020-05-24 00:36:16 +02:00
|
|
|
builder->action(mousebtn::LEFT, *this, EVENT_TOGGLE, "", m_label);
|
2017-01-01 21:28:28 +01:00
|
|
|
} else if (tag == TAG_TRAY_CLIENTS && !m_hidden) {
|
|
|
|
builder->append(TRAY_PLACEHOLDER);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle input event
|
|
|
|
*/
|
2021-01-04 10:25:52 +01:00
|
|
|
void systray_module::action_toggle() {
|
2017-01-01 21:28:28 +01:00
|
|
|
m_hidden = !m_hidden;
|
|
|
|
broadcast();
|
|
|
|
}
|
2021-01-04 10:25:52 +01:00
|
|
|
} // namespace modules
|
2017-01-01 21:28:28 +01:00
|
|
|
|
|
|
|
POLYBAR_NS_END
|
|
|
|
#endif
|