2018-08-29 20:36:39 +02:00
|
|
|
#include "modules/sni/tray.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
|
2019-04-24 12:37:24 +02:00
|
|
|
namespace waybar::modules::SNI {
|
|
|
|
|
|
|
|
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
2019-03-22 12:25:05 +01:00
|
|
|
: config_(config),
|
2019-04-17 14:19:04 +02:00
|
|
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
|
|
|
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
|
|
|
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
2019-04-24 12:37:24 +02:00
|
|
|
box_.set_name("tray");
|
|
|
|
if (!id.empty()) {
|
|
|
|
box_.get_style_context()->add_class(id);
|
|
|
|
}
|
2018-10-26 12:08:50 +02:00
|
|
|
if (config_["spacing"].isUInt()) {
|
|
|
|
box_.set_spacing(config_["spacing"].asUInt());
|
|
|
|
}
|
2018-12-01 00:10:41 +01:00
|
|
|
nb_hosts_ += 1;
|
2019-04-24 12:37:24 +02:00
|
|
|
dp.emit();
|
2018-10-26 12:08:50 +02:00
|
|
|
}
|
2018-08-29 20:36:39 +02:00
|
|
|
|
2019-04-24 12:37:24 +02:00
|
|
|
void Tray::onAdd(std::unique_ptr<Item>& item) {
|
2018-11-22 15:47:23 +01:00
|
|
|
box_.pack_start(item->event_box);
|
|
|
|
dp.emit();
|
|
|
|
}
|
|
|
|
|
2019-04-24 12:37:24 +02:00
|
|
|
void Tray::onRemove(std::unique_ptr<Item>& item) {
|
2018-11-22 15:47:23 +01:00
|
|
|
box_.remove(item->event_box);
|
|
|
|
dp.emit();
|
|
|
|
}
|
|
|
|
|
2019-04-24 12:37:24 +02:00
|
|
|
auto Tray::update() -> void {
|
|
|
|
if (box_.get_children().empty()) {
|
|
|
|
box_.hide();
|
2018-08-29 20:36:39 +02:00
|
|
|
} else {
|
2019-04-24 12:37:24 +02:00
|
|
|
box_.show_all();
|
2018-08-29 20:36:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 12:37:24 +02:00
|
|
|
Tray::operator Gtk::Widget&() { return box_; }
|
|
|
|
|
|
|
|
}
|