Waybar/src/modules/sni/tray.cpp

47 lines
1.3 KiB
C++
Raw Normal View History

#include "modules/sni/tray.hpp"
2022-04-06 06:37:19 +00:00
#include <spdlog/spdlog.h>
2019-04-24 10:37:24 +00:00
namespace waybar::modules::SNI {
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
2019-06-15 12:57:52 +00:00
: AModule(config, "tray", id),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
watcher_(SNI::Watcher::getInstance()),
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
2019-06-15 12:57:52 +00:00
box_.set_name("tray");
event_box_.add(box_);
2019-04-24 10:37:24 +00:00
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
2018-10-26 10:08:50 +00:00
if (config_["spacing"].isUInt()) {
box_.set_spacing(config_["spacing"].asUInt());
}
2018-11-30 23:10:41 +00:00
nb_hosts_ += 1;
2019-04-24 10:37:24 +00:00
dp.emit();
2018-10-26 10:08:50 +00:00
}
2019-04-24 10:37:24 +00:00
void Tray::onAdd(std::unique_ptr<Item>& item) {
2022-01-28 18:14:46 +00:00
if (config_["reverse-direction"].isBool() && config_["reverse-direction"].asBool()) {
box_.pack_end(item->event_box);
} else {
box_.pack_start(item->event_box);
}
2018-11-22 14:47:23 +00:00
dp.emit();
}
2019-04-24 10:37:24 +00:00
void Tray::onRemove(std::unique_ptr<Item>& item) {
2018-11-22 14:47:23 +00:00
box_.remove(item->event_box);
dp.emit();
}
2019-04-24 10:37:24 +00:00
auto Tray::update() -> void {
// Show tray only when items are available
box_.set_visible(!box_.get_children().empty());
2020-04-12 16:35:41 +00:00
// Call parent update
AModule::update();
}
} // namespace waybar::modules::SNI