Merge pull request #4907 from jaypikay/master

hostname dependend module
This commit is contained in:
Alexis Rouillard
2026-07-03 23:12:46 +02:00
committed by GitHub
4 changed files with 32 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include <json/value.h>
namespace waybar::util {
bool valid_host(const Json::Value& config);
} // namespace waybar::util
+1
View File
@@ -182,6 +182,7 @@ src_files = files(
'src/util/ustring_clen.cpp', 'src/util/ustring_clen.cpp',
'src/util/sanitize_str.cpp', 'src/util/sanitize_str.cpp',
'src/util/rewrite_string.cpp', 'src/util/rewrite_string.cpp',
'src/util/hosts_check.cpp',
'src/util/gtk_icon.cpp', 'src/util/gtk_icon.cpp',
'src/util/icon_loader.cpp', 'src/util/icon_loader.cpp',
'src/util/regex_collection.cpp', 'src/util/regex_collection.cpp',
+7
View File
@@ -3,12 +3,14 @@
#include <gtk-layer-shell.h> #include <gtk-layer-shell.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <ostream>
#include <type_traits> #include <type_traits>
#include "client.hpp" #include "client.hpp"
#include "factory.hpp" #include "factory.hpp"
#include "group.hpp" #include "group.hpp"
#include "util/enum.hpp" #include "util/enum.hpp"
#include "util/hosts_check.hpp"
#include "util/kill_signal.hpp" #include "util/kill_signal.hpp"
#ifdef HAVE_SWAY #ifdef HAVE_SWAY
@@ -565,6 +567,11 @@ 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();
if (config[ref].isMember("hosts") && !waybar::util::valid_host(config[ref])) {
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) {
+17
View File
@@ -0,0 +1,17 @@
#include "util/hosts_check.hpp"
#include <glibmm/miscutils.h>
#include <json/config.h>
namespace waybar::util {
bool valid_host(const Json::Value& config) {
if (config.isMember("hosts") && config["hosts"].isArray()) {
const auto hostname = Glib::get_host_name();
if (!std::ranges::any_of(config["hosts"].begin(), config["hosts"].end(),
[&](const auto& h) { return h.asString() == hostname; }))
return false;
}
return true;
}
} // namespace waybar::util