feat(Network): frequency

This commit is contained in:
Alex 2019-05-17 11:27:38 +02:00
parent 17291dffdf
commit cb2d6e1997
2 changed files with 14 additions and 2 deletions

View File

@ -36,6 +36,7 @@ class Network : public ALabel {
int netlinkResponse(void*, uint32_t, uint32_t groups = 0);
void parseEssid(struct nlattr**);
void parseSignal(struct nlattr**);
void parseFreq(struct nlattr**);
bool associatedOrJoined(struct nlattr**);
bool checkInterface(int if_index, std::string name);
int getPreferredIface();
@ -63,6 +64,7 @@ class Network : public ALabel {
bool linked_;
int32_t signal_strength_dbm_;
uint8_t signal_strength_;
uint32_t frequency_;
};
} // namespace waybar::modules

View File

@ -10,7 +10,8 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
ev_fd_(-1),
cidr_(-1),
signal_strength_dbm_(0),
signal_strength_(0) {
signal_strength_(0),
frequency_(0) {
label_.set_name("network");
if (!id.empty()) {
label_.get_style_context()->add_class(id);
@ -184,6 +185,7 @@ auto waybar::modules::Network::update() -> void {
fmt::arg("netmask", netmask_),
fmt::arg("ipaddr", ipaddr_),
fmt::arg("cidr", cidr_),
fmt::arg("frequency", frequency_),
fmt::arg("icon", getIcon(signal_strength_, connectiontype)));
label_.set_markup(text);
if (tooltipEnabled()) {
@ -196,6 +198,7 @@ auto waybar::modules::Network::update() -> void {
fmt::arg("netmask", netmask_),
fmt::arg("ipaddr", ipaddr_),
fmt::arg("cidr", cidr_),
fmt::arg("frequency", frequency_),
fmt::arg("icon", getIcon(signal_strength_, connectiontype)));
label_.set_tooltip_text(tooltip_text);
} else {
@ -536,7 +539,7 @@ int waybar::modules::Network::handleScan(struct nl_msg *msg, void *data) {
}
net->parseEssid(bss);
net->parseSignal(bss);
// TODO(someone): parse quality
net->parseFreq(bss);
return NL_SKIP;
}
@ -576,6 +579,13 @@ void waybar::modules::Network::parseSignal(struct nlattr **bss) {
}
}
void waybar::modules::Network::parseFreq(struct nlattr **bss) {
if (bss[NL80211_BSS_FREQUENCY] != nullptr) {
// in MHz
frequency_ = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
}
}
bool waybar::modules::Network::associatedOrJoined(struct nlattr **bss) {
if (bss[NL80211_BSS_STATUS] == nullptr) {
return false;