mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' into master
This commit is contained in:
commit
93a644eec4
@ -38,7 +38,7 @@ class Network : public ALabel {
|
|||||||
void parseSignal(struct nlattr**);
|
void parseSignal(struct nlattr**);
|
||||||
void parseFreq(struct nlattr**);
|
void parseFreq(struct nlattr**);
|
||||||
bool associatedOrJoined(struct nlattr**);
|
bool associatedOrJoined(struct nlattr**);
|
||||||
bool checkInterface(int if_index, std::string name);
|
bool checkInterface(struct ifinfomsg *rtif, std::string name);
|
||||||
int getPreferredIface();
|
int getPreferredIface();
|
||||||
auto getInfo() -> void;
|
auto getInfo() -> void;
|
||||||
bool wildcardMatch(const std::string& pattern, const std::string& text);
|
bool wildcardMatch(const std::string& pattern, const std::string& text);
|
||||||
|
@ -272,12 +272,15 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
|
|||||||
modules_right_.emplace_back(module);
|
modules_right_.emplace_back(module);
|
||||||
}
|
}
|
||||||
module->dp.connect([module, &name] {
|
module->dp.connect([module, &name] {
|
||||||
|
// Fix https://github.com/Alexays/Waybar/issues/320, proper way?
|
||||||
|
Glib::signal_idle().connect_once([module, &name] {
|
||||||
try {
|
try {
|
||||||
module->update();
|
module->update();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << name.asString() + ": " + e.what() << std::endl;
|
std::cerr << name.asString() + ": " + e.what() << std::endl;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -126,8 +126,6 @@ waybar::modules::Network::~Network() {
|
|||||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_LINK);
|
nl_socket_drop_membership(ev_sock_, RTNLGRP_LINK);
|
||||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV4_IFADDR);
|
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV4_IFADDR);
|
||||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV6_IFADDR);
|
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV6_IFADDR);
|
||||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV4_ROUTE);
|
|
||||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV6_ROUTE);
|
|
||||||
nl_close(ev_sock_);
|
nl_close(ev_sock_);
|
||||||
nl_socket_free(ev_sock_);
|
nl_socket_free(ev_sock_);
|
||||||
}
|
}
|
||||||
@ -148,8 +146,6 @@ void waybar::modules::Network::createInfoSocket() {
|
|||||||
nl_socket_add_membership(ev_sock_, RTNLGRP_LINK);
|
nl_socket_add_membership(ev_sock_, RTNLGRP_LINK);
|
||||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV4_IFADDR);
|
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV4_IFADDR);
|
||||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV6_IFADDR);
|
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV6_IFADDR);
|
||||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV4_ROUTE);
|
|
||||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV6_ROUTE);
|
|
||||||
efd_ = epoll_create1(EPOLL_CLOEXEC);
|
efd_ = epoll_create1(EPOLL_CLOEXEC);
|
||||||
if (efd_ < 0) {
|
if (efd_ < 0) {
|
||||||
throw std::runtime_error("Can't create epoll");
|
throw std::runtime_error("Can't create epoll");
|
||||||
@ -192,10 +188,13 @@ void waybar::modules::Network::createEventSocket() {
|
|||||||
|
|
||||||
void waybar::modules::Network::worker() {
|
void waybar::modules::Network::worker() {
|
||||||
thread_timer_ = [this] {
|
thread_timer_ = [this] {
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
if (ifid_ > 0) {
|
if (ifid_ > 0) {
|
||||||
getInfo();
|
getInfo();
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
thread_timer_.sleep_for(interval_);
|
thread_timer_.sleep_for(interval_);
|
||||||
};
|
};
|
||||||
std::array<struct epoll_event, EPOLL_MAX> events{};
|
std::array<struct epoll_event, EPOLL_MAX> events{};
|
||||||
@ -215,6 +214,9 @@ void waybar::modules::Network::worker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::modules::Network::update() -> void {
|
auto waybar::modules::Network::update() -> void {
|
||||||
|
std::string connectiontype;
|
||||||
|
std::string tooltip_format;
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
|
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
|
||||||
auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY);
|
auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY);
|
||||||
|
|
||||||
@ -229,13 +231,6 @@ auto waybar::modules::Network::update() -> void {
|
|||||||
bandwidth_up = *up_octets - bandwidth_up_total_;
|
bandwidth_up = *up_octets - bandwidth_up_total_;
|
||||||
bandwidth_up_total_ = *up_octets;
|
bandwidth_up_total_ = *up_octets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string connectiontype;
|
|
||||||
std::string tooltip_format = "";
|
|
||||||
if (config_["tooltip-format"].isString()) {
|
|
||||||
tooltip_format = config_["tooltip-format"].asString();
|
|
||||||
}
|
|
||||||
if (ifid_ <= 0 || !linked_) {
|
if (ifid_ <= 0 || !linked_) {
|
||||||
if (config_["format-disconnected"].isString()) {
|
if (config_["format-disconnected"].isString()) {
|
||||||
default_format_ = config_["format-disconnected"].asString();
|
default_format_ = config_["format-disconnected"].asString();
|
||||||
@ -310,8 +305,13 @@ auto waybar::modules::Network::update() -> void {
|
|||||||
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / interval_.count(), "b/s")),
|
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("bandwidthDownOctets", pow_format(bandwidth_down / interval_.count(), "o/s")),
|
||||||
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
||||||
|
if (text != label_.get_label()) {
|
||||||
label_.set_markup(text);
|
label_.set_markup(text);
|
||||||
|
}
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
|
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
|
||||||
|
tooltip_format = config_["tooltip-format"].asString();
|
||||||
|
}
|
||||||
if (!tooltip_format.empty()) {
|
if (!tooltip_format.empty()) {
|
||||||
auto tooltip_text = fmt::format(tooltip_format,
|
auto tooltip_text = fmt::format(tooltip_format,
|
||||||
fmt::arg("essid", essid_),
|
fmt::arg("essid", essid_),
|
||||||
@ -327,7 +327,9 @@ auto waybar::modules::Network::update() -> void {
|
|||||||
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / interval_.count(), "b/s")),
|
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("bandwidthDownOctets", pow_format(bandwidth_down / interval_.count(), "o/s")),
|
||||||
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
||||||
|
if (label_.get_tooltip_text() != text) {
|
||||||
label_.set_tooltip_text(tooltip_text);
|
label_.set_tooltip_text(tooltip_text);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
label_.set_tooltip_text(text);
|
label_.set_tooltip_text(text);
|
||||||
}
|
}
|
||||||
@ -525,7 +527,7 @@ int waybar::modules::Network::netlinkResponse(void *resp, uint32_t resplen, uint
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::modules::Network::checkInterface(int if_index, std::string name) {
|
bool waybar::modules::Network::checkInterface(struct ifinfomsg *rtif, std::string name) {
|
||||||
if (config_["interface"].isString()) {
|
if (config_["interface"].isString()) {
|
||||||
return config_["interface"].asString() == name ||
|
return config_["interface"].asString() == name ||
|
||||||
wildcardMatch(config_["interface"].asString(), name);
|
wildcardMatch(config_["interface"].asString(), name);
|
||||||
@ -533,9 +535,9 @@ bool waybar::modules::Network::checkInterface(int if_index, std::string name) {
|
|||||||
auto external_iface = getExternalInterface();
|
auto external_iface = getExternalInterface();
|
||||||
if (external_iface == -1) {
|
if (external_iface == -1) {
|
||||||
// Try with lastest working external iface
|
// Try with lastest working external iface
|
||||||
return last_ext_iface_ == if_index;
|
return last_ext_iface_ == rtif->ifi_index;
|
||||||
}
|
}
|
||||||
return external_iface == if_index;
|
return external_iface == rtif->ifi_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int waybar::modules::Network::getPreferredIface() {
|
int waybar::modules::Network::getPreferredIface() {
|
||||||
@ -584,23 +586,21 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
char ifname[IF_NAMESIZE];
|
char ifname[IF_NAMESIZE];
|
||||||
if_indextoname(rtif->ifi_index, ifname);
|
if_indextoname(rtif->ifi_index, ifname);
|
||||||
// Auto detected network can also be assigned here
|
// Auto detected network can also be assigned here
|
||||||
if (net->checkInterface(rtif->ifi_index, ifname) && net->ifid_ == -1) {
|
if (net->ifid_ == -1 && net->checkInterface(rtif, ifname)) {
|
||||||
net->linked_ = true;
|
net->linked_ = true;
|
||||||
net->ifname_ = ifname;
|
net->ifname_ = ifname;
|
||||||
net->ifid_ = rtif->ifi_index;
|
net->ifid_ = rtif->ifi_index;
|
||||||
net->dp.emit();
|
|
||||||
}
|
}
|
||||||
// Check for valid interface
|
// Check for valid interface
|
||||||
if (rtif->ifi_index == static_cast<int>(net->ifid_)) {
|
if (rtif->ifi_index == net->ifid_) {
|
||||||
// Get Iface and WIFI info
|
// Get Iface and WIFI info
|
||||||
net->thread_timer_.wake_up();
|
|
||||||
net->getInterfaceAddress();
|
net->getInterfaceAddress();
|
||||||
net->dp.emit();
|
net->thread_timer_.wake_up();
|
||||||
}
|
}
|
||||||
} else if (nh->nlmsg_type == RTM_DELADDR) {
|
} else if (nh->nlmsg_type == RTM_DELADDR) {
|
||||||
auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
|
auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
|
||||||
// Check for valid interface
|
// Check for valid interface
|
||||||
if (rtif->ifi_index == static_cast<int>(net->ifid_)) {
|
if (rtif->ifi_index == net->ifid_) {
|
||||||
net->ipaddr_.clear();
|
net->ipaddr_.clear();
|
||||||
net->netmask_.clear();
|
net->netmask_.clear();
|
||||||
net->cidr_ = 0;
|
net->cidr_ = 0;
|
||||||
@ -611,7 +611,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
char ifname[IF_NAMESIZE];
|
char ifname[IF_NAMESIZE];
|
||||||
if_indextoname(rtif->ifi_index, ifname);
|
if_indextoname(rtif->ifi_index, ifname);
|
||||||
// Check for valid interface
|
// Check for valid interface
|
||||||
if (net->checkInterface(rtif->ifi_index, ifname) && rtif->ifi_flags & IFF_RUNNING) {
|
if (rtif->ifi_flags & IFF_RUNNING && net->checkInterface(rtif, ifname)) {
|
||||||
net->linked_ = true;
|
net->linked_ = true;
|
||||||
net->ifname_ = ifname;
|
net->ifname_ = ifname;
|
||||||
net->ifid_ = rtif->ifi_index;
|
net->ifid_ = rtif->ifi_index;
|
||||||
@ -623,15 +623,17 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
net->essid_.clear();
|
net->essid_.clear();
|
||||||
net->signal_strength_dbm_ = 0;
|
net->signal_strength_dbm_ = 0;
|
||||||
net->signal_strength_ = 0;
|
net->signal_strength_ = 0;
|
||||||
|
net->frequency_ = 0;
|
||||||
// Check for a new interface and get info
|
// Check for a new interface and get info
|
||||||
auto new_iface = net->getPreferredIface();
|
auto new_iface = net->getPreferredIface();
|
||||||
if (new_iface != -1) {
|
if (new_iface != -1) {
|
||||||
net->thread_timer_.wake_up();
|
|
||||||
net->getInterfaceAddress();
|
net->getInterfaceAddress();
|
||||||
}
|
net->thread_timer_.wake_up();
|
||||||
|
} else {
|
||||||
net->dp.emit();
|
net->dp.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NL_SKIP;
|
return NL_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||||||
|
|
||||||
const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterator it,
|
const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterator it,
|
||||||
bool prev) const {
|
bool prev) const {
|
||||||
if (prev && it == workspaces_.begin()) {
|
if (prev && it == workspaces_.begin() && !config_["disable-scroll-wraparound"].asBool()) {
|
||||||
return (*(--workspaces_.end()))["name"].asString();
|
return (*(--workspaces_.end()))["name"].asString();
|
||||||
}
|
}
|
||||||
if (prev && it != workspaces_.begin())
|
if (prev && it != workspaces_.begin())
|
||||||
@ -223,8 +223,12 @@ const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterat
|
|||||||
else if (!prev && it != workspaces_.end())
|
else if (!prev && it != workspaces_.end())
|
||||||
++it;
|
++it;
|
||||||
if (!prev && it == workspaces_.end()) {
|
if (!prev && it == workspaces_.end()) {
|
||||||
|
if (config_["disable-scroll-wraparound"].asBool()) {
|
||||||
|
--it;
|
||||||
|
} else {
|
||||||
return (*(workspaces_.begin()))["name"].asString();
|
return (*(workspaces_.begin()))["name"].asString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (*it)["name"].asString();
|
return (*it)["name"].asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user