feat: multiple config per modules
This commit is contained in:
parent
1ea0c1f9dd
commit
7f1f217d84
|
@ -6,7 +6,7 @@
|
|||
// Choose the order of the modules
|
||||
"modules-left": ["sway/workspaces", "custom/spotify"],
|
||||
"modules-center": ["sway/window"],
|
||||
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock", "tray"],
|
||||
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "battery#bat2", "clock", "tray"],
|
||||
// Modules configuration
|
||||
// "sway/workspaces": {
|
||||
// "disable-scroll": true,
|
||||
|
@ -39,6 +39,9 @@
|
|||
"format": "{capacity}% {icon}",
|
||||
"format-icons": ["", "", "", "", ""]
|
||||
},
|
||||
"battery#bat2": {
|
||||
"bat": "BAT2"
|
||||
},
|
||||
"network": {
|
||||
// "interface": "wlp2s0", // (Optional) To force the use of this interface
|
||||
"format-wifi": "{essid} ({signalStrength}%) ",
|
||||
|
|
|
@ -7,43 +7,44 @@ waybar::Factory::Factory(Bar& bar, const Json::Value& config)
|
|||
waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
||||
{
|
||||
try {
|
||||
if (name == "battery") {
|
||||
auto ref = name.substr(0, name.find("#"));
|
||||
if (ref == "battery") {
|
||||
return new waybar::modules::Battery(config_[name]);
|
||||
}
|
||||
#ifdef HAVE_SWAY
|
||||
if (name == "sway/workspaces") {
|
||||
if (ref == "sway/workspaces") {
|
||||
return new waybar::modules::sway::Workspaces(bar_, config_[name]);
|
||||
}
|
||||
if (name == "sway/window") {
|
||||
if (ref == "sway/window") {
|
||||
return new waybar::modules::sway::Window(bar_, config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (name == "memory") {
|
||||
if (ref == "memory") {
|
||||
return new waybar::modules::Memory(config_[name]);
|
||||
}
|
||||
if (name == "cpu") {
|
||||
if (ref == "cpu") {
|
||||
return new waybar::modules::Cpu(config_[name]);
|
||||
}
|
||||
if (name == "clock") {
|
||||
if (ref == "clock") {
|
||||
return new waybar::modules::Clock(config_[name]);
|
||||
}
|
||||
#ifdef HAVE_DBUSMENU
|
||||
if (name == "tray") {
|
||||
if (ref == "tray") {
|
||||
return new waybar::modules::SNI::Tray(config_[name]);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LIBNL
|
||||
if (name == "network") {
|
||||
if (ref == "network") {
|
||||
return new waybar::modules::Network(config_[name]);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LIBPULSE
|
||||
if (name == "pulseaudio") {
|
||||
if (ref == "pulseaudio") {
|
||||
return new waybar::modules::Pulseaudio(config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (name.compare(0, 7, "custom/") == 0 && name.size() > 7) {
|
||||
return new waybar::modules::Custom(name.substr(7), config_[name]);
|
||||
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
|
||||
return new waybar::modules::Custom(ref.substr(7), config_[name]);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
|
||||
|
|
|
@ -4,16 +4,27 @@ waybar::modules::Battery::Battery(const Json::Value& config)
|
|||
: ALabel(config, "{capacity}%")
|
||||
{
|
||||
try {
|
||||
for (auto const& node : fs::directory_iterator(data_dir_)) {
|
||||
if (fs::is_directory(node) && fs::exists(node / "capacity")
|
||||
&& fs::exists(node / "status") && fs::exists(node / "uevent")) {
|
||||
batteries_.push_back(node);
|
||||
if (config_["bat"]) {
|
||||
auto dir = data_dir_ / config_["bat"].asString();
|
||||
if (fs::is_directory(dir) && fs::exists(dir / "capacity")
|
||||
&& fs::exists(dir / "status") && fs::exists(dir / "uevent")) {
|
||||
batteries_.push_back(dir);
|
||||
}
|
||||
} else {
|
||||
for (auto const& node : fs::directory_iterator(data_dir_)) {
|
||||
if (fs::is_directory(node) && fs::exists(node / "capacity")
|
||||
&& fs::exists(node / "status") && fs::exists(node / "uevent")) {
|
||||
batteries_.push_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (fs::filesystem_error &e) {
|
||||
throw std::runtime_error(e.what());
|
||||
}
|
||||
if (batteries_.empty()) {
|
||||
if (config_["bat"]) {
|
||||
throw std::runtime_error("No battery named " + config_["bat"].asString());
|
||||
}
|
||||
throw std::runtime_error("No batteries.");
|
||||
}
|
||||
fd_ = inotify_init1(IN_CLOEXEC);
|
||||
|
|
Loading…
Reference in New Issue