refactor(tray): cleanup and fixes

This commit is contained in:
Alexis
2018-11-22 15:47:23 +01:00
parent bd62c4cbc5
commit ba79b4d397
14 changed files with 209 additions and 243 deletions

View File

@ -3,7 +3,9 @@
#include <iostream>
waybar::modules::SNI::Tray::Tray(const Json::Value &config)
: config_(config), watcher_(), host_(&dp, config)
: config_(config), watcher_(), host_(config,
std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1))
{
std::cout << "Tray is in beta, so there may be bugs or even be unusable." << std::endl;
if (config_["spacing"].isUInt()) {
@ -11,12 +13,19 @@ waybar::modules::SNI::Tray::Tray(const Json::Value &config)
}
}
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item)
{
box_.pack_start(item->event_box);
dp.emit();
}
void waybar::modules::SNI::Tray::onRemove(std::unique_ptr<Item>& item)
{
box_.remove(item->event_box);
dp.emit();
}
auto waybar::modules::SNI::Tray::update() -> void {
auto childrens = box_.get_children();
// childrens.erase(childrens.begin(), childrens.end());
for (auto &item : host_.items) {
box_.pack_start(*item.event_box);
}
if (box_.get_children().size() > 0) {
box_.set_name("tray");
box_.show_all();