Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): signal strength in dBm #5

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/modules/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ namespace waybar::modules {
double frequency;
} wireless_info_t;
private:
void _parseEssid(struct nlattr** bss);
void _parseEssid(struct nlattr **bss);
void _parseSignal(struct nlattr **bss);
bool _associatedOrJoined(struct nlattr **bss);
static int _scanCb(struct nl_msg *msg, void *data);
auto _getInfo() -> void;
Expand All @@ -44,6 +45,7 @@ namespace waybar::modules {
Json::Value _config;
std::size_t _ifid;
std::string _essid;
int _signalStrength;
};

}
2 changes: 1 addition & 1 deletion resources/config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"network": {
"interface": "wlp2s0",
"format": "{} "
"format": "{essid} ({signalStrength}dBm) "
}
}
16 changes: 14 additions & 2 deletions src/modules/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ auto waybar::modules::Network::update() -> void
{
_getInfo();
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) {
Expand Down Expand Up @@ -44,7 +47,8 @@ int waybar::modules::Network::_scanCb(struct nl_msg *msg, void *data) {
if (!net->_associatedOrJoined(bss))
return NL_SKIP;
net->_parseEssid(bss);
// TODO: parse signal
net->_parseSignal(bss);
// TODO: parse quality
return NL_SKIP;
}

Expand All @@ -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)
{
if (!bss[NL80211_BSS_STATUS])
Expand Down
2 changes: 1 addition & 1 deletion src/modules/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void waybar::modules::Workspaces::_updateThread()
{
_thread = new waybar::util::SleeperThread([this] {
update();
_thread->sleep_for(waybar::chrono::milliseconds(250));
_thread->sleep_for(waybar::chrono::milliseconds(150));
});
}

Expand Down