Added support for hostname based module addition
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <json/value.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace waybar::util {
|
||||||
|
bool valid_host(const Json::Value& config);
|
||||||
|
} // namespace waybar::util
|
||||||
@@ -181,6 +181,7 @@ src_files = files(
|
|||||||
'src/util/prepare_for_sleep.cpp',
|
'src/util/prepare_for_sleep.cpp',
|
||||||
'src/util/ustring_clen.cpp',
|
'src/util/ustring_clen.cpp',
|
||||||
'src/util/sanitize_str.cpp',
|
'src/util/sanitize_str.cpp',
|
||||||
|
'src/util/hosts_check.cpp',
|
||||||
'src/util/rewrite_string.cpp',
|
'src/util/rewrite_string.cpp',
|
||||||
'src/util/gtk_icon.cpp',
|
'src/util/gtk_icon.cpp',
|
||||||
'src/util/icon_loader.cpp',
|
'src/util/icon_loader.cpp',
|
||||||
|
|||||||
+14
@@ -10,6 +10,7 @@
|
|||||||
#include "group.hpp"
|
#include "group.hpp"
|
||||||
#include "util/enum.hpp"
|
#include "util/enum.hpp"
|
||||||
#include "util/kill_signal.hpp"
|
#include "util/kill_signal.hpp"
|
||||||
|
#include "util/hosts_check.hpp"
|
||||||
|
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
#include "modules/sway/bar.hpp"
|
#include "modules/sway/bar.hpp"
|
||||||
@@ -531,6 +532,19 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
|||||||
for (const auto& name : module_list) {
|
for (const auto& name : module_list) {
|
||||||
try {
|
try {
|
||||||
auto ref = name.asString();
|
auto ref = name.asString();
|
||||||
|
const Json::Value* module_config = nullptr;
|
||||||
|
if (config.isMember(ref)) {
|
||||||
|
module_config = &config[ref];
|
||||||
|
} else {
|
||||||
|
auto hash_pos = ref.find('#');
|
||||||
|
if (hash_pos != std::string::npos) {
|
||||||
|
std::string ref_base = ref.substr(0, hash_pos);
|
||||||
|
if (config.isMember(ref_base)) {
|
||||||
|
module_config = &config[ref_base];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (module_config && !waybar::util::valid_host(*module_config)) continue;
|
||||||
AModule* module;
|
AModule* module;
|
||||||
|
|
||||||
if (ref.compare(0, 6, "group/") == 0 && ref.size() > 6) {
|
if (ref.compare(0, 6, "group/") == 0 && ref.size() > 6) {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include <glibmm/miscutils.h>
|
||||||
|
|
||||||
|
#include "util/hosts_check.hpp"
|
||||||
|
|
||||||
|
namespace waybar::util {
|
||||||
|
// replaces ``<>&"'`` with their encoded counterparts
|
||||||
|
bool valid_host(const Json::Value& config) {
|
||||||
|
if (config.isMember("hosts") && config["hosts"].isArray()) {
|
||||||
|
auto hostname = Glib::get_host_name();
|
||||||
|
for (const auto& host : config["hosts"]) {
|
||||||
|
if (host.asString() == hostname) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // namespace waybar::util
|
||||||
Reference in New Issue
Block a user