Merge pull request #5 from Alexays/signalDbm
feat(network): signal strength in dBm
This commit is contained in:
commit
11fab436b9
|
@ -35,7 +35,8 @@ namespace waybar::modules {
|
||||||
double frequency;
|
double frequency;
|
||||||
} wireless_info_t;
|
} wireless_info_t;
|
||||||
private:
|
private:
|
||||||
void _parseEssid(struct nlattr** bss);
|
void _parseEssid(struct nlattr **bss);
|
||||||
|
void _parseSignal(struct nlattr **bss);
|
||||||
bool _associatedOrJoined(struct nlattr **bss);
|
bool _associatedOrJoined(struct nlattr **bss);
|
||||||
static int _scanCb(struct nl_msg *msg, void *data);
|
static int _scanCb(struct nl_msg *msg, void *data);
|
||||||
auto _getInfo() -> void;
|
auto _getInfo() -> void;
|
||||||
|
@ -44,6 +45,7 @@ namespace waybar::modules {
|
||||||
Json::Value _config;
|
Json::Value _config;
|
||||||
std::size_t _ifid;
|
std::size_t _ifid;
|
||||||
std::string _essid;
|
std::string _essid;
|
||||||
|
int _signalStrength;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,6 @@
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"interface": "wlp2s0",
|
"interface": "wlp2s0",
|
||||||
"format": "{} "
|
"format": "{essid} ({signalStrength}dBm) "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,10 @@ auto waybar::modules::Network::update() -> void
|
||||||
{
|
{
|
||||||
_getInfo();
|
_getInfo();
|
||||||
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
||||||
_label.set_text(fmt::format(format, _essid));
|
_label.set_text(fmt::format(format,
|
||||||
|
fmt::arg("essid", _essid),
|
||||||
|
fmt::arg("signalStrength", _signalStrength)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
int waybar::modules::Network::_scanCb(struct nl_msg *msg, void *data) {
|
int waybar::modules::Network::_scanCb(struct nl_msg *msg, void *data) {
|
||||||
|
@ -44,7 +47,8 @@ int waybar::modules::Network::_scanCb(struct nl_msg *msg, void *data) {
|
||||||
if (!net->_associatedOrJoined(bss))
|
if (!net->_associatedOrJoined(bss))
|
||||||
return NL_SKIP;
|
return NL_SKIP;
|
||||||
net->_parseEssid(bss);
|
net->_parseEssid(bss);
|
||||||
// TODO: parse signal
|
net->_parseSignal(bss);
|
||||||
|
// TODO: parse quality
|
||||||
return NL_SKIP;
|
return NL_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +74,14 @@ void waybar::modules::Network::_parseEssid(struct nlattr **bss)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waybar::modules::Network::_parseSignal(struct nlattr **bss) {
|
||||||
|
if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) {
|
||||||
|
// signalstrength in dBm
|
||||||
|
_signalStrength =
|
||||||
|
static_cast<int>(nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM])) / 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool waybar::modules::Network::_associatedOrJoined(struct nlattr** bss)
|
bool waybar::modules::Network::_associatedOrJoined(struct nlattr** bss)
|
||||||
{
|
{
|
||||||
if (!bss[NL80211_BSS_STATUS])
|
if (!bss[NL80211_BSS_STATUS])
|
||||||
|
|
|
@ -59,7 +59,7 @@ void waybar::modules::Workspaces::_updateThread()
|
||||||
{
|
{
|
||||||
_thread = new waybar::util::SleeperThread([this] {
|
_thread = new waybar::util::SleeperThread([this] {
|
||||||
update();
|
update();
|
||||||
_thread->sleep_for(waybar::chrono::milliseconds(250));
|
_thread->sleep_for(waybar::chrono::milliseconds(150));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue