From fdfb60c633681908e81337ce793350588add2478 Mon Sep 17 00:00:00 2001 From: wjoe Date: Fri, 14 Aug 2020 20:56:45 +0200 Subject: [PATCH 1/3] meson feature: make rfkill optional --- meson.build | 12 ++++++++++-- meson_options.txt | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 56b45be8..16da9575 100644 --- a/meson.build +++ b/meson.build @@ -137,12 +137,10 @@ if is_linux add_project_arguments('-DHAVE_MEMORY_LINUX', language: 'cpp') src_files += files( 'src/modules/battery.cpp', - 'src/modules/bluetooth.cpp', 'src/modules/cpu/common.cpp', 'src/modules/cpu/linux.cpp', 'src/modules/memory/common.cpp', 'src/modules/memory/linux.cpp', - 'src/util/rfkill.cpp' ) elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd add_project_arguments('-DHAVE_CPU_BSD', language: 'cpp') @@ -207,6 +205,16 @@ if gtk_layer_shell.found() add_project_arguments('-DHAVE_GTK_LAYER_SHELL', language: 'cpp') endif +if get_option('rfkill').enabled() + if is_linux + add_project_arguments('-DWANT_RFKILL', language: 'cpp') + src_files += files( + 'src/modules/bluetooth.cpp', + 'src/util/rfkill.cpp' + ) + endif +endif + subdir('protocol') executable( diff --git a/meson_options.txt b/meson_options.txt index a44ff648..de47da74 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,3 +7,4 @@ option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable supp option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') option('mpd', type: 'feature', value: 'auto', description: 'Enable support for the Music Player Daemon') option('gtk-layer-shell', type: 'feature', value: 'auto', description: 'Use gtk-layer-shell library for popups support') +option('rfkill', type: 'feature', value: 'auto', description: 'Enable support for RFKILL') From 4565f7f8b9ade0e43057cbd47b3f14b218fd589e Mon Sep 17 00:00:00 2001 From: wjoe Date: Fri, 14 Aug 2020 20:58:48 +0200 Subject: [PATCH 2/3] 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"; From 4d775008df1cabaa6a9cfd56dfb75fa5d83d54b1 Mon Sep 17 00:00:00 2001 From: wjoe Date: Fri, 14 Aug 2020 20:59:30 +0200 Subject: [PATCH 3/3] only return a bluetooth module from factory if the rfkill feature is enabled. --- include/factory.hpp | 4 +++- src/factory.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/factory.hpp b/include/factory.hpp index fcbf3a2d..ebc2359f 100644 --- a/include/factory.hpp +++ b/include/factory.hpp @@ -43,7 +43,9 @@ #include "modules/custom.hpp" #include "modules/temperature.hpp" #if defined(__linux__) -#include "modules/bluetooth.hpp" +# ifdef WANT_RFKILL +# include "modules/bluetooth.hpp" +# endif #endif namespace waybar { diff --git a/src/factory.cpp b/src/factory.cpp index 5a01d523..af93b20f 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -81,9 +81,11 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const { return new waybar::modules::Temperature(id, config_[name]); } #if defined(__linux__) +# ifdef WANT_RFKILL if (ref == "bluetooth") { return new waybar::modules::Bluetooth(id, config_[name]); } +# endif #endif if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) { return new waybar::modules::Custom(ref.substr(7), id, config_[name]);