Waybar/src/group.cpp

43 lines
1.2 KiB
C++

#include "group.hpp"
#include <fmt/format.h>
#include <util/command.hpp>
namespace waybar {
Group::Group(const std::string& name, const std::string& id, const Json::Value& config,
bool vertical)
: AModule(config, name, id, false, false),
box{vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0} {
box.set_name(name_);
if (!id.empty()) {
box.get_style_context()->add_class(id);
}
// default orientation: orthogonal to parent
auto orientation =
config_["orientation"].empty() ? "orthogonal" : config_["orientation"].asString();
if (orientation == "inherit") {
// keep orientation passed
} else if (orientation == "orthogonal") {
box.set_orientation(vertical ? Gtk::ORIENTATION_HORIZONTAL : Gtk::ORIENTATION_VERTICAL);
} else if (orientation == "vertical") {
box.set_orientation(Gtk::ORIENTATION_VERTICAL);
} else if (orientation == "horizontal") {
box.set_orientation(Gtk::ORIENTATION_HORIZONTAL);
} else {
throw std::runtime_error("Invalid orientation value: " + orientation);
}
}
auto Group::update() -> void {
// noop
}
Gtk::Box& Group::getBox() { return box; }
Group::operator Gtk::Widget&() { return getBox(); }
} // namespace waybar