feat(network): network info interval

pull/103/head
Alexis 2018-11-16 10:02:12 +01:00
parent c910767378
commit e42fae32ab
6 changed files with 30 additions and 11 deletions

View File

@ -34,7 +34,7 @@ class Battery : public ALabel {
std::string getState(uint16_t);
util::SleeperThread thread_;
util::SleeperThread threadTimer_;
util::SleeperThread thread_timer_;
std::vector<fs::path> batteries_;
int fd_;
std::string old_status_;

View File

@ -23,6 +23,7 @@ class Network : public ALabel {
static int netlinkResponse(int, void*, uint32_t, uint32_t groups = 0);
static int scanCb(struct nl_msg*, void*);
void worker();
void disconnected();
void initNL80211();
int getExternalInterface();
@ -33,10 +34,11 @@ class Network : public ALabel {
auto getInfo() -> void;
waybar::util::SleeperThread thread_;
waybar::util::SleeperThread thread_timer_;
int ifid_;
sa_family_t family_;
int sock_fd_;
struct sockaddr_nl nladdr_ = {};
struct sockaddr_nl nladdr_ = {0};
struct nl_sock* sk_ = nullptr;
int nl80211_id_;

View File

@ -90,6 +90,10 @@ void waybar::Client::bindInterfaces()
};
wl_registry_add_listener(registry, &registry_listener, this);
wl_display_roundtrip(wl_display);
if (!layer_shell || !seat || !xdg_output_manager) {
throw std::runtime_error("Failed to acquire required resources.");
}
wl_display_roundtrip(wl_display);
}
int waybar::Client::main(int /*argc*/, char* /*argv*/[])

View File

@ -47,7 +47,7 @@ void waybar::modules::Battery::worker()
// Trigger first values
update();
uint32_t interval = config_["interval"].isUInt() ? config_["interval"].asUInt() : 60;
threadTimer_ = [this, interval] {
thread_timer_ = [this, interval] {
thread_.sleep_for(chrono::seconds(interval));
dp.emit();
};
@ -58,7 +58,7 @@ void waybar::modules::Battery::worker()
return;
}
// TODO: don't stop timer for now since there is some bugs :?
// threadTimer_.stop();
// thread_timer_.stop();
dp.emit();
};
}

View File

@ -14,7 +14,7 @@ waybar::modules::Cpu::Cpu(const Json::Value& config)
auto waybar::modules::Cpu::update() -> void
{
try {
// TODO: as creating dynamic fmt::arg arrays is buggy we have to do this
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
auto cpu_load = getCpuLoad();
auto [cpu_usage, tooltip] = getCpuUsage();
label_.set_tooltip_text(tooltip);

View File

@ -34,6 +34,17 @@ waybar::modules::Network::Network(const Json::Value& config)
// Trigger first values
getInfo();
update();
worker();
}
waybar::modules::Network::~Network()
{
close(sock_fd_);
nl_socket_free(sk_);
}
void waybar::modules::Network::worker()
{
thread_ = [this] {
char buf[4096];
uint64_t len = netlinkResponse(sock_fd_, buf, sizeof(buf),
@ -74,12 +85,14 @@ waybar::modules::Network::Network(const Json::Value& config)
dp.emit();
}
};
}
waybar::modules::Network::~Network()
{
close(sock_fd_);
nl_socket_free(sk_);
uint32_t interval = config_["interval"].isUInt() ? config_["interval"].asUInt() : 60;
thread_timer_ = [this, interval] {
thread_.sleep_for(std::chrono::seconds(interval));
if (ifid_ > 0) {
getInfo();
dp.emit();
}
};
}
auto waybar::modules::Network::update() -> void