From 4565f7f8b9ade0e43057cbd47b3f14b218fd589e Mon Sep 17 00:00:00 2001 From: wjoe Date: Fri, 14 Aug 2020 20:58:48 +0200 Subject: [PATCH] only compile rfkill into the network module if the feature is enabled. --- include/modules/network.hpp | 4 ++++ src/modules/network.cpp | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/modules/network.hpp b/include/modules/network.hpp index a0156fbc..4441dc07 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -11,7 +11,9 @@ #include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" +#ifdef WANT_RFKILL #include "util/rfkill.hpp" +#endif namespace waybar::modules { @@ -70,9 +72,11 @@ class Network : public ALabel { util::SleeperThread thread_; util::SleeperThread thread_timer_; +#ifdef WANT_RFKILL util::SleeperThread thread_rfkill_; util::Rfkill rfkill_; +#endif }; } // namespace waybar::modules diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 2c0562f4..4e96cef0 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -4,7 +4,9 @@ #include #include #include "util/format.hpp" +#ifdef WANT_RFKILL #include "util/rfkill.hpp" +#endif namespace { @@ -84,8 +86,10 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf cidr_(-1), signal_strength_dbm_(0), signal_strength_(0), - frequency_(0), - rfkill_{RFKILL_TYPE_WLAN} { +#ifdef WANT_RFKILL + rfkill_{RFKILL_TYPE_WLAN}, +#endif + frequency_(0) { auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY); if (down_octets) { @@ -174,6 +178,7 @@ void waybar::modules::Network::worker() { } thread_timer_.sleep_for(interval_); }; +#ifdef WANT_RFKILL thread_rfkill_ = [this] { rfkill_.waitForEvent(); { @@ -184,14 +189,19 @@ void waybar::modules::Network::worker() { } } }; +#else + spdlog::warn("Waybar has been built without rfkill support."); +#endif } const std::string waybar::modules::Network::getNetworkState() const { +#ifdef WANT_RFKILL if (ifid_ == -1) { if (rfkill_.getState()) return "disabled"; return "disconnected"; } +#endif if (ipaddr_.empty()) return "linked"; if (essid_.empty()) return "ethernet"; return "wifi";