2018-08-29 18:36:39 +00:00
|
|
|
#include "modules/sni/tray.hpp"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2019-03-22 11:25:05 +00:00
|
|
|
waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar,
|
|
|
|
const Json::Value &config)
|
|
|
|
: config_(config),
|
|
|
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
|
|
|
watcher_(), host_(nb_hosts_, config,
|
2018-11-22 14:47:23 +00:00
|
|
|
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
|
|
|
std::bind(&Tray::onRemove, this, std::placeholders::_1))
|
2018-10-26 10:08:50 +00:00
|
|
|
{
|
2018-10-28 07:43:48 +00:00
|
|
|
std::cout << "Tray is in beta, so there may be bugs or even be unusable." << std::endl;
|
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;
|
2018-10-26 10:08:50 +00:00
|
|
|
}
|
2018-08-29 18:36:39 +00:00
|
|
|
|
2018-11-22 14:47:23 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-10-04 16:03:01 +00:00
|
|
|
auto waybar::modules::SNI::Tray::update() -> void {
|
2018-08-29 18:36:39 +00:00
|
|
|
if (box_.get_children().size() > 0) {
|
|
|
|
box_.set_name("tray");
|
|
|
|
box_.show_all();
|
|
|
|
} else {
|
|
|
|
box_.set_name("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 12:53:39 +00:00
|
|
|
waybar::modules::SNI::Tray::operator Gtk::Widget &() {
|
|
|
|
return box_;
|
|
|
|
}
|