mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' into on-update
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include "util/format.hpp"
|
||||
|
||||
|
||||
@ -278,8 +279,13 @@ auto waybar::modules::Network::update() -> void {
|
||||
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / interval_.count(), "b/s")),
|
||||
fmt::arg("bandwidthDownOctets", pow_format(bandwidth_down / interval_.count(), "o/s")),
|
||||
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
||||
if (text != label_.get_label()) {
|
||||
if (text.compare(label_.get_label()) != 0) {
|
||||
label_.set_markup(text);
|
||||
if (text.empty()) {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
event_box_.show();
|
||||
}
|
||||
}
|
||||
if (tooltipEnabled()) {
|
||||
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
|
||||
@ -437,7 +443,6 @@ out:
|
||||
}
|
||||
|
||||
void waybar::modules::Network::getInterfaceAddress() {
|
||||
unsigned int cidrRaw;
|
||||
struct ifaddrs *ifaddr, *ifa;
|
||||
cidr_ = 0;
|
||||
int success = getifaddrs(&ifaddr);
|
||||
@ -449,18 +454,34 @@ void waybar::modules::Network::getInterfaceAddress() {
|
||||
if (ifa->ifa_addr != nullptr && ifa->ifa_addr->sa_family == family_ &&
|
||||
ifa->ifa_name == ifname_) {
|
||||
char ipaddr[INET6_ADDRSTRLEN];
|
||||
ipaddr_ = inet_ntop(family_,
|
||||
&reinterpret_cast<struct sockaddr_in *>(ifa->ifa_addr)->sin_addr,
|
||||
ipaddr,
|
||||
INET6_ADDRSTRLEN);
|
||||
char netmask[INET6_ADDRSTRLEN];
|
||||
auto net_addr = reinterpret_cast<struct sockaddr_in *>(ifa->ifa_netmask);
|
||||
netmask_ = inet_ntop(family_, &net_addr->sin_addr, netmask, INET6_ADDRSTRLEN);
|
||||
cidrRaw = net_addr->sin_addr.s_addr;
|
||||
unsigned int cidr = 0;
|
||||
while (cidrRaw) {
|
||||
cidr += cidrRaw & 1;
|
||||
cidrRaw >>= 1;
|
||||
if (family_ == AF_INET) {
|
||||
ipaddr_ = inet_ntop(AF_INET,
|
||||
&reinterpret_cast<struct sockaddr_in *>(ifa->ifa_addr)->sin_addr,
|
||||
ipaddr,
|
||||
INET_ADDRSTRLEN);
|
||||
auto net_addr = reinterpret_cast<struct sockaddr_in *>(ifa->ifa_netmask);
|
||||
netmask_ = inet_ntop(AF_INET, &net_addr->sin_addr, netmask, INET_ADDRSTRLEN);
|
||||
unsigned int cidrRaw = net_addr->sin_addr.s_addr;
|
||||
while (cidrRaw) {
|
||||
cidr += cidrRaw & 1;
|
||||
cidrRaw >>= 1;
|
||||
}
|
||||
} else {
|
||||
ipaddr_ = inet_ntop(AF_INET6,
|
||||
&reinterpret_cast<struct sockaddr_in6 *>(ifa->ifa_addr)->sin6_addr,
|
||||
ipaddr,
|
||||
INET6_ADDRSTRLEN);
|
||||
auto net_addr = reinterpret_cast<struct sockaddr_in6 *>(ifa->ifa_netmask);
|
||||
netmask_ = inet_ntop(AF_INET6, &net_addr->sin6_addr, netmask, INET6_ADDRSTRLEN);
|
||||
for (size_t i = 0; i < sizeof(net_addr->sin6_addr.s6_addr); ++i) {
|
||||
unsigned char cidrRaw = net_addr->sin6_addr.s6_addr[i];
|
||||
while (cidrRaw) {
|
||||
cidr += cidrRaw & 1;
|
||||
cidrRaw >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
cidr_ = cidr;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user