mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(Bar): handle widget size changes
This commit is contained in:
@ -1,36 +1,42 @@
|
||||
#include "modules/sni/tray.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
namespace 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, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
||||
box_.set_name("tray");
|
||||
if (!id.empty()) {
|
||||
box_.get_style_context()->add_class(id);
|
||||
}
|
||||
if (config_["spacing"].isUInt()) {
|
||||
box_.set_spacing(config_["spacing"].asUInt());
|
||||
}
|
||||
nb_hosts_ += 1;
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item) {
|
||||
void 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) {
|
||||
void Tray::onRemove(std::unique_ptr<Item>& item) {
|
||||
box_.remove(item->event_box);
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
auto waybar::modules::SNI::Tray::update() -> void {
|
||||
if (box_.get_children().size() > 0) {
|
||||
box_.set_name("tray");
|
||||
box_.show_all();
|
||||
auto Tray::update() -> void {
|
||||
if (box_.get_children().empty()) {
|
||||
box_.hide();
|
||||
} else {
|
||||
box_.set_name("");
|
||||
box_.show_all();
|
||||
}
|
||||
}
|
||||
|
||||
waybar::modules::SNI::Tray::operator Gtk::Widget&() { return box_; }
|
||||
Tray::operator Gtk::Widget&() { return box_; }
|
||||
|
||||
}
|
Reference in New Issue
Block a user