From 5de21f4a078ebc251605b35ab430bb59bb1d356f Mon Sep 17 00:00:00 2001 From: jpk Date: Thu, 5 Mar 2026 09:04:21 +0100 Subject: [PATCH 1/4] Added support for hostname based module addition --- include/util/hosts_check.hpp | 8 ++++++++ meson.build | 1 + src/bar.cpp | 14 ++++++++++++++ src/util/hosts_check.cpp | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 include/util/hosts_check.hpp create mode 100644 src/util/hosts_check.cpp diff --git a/include/util/hosts_check.hpp b/include/util/hosts_check.hpp new file mode 100644 index 00000000..a927f535 --- /dev/null +++ b/include/util/hosts_check.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +namespace waybar::util { +bool valid_host(const Json::Value& config); +} // namespace waybar::util diff --git a/meson.build b/meson.build index db9407eb..fdab7932 100644 --- a/meson.build +++ b/meson.build @@ -181,6 +181,7 @@ src_files = files( 'src/util/prepare_for_sleep.cpp', 'src/util/ustring_clen.cpp', 'src/util/sanitize_str.cpp', + 'src/util/hosts_check.cpp', 'src/util/rewrite_string.cpp', 'src/util/gtk_icon.cpp', 'src/util/icon_loader.cpp', diff --git a/src/bar.cpp b/src/bar.cpp index 6a78707e..6f2f36a6 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -10,6 +10,7 @@ #include "group.hpp" #include "util/enum.hpp" #include "util/kill_signal.hpp" +#include "util/hosts_check.hpp" #ifdef HAVE_SWAY #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) { try { 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; if (ref.compare(0, 6, "group/") == 0 && ref.size() > 6) { diff --git a/src/util/hosts_check.cpp b/src/util/hosts_check.cpp new file mode 100644 index 00000000..27260cd3 --- /dev/null +++ b/src/util/hosts_check.cpp @@ -0,0 +1,19 @@ +#include + +#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 From 49db7adc0c782a59a65ec99212590472ade16587 Mon Sep 17 00:00:00 2001 From: jpk Date: Thu, 5 Mar 2026 12:28:48 +0100 Subject: [PATCH 2/4] Per host checks --- meson.build | 1 + src/bar.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index fdab7932..58b49b34 100644 --- a/meson.build +++ b/meson.build @@ -183,6 +183,7 @@ src_files = files( 'src/util/sanitize_str.cpp', 'src/util/hosts_check.cpp', 'src/util/rewrite_string.cpp', + 'src/util/hosts_check.cpp', 'src/util/gtk_icon.cpp', 'src/util/icon_loader.cpp', 'src/util/regex_collection.cpp', diff --git a/src/bar.cpp b/src/bar.cpp index 6f2f36a6..04ad8362 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -9,6 +9,7 @@ #include "factory.hpp" #include "group.hpp" #include "util/enum.hpp" +#include "util/hosts_check.hpp" #include "util/kill_signal.hpp" #include "util/hosts_check.hpp" @@ -532,6 +533,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, for (const auto& name : module_list) { try { auto ref = name.asString(); + const Json::Value* module_config = nullptr; if (config.isMember(ref)) { module_config = &config[ref]; @@ -544,7 +546,8 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, } } } - if (module_config && !waybar::util::valid_host(*module_config)) continue; + if ((module_config != nullptr) && !waybar::util::valid_host(*module_config)) continue; + AModule* module; if (ref.compare(0, 6, "group/") == 0 && ref.size() > 6) { From 88e1f85341f2a5c26ab963ab0fad0ed44076e859 Mon Sep 17 00:00:00 2001 From: jpk Date: Thu, 5 Mar 2026 13:29:14 +0100 Subject: [PATCH 3/4] Simplified logic --- include/util/hosts_check.hpp | 1 - src/bar.cpp | 16 +++------------- src/util/hosts_check.cpp | 18 ++++++++---------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/include/util/hosts_check.hpp b/include/util/hosts_check.hpp index a927f535..4179f633 100644 --- a/include/util/hosts_check.hpp +++ b/include/util/hosts_check.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace waybar::util { bool valid_host(const Json::Value& config); diff --git a/src/bar.cpp b/src/bar.cpp index 04ad8362..4b619de2 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include "client.hpp" @@ -11,7 +12,6 @@ #include "util/enum.hpp" #include "util/hosts_check.hpp" #include "util/kill_signal.hpp" -#include "util/hosts_check.hpp" #ifdef HAVE_SWAY #include "modules/sway/bar.hpp" @@ -534,19 +534,9 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, try { 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 (config[ref].isMember("hosts") && !waybar::util::valid_host(config[ref])) { + continue; } - if ((module_config != nullptr) && !waybar::util::valid_host(*module_config)) continue; AModule* module; diff --git a/src/util/hosts_check.cpp b/src/util/hosts_check.cpp index 27260cd3..1769dd78 100644 --- a/src/util/hosts_check.cpp +++ b/src/util/hosts_check.cpp @@ -1,18 +1,16 @@ -#include - #include "util/hosts_check.hpp" +#include +#include + 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; + 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; } From 78bd6c8b87cd5c6bd987d1fa7563be48bfbc2b7a Mon Sep 17 00:00:00 2001 From: jpk Date: Thu, 5 Mar 2026 14:15:29 +0100 Subject: [PATCH 4/4] Remove duplicate from source include --- meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/meson.build b/meson.build index 58b49b34..9f533aa8 100644 --- a/meson.build +++ b/meson.build @@ -181,7 +181,6 @@ src_files = files( 'src/util/prepare_for_sleep.cpp', 'src/util/ustring_clen.cpp', 'src/util/sanitize_str.cpp', - 'src/util/hosts_check.cpp', 'src/util/rewrite_string.cpp', 'src/util/hosts_check.cpp', 'src/util/gtk_icon.cpp',