Merge pull request #823 from W-joe/rfkill_optional

Rfkill optional
pull/824/head
Alex 2020-08-14 21:56:52 +02:00 committed by GitHub
commit 69f5d19455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 5 deletions

View File

@ -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 {

View File

@ -11,7 +11,9 @@
#include <sys/epoll.h>
#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

View File

@ -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(

View File

@ -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')

View File

@ -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]);

View File

@ -4,7 +4,9 @@
#include <fstream>
#include <cassert>
#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";