2022-04-15 21:50:04 +00:00
|
|
|
#include "modules/tray.hpp"
|
|
|
|
|
|
|
|
#include "modules/meta/base.inl"
|
2022-08-28 13:15:48 +00:00
|
|
|
#include "x11/background_manager.hpp"
|
2022-04-15 21:50:04 +00:00
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
namespace modules {
|
|
|
|
template class module<tray_module>;
|
|
|
|
|
2023-05-01 12:58:52 +00:00
|
|
|
tray_module::tray_module(const bar_settings& bar_settings, string name_, const config& config)
|
2023-11-11 02:36:02 +00:00
|
|
|
: static_module<tray_module>(bar_settings, std::move(name_), config)
|
2022-09-03 19:33:22 +00:00
|
|
|
, m_tray(connection::make(), signal_emitter::make(), m_log, bar_settings, [&] { this->broadcast(); }) {
|
2022-04-15 21:50:04 +00:00
|
|
|
m_formatter->add(DEFAULT_FORMAT, TAG_TRAY, {TAG_TRAY});
|
2023-11-11 02:36:02 +00:00
|
|
|
|
|
|
|
/* There are a bunch of edge cases with regards to tray visiblity when the
|
|
|
|
* <tray> tag is not there (in that case the tray icons should under no
|
|
|
|
* circumnstances appear). To avoid this, we simply disallow the situation.
|
|
|
|
* The module is basically useless without that tag anyway.
|
|
|
|
*/
|
|
|
|
if (!m_formatter->has(TAG_TRAY, DEFAULT_FORMAT)) {
|
|
|
|
throw module_error("The " + std::string(TAG_TRAY) + " tag is required in " + name() + "." + DEFAULT_FORMAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise the tray does not see the initial module visibility
|
|
|
|
m_tray.change_visibility(visible());
|
2022-04-15 21:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string tray_module::get_format() const {
|
|
|
|
return DEFAULT_FORMAT;
|
|
|
|
}
|
|
|
|
|
2023-11-11 02:36:02 +00:00
|
|
|
void tray_module::set_visible(bool value) {
|
|
|
|
m_tray.change_visibility(value);
|
|
|
|
static_module<tray_module>::set_visible(value);
|
|
|
|
}
|
|
|
|
|
2022-08-28 13:15:48 +00:00
|
|
|
void tray_module::start() {
|
2022-09-03 18:56:32 +00:00
|
|
|
m_tray.setup(m_conf, name());
|
2022-08-28 13:15:48 +00:00
|
|
|
this->static_module<tray_module>::start();
|
|
|
|
}
|
|
|
|
|
2022-04-15 21:50:04 +00:00
|
|
|
bool tray_module::build(builder* builder, const string& tag) const {
|
2023-11-11 02:36:02 +00:00
|
|
|
// Don't produce any output if the tray is empty so that the module can be hidden
|
|
|
|
if (tag == TAG_TRAY && m_tray.get_width() > 0) {
|
2022-04-15 21:50:04 +00:00
|
|
|
builder->control(tags::controltag::t);
|
2022-08-28 13:29:36 +00:00
|
|
|
extent_val offset_extent = {extent_type::PIXEL, static_cast<float>(m_tray.get_width())};
|
2022-04-15 21:50:04 +00:00
|
|
|
builder->offset(offset_extent);
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-11 02:36:02 +00:00
|
|
|
|
2022-04-15 21:50:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-28 13:15:48 +00:00
|
|
|
} // namespace modules
|
2022-04-15 21:50:04 +00:00
|
|
|
POLYBAR_NS_END
|