only compile rfkill into the network module if the feature is enabled.

pull/823/head
wjoe 2020-08-14 20:58:48 +02:00
parent fdfb60c633
commit 4565f7f8b9
2 changed files with 16 additions and 2 deletions

View File

@ -11,7 +11,9 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#include "ALabel.hpp" #include "ALabel.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
#ifdef WANT_RFKILL
#include "util/rfkill.hpp" #include "util/rfkill.hpp"
#endif
namespace waybar::modules { namespace waybar::modules {
@ -70,9 +72,11 @@ class Network : public ALabel {
util::SleeperThread thread_; util::SleeperThread thread_;
util::SleeperThread thread_timer_; util::SleeperThread thread_timer_;
#ifdef WANT_RFKILL
util::SleeperThread thread_rfkill_; util::SleeperThread thread_rfkill_;
util::Rfkill rfkill_; util::Rfkill rfkill_;
#endif
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -4,7 +4,9 @@
#include <fstream> #include <fstream>
#include <cassert> #include <cassert>
#include "util/format.hpp" #include "util/format.hpp"
#ifdef WANT_RFKILL
#include "util/rfkill.hpp" #include "util/rfkill.hpp"
#endif
namespace { namespace {
@ -84,8 +86,10 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
cidr_(-1), cidr_(-1),
signal_strength_dbm_(0), signal_strength_dbm_(0),
signal_strength_(0), signal_strength_(0),
frequency_(0), #ifdef WANT_RFKILL
rfkill_{RFKILL_TYPE_WLAN} { rfkill_{RFKILL_TYPE_WLAN},
#endif
frequency_(0) {
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY); auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY);
if (down_octets) { if (down_octets) {
@ -174,6 +178,7 @@ void waybar::modules::Network::worker() {
} }
thread_timer_.sleep_for(interval_); thread_timer_.sleep_for(interval_);
}; };
#ifdef WANT_RFKILL
thread_rfkill_ = [this] { thread_rfkill_ = [this] {
rfkill_.waitForEvent(); 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 { const std::string waybar::modules::Network::getNetworkState() const {
#ifdef WANT_RFKILL
if (ifid_ == -1) { if (ifid_ == -1) {
if (rfkill_.getState()) if (rfkill_.getState())
return "disabled"; return "disabled";
return "disconnected"; return "disconnected";
} }
#endif
if (ipaddr_.empty()) return "linked"; if (ipaddr_.empty()) return "linked";
if (essid_.empty()) return "ethernet"; if (essid_.empty()) return "ethernet";
return "wifi"; return "wifi";