2018-08-29 20:36:39 +02:00
|
|
|
#include "modules/sni/tray.hpp"
|
2019-05-20 15:21:13 +02:00
|
|
|
#include <spdlog/spdlog.h>
|
2018-08-29 20:36:39 +02:00
|
|
|
|
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-06-15 14:57:52 +02:00
|
|
|
: AModule(config, "tray", id),
|
2019-04-17 14:19:04 +02:00
|
|
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
2020-02-19 12:06:35 +01:00
|
|
|
watcher_(SNI::Watcher::getInstance()),
|
2021-08-17 08:33:29 +02:00
|
|
|
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
2019-04-17 14:19:04 +02:00
|
|
|
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
2019-05-20 15:21:13 +02:00
|
|
|
spdlog::warn(
|
2019-07-15 12:21:31 +02:00
|
|
|
"For a functional tray you must have libappindicator-* installed and export "
|
2019-05-20 15:21:13 +02:00
|
|
|
"XDG_CURRENT_DESKTOP=Unity");
|
2019-06-15 14:57:52 +02:00
|
|
|
box_.set_name("tray");
|
|
|
|
event_box_.add(box_);
|
2019-04-24 12:37:24 +02:00
|
|
|
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) {
|
2022-01-28 19:14:46 +01: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 15:47:23 +01:00
|
|
|
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 {
|
2021-10-02 18:13:17 +02:00
|
|
|
// Show tray only when items are available
|
2021-09-19 17:30:41 +02:00
|
|
|
box_.set_visible(!box_.get_children().empty());
|
2020-04-12 18:35:41 +02:00
|
|
|
// Call parent update
|
|
|
|
AModule::update();
|
2018-08-29 20:36:39 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 15:21:13 +02:00
|
|
|
} // namespace waybar::modules::SNI
|