From 0f0765e5175d53217ddd200a04a488c9dca0ed30 Mon Sep 17 00:00:00 2001 From: Jordi Pakey-Rodriguez Date: Fri, 5 Jul 2019 14:46:38 -0700 Subject: [PATCH 01/40] feat(modules): call user on-update if configured --- src/AModule.cpp | 2 +- src/modules/backlight.cpp | 5 +++++ src/modules/battery.cpp | 5 +++++ src/modules/clock.cpp | 5 +++++ src/modules/cpu.cpp | 5 +++++ src/modules/custom.cpp | 5 +++++ src/modules/idle_inhibitor.cpp | 5 +++++ src/modules/memory.cpp | 5 +++++ src/modules/mpd.cpp | 5 +++++ src/modules/network.cpp | 5 +++++ src/modules/pulseaudio.cpp | 5 +++++ src/modules/temperature.cpp | 5 +++++ 12 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/AModule.cpp b/src/AModule.cpp index 354d1bf..da43259 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -29,7 +29,7 @@ AModule::~AModule() { } auto AModule::update() -> void { - // Nothing here + pid_.push_back(util::command::forkExec(config_["on-update"].asString())); } bool AModule::handleToggle(GdkEventButton* const& e) { diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index b38f260..8b63bd6 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -175,6 +175,11 @@ auto waybar::modules::Backlight::update() -> void { return; } + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + const auto percent = best->get_max() == 0 ? 100 : best->get_actual() * 100 / best->get_max(); label_.set_markup(fmt::format( format_, fmt::arg("percent", std::to_string(percent)), fmt::arg("icon", getIcon(percent)))); diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 61ed50a..b50c38a 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -149,6 +149,11 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai } auto waybar::modules::Battery::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + auto [capacity, time_remaining, status] = getInfos(); if (status == "Unknown") { status = getAdapterStatus(capacity); diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 2fa0214..5a781ef 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -13,6 +13,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } auto waybar::modules::Clock::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + tzset(); // Update timezone information auto now = std::chrono::system_clock::now(); auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 298f7a4..33d0d53 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -10,6 +10,11 @@ waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config) } auto waybar::modules::Cpu::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both auto cpu_load = getCpuLoad(); auto [cpu_usage, tooltip] = getCpuUsage(); diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index ca09508..1853b2f 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -93,6 +93,11 @@ bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) { } auto waybar::modules::Custom::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + // Hide label if output is empty if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) { event_box_.hide(); diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index e5460ad..c39e011 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -26,6 +26,11 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { } auto waybar::modules::IdleInhibitor::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + label_.set_markup( fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); label_.get_style_context()->add_class(status_); diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index eeb92bf..3e1ed74 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -9,6 +9,11 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config } auto waybar::modules::Memory::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + parseMeminfo(); if (memtotal_ > 0 && memfree_ >= 0) { auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2); diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 7bad855..f61dfc4 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -35,6 +35,11 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config) } auto waybar::modules::MPD::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + std::lock_guard guard(connection_lock_); tryConnect(); diff --git a/src/modules/network.cpp b/src/modules/network.cpp index ba196cf..9513a93 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -228,6 +228,11 @@ const std::string waybar::modules::Network::getNetworkState() const { } auto waybar::modules::Network::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + std::lock_guard lock(mutex_); std::string tooltip_format; auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index ef2bc27..e336825 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -196,6 +196,11 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const { } auto waybar::modules::Pulseaudio::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + auto format = format_; std::string format_name = "format"; if (monitor_.find("a2dp_sink") != std::string::npos) { diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index 78391a0..d17c2ad 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -19,6 +19,11 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val } auto waybar::modules::Temperature::update() -> void { + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + AModule::update(); + } + auto [temperature_c, temperature_f] = getTemperature(); auto critical = isCritical(temperature_c); auto format = format_; From 2dc4ae78fcd96ffc549b8ed094a3eb43c20bf73a Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Mon, 20 Jan 2020 00:35:37 +0100 Subject: [PATCH 02/40] distinguish between wifi disabled and disconnected --- include/modules/network.hpp | 2 ++ src/modules/network.cpp | 54 ++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 91e4ddb..f0d2e8e 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" @@ -45,6 +46,7 @@ class Network : public ALabel { const std::string getNetworkState() const; void clearIface(); bool wildcardMatch(const std::string& pattern, const std::string& text) const; + bool isDisabled(enum rfkill_type rfkill_type) const; int ifid_; sa_family_t family_; diff --git a/src/modules/network.cpp b/src/modules/network.cpp index a332d5a..b140a95 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -4,6 +4,11 @@ #include #include "util/format.hpp" +#include +//#include +#include +#include +#include namespace { @@ -221,12 +226,59 @@ void waybar::modules::Network::worker() { } const std::string waybar::modules::Network::getNetworkState() const { - if (ifid_ == -1) return "disconnected"; + if (ifid_ == -1) { + if (isDisabled(RFKILL_TYPE_WLAN)) + return "disabled"; + return "disconnected"; + } if (ipaddr_.empty()) return "linked"; if (essid_.empty()) return "ethernet"; return "wifi"; } +bool waybar::modules::Network::isDisabled(enum rfkill_type rfkill_type) const { + struct rfkill_event event; + ssize_t len; + int fd; + int ret; + ret = false; + + fd = open("/dev/rfkill", O_RDONLY); + if (fd < 0) { + perror("Can't open RFKILL control device"); + return false; + } + + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + perror("Can't set RFKILL control device to non-blocking"); + close(fd); + return false; + } + + while(true) { + len = read(fd, &event, sizeof(event)); + if (len < 0) { + if (errno == EAGAIN) + return 1; + perror("Reading of RFKILL events failed"); + return false; + } + + if (len != RFKILL_EVENT_SIZE_V1) { + fprintf(stderr, "Wrong size of RFKILL event\n"); + return false; + } + + if(event.type == rfkill_type) { + ret = event.soft || event.hard; + break; + } + } + + close(fd); + return ret; +} + auto waybar::modules::Network::update() -> void { std::lock_guard lock(mutex_); std::string tooltip_format; From 2c4369a65321901fb70b5d9327736a9aaa6e9bd0 Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Tue, 21 Jan 2020 15:46:08 +0100 Subject: [PATCH 03/40] add basis for bluetooth module implementation --- include/factory.hpp | 1 + meson.build | 1 + src/factory.cpp | 3 +++ 3 files changed, 5 insertions(+) diff --git a/include/factory.hpp b/include/factory.hpp index 7d4d14e..b14b998 100644 --- a/include/factory.hpp +++ b/include/factory.hpp @@ -32,6 +32,7 @@ #include "bar.hpp" #include "modules/custom.hpp" #include "modules/temperature.hpp" +#include "modules/bluetooth.hpp" namespace waybar { diff --git a/meson.build b/meson.build index a099ad2..0032c91 100644 --- a/meson.build +++ b/meson.build @@ -88,6 +88,7 @@ src_files = files( 'src/ALabel.cpp', 'src/modules/memory.cpp', 'src/modules/battery.cpp', + 'src/modules/bluetooth.cpp', 'src/modules/clock.cpp', 'src/modules/custom.cpp', 'src/modules/cpu.cpp', diff --git a/src/factory.cpp b/src/factory.cpp index 8f7cea7..16a6903 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -66,6 +66,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const { if (ref == "temperature") { return new waybar::modules::Temperature(id, config_[name]); } + if (ref == "bluetooth") { + return new waybar::modules::Bluetooth(id, config_[name]); + } if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) { return new waybar::modules::Custom(ref.substr(7), id, config_[name]); } From 626af1ddc15df55b92bd38e03977089922e34f40 Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Tue, 21 Jan 2020 17:04:54 +0100 Subject: [PATCH 04/40] add rudimentary bluetooth module functionality --- include/modules/bluetooth.hpp | 18 ++++++++++++ include/util/rfkill.hpp | 55 +++++++++++++++++++++++++++++++++++ src/modules/bluetooth.cpp | 29 ++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 include/modules/bluetooth.hpp create mode 100644 include/util/rfkill.hpp create mode 100644 src/modules/bluetooth.cpp diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp new file mode 100644 index 0000000..4329861 --- /dev/null +++ b/include/modules/bluetooth.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include "ALabel.hpp" + +namespace waybar::modules { + +class Bluetooth : public ALabel { + public: + Bluetooth(const std::string&, const Json::Value&); + ~Bluetooth() = default; + auto update() -> void; + + private: + ; +}; + +} // namespace waybar::modules diff --git a/include/util/rfkill.hpp b/include/util/rfkill.hpp new file mode 100644 index 0000000..9ef6892 --- /dev/null +++ b/include/util/rfkill.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +//#include +#include +#include +#include + +namespace waybar::util { + +bool isDisabled(enum rfkill_type rfkill_type) { + struct rfkill_event event; + ssize_t len; + int fd; + int ret; + ret = false; + + fd = open("/dev/rfkill", O_RDONLY); + if (fd < 0) { + perror("Can't open RFKILL control device"); + return false; + } + + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + perror("Can't set RFKILL control device to non-blocking"); + close(fd); + return false; + } + + while(true) { + len = read(fd, &event, sizeof(event)); + if (len < 0) { + if (errno == EAGAIN) + return 1; + perror("Reading of RFKILL events failed"); + return false; + } + + if (len != RFKILL_EVENT_SIZE_V1) { + fprintf(stderr, "Wrong size of RFKILL event\n"); + return false; + } + + if(event.type == rfkill_type) { + ret = event.soft || event.hard; + break; + } + } + + close(fd); + return ret; +} + +} // namespace waybar::util diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp new file mode 100644 index 0000000..ab8bdda --- /dev/null +++ b/src/modules/bluetooth.cpp @@ -0,0 +1,29 @@ +#include "modules/bluetooth.hpp" +#include "util/rfkill.hpp" +#include + +waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) + : ALabel(config, "bluetooth", id, "{status}", 10) { + dp.emit(); +} + +auto waybar::modules::Bluetooth::update() -> void { + auto text = "enabled"; + if (waybar::util::isDisabled(RFKILL_TYPE_BLUETOOTH)) { + text = "disabled"; + } else { + text = "enabled"; + } + + label_.set_markup(text); + + if (tooltipEnabled()) { + if (config_["tooltip-format"].isString()) { + auto tooltip_format = config_["tooltip-format"].asString(); + auto tooltip_text = fmt::format(tooltip_format, localtime); + label_.set_tooltip_text(tooltip_text); + } else { + label_.set_tooltip_text(text); + } + } +} From f0dbd8b78ddacee555cabb0258d758ff670db122 Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Tue, 21 Jan 2020 17:48:45 +0100 Subject: [PATCH 05/40] properly structure rfkill util --- include/modules/network.hpp | 2 -- include/util/rfkill.hpp | 48 +------------------------------ meson.build | 3 +- src/modules/network.cpp | 57 ++++--------------------------------- src/util/rfkill.cpp | 49 +++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 102 deletions(-) create mode 100644 src/util/rfkill.cpp diff --git a/include/modules/network.hpp b/include/modules/network.hpp index f0d2e8e..91e4ddb 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" @@ -46,7 +45,6 @@ class Network : public ALabel { const std::string getNetworkState() const; void clearIface(); bool wildcardMatch(const std::string& pattern, const std::string& text) const; - bool isDisabled(enum rfkill_type rfkill_type) const; int ifid_; sa_family_t family_; diff --git a/include/util/rfkill.hpp b/include/util/rfkill.hpp index 9ef6892..53f558c 100644 --- a/include/util/rfkill.hpp +++ b/include/util/rfkill.hpp @@ -1,55 +1,9 @@ #pragma once #include -#include -//#include -#include -#include -#include namespace waybar::util { -bool isDisabled(enum rfkill_type rfkill_type) { - struct rfkill_event event; - ssize_t len; - int fd; - int ret; - ret = false; - - fd = open("/dev/rfkill", O_RDONLY); - if (fd < 0) { - perror("Can't open RFKILL control device"); - return false; - } - - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - perror("Can't set RFKILL control device to non-blocking"); - close(fd); - return false; - } - - while(true) { - len = read(fd, &event, sizeof(event)); - if (len < 0) { - if (errno == EAGAIN) - return 1; - perror("Reading of RFKILL events failed"); - return false; - } - - if (len != RFKILL_EVENT_SIZE_V1) { - fprintf(stderr, "Wrong size of RFKILL event\n"); - return false; - } - - if(event.type == rfkill_type) { - ret = event.soft || event.hard; - break; - } - } - - close(fd); - return ret; -} +bool isDisabled(enum rfkill_type rfkill_type); } // namespace waybar::util diff --git a/meson.build b/meson.build index 0032c91..8f29d10 100644 --- a/meson.build +++ b/meson.build @@ -97,7 +97,8 @@ src_files = files( 'src/modules/temperature.cpp', 'src/main.cpp', 'src/bar.cpp', - 'src/client.cpp' + 'src/client.cpp', + 'src/util/rfkill.cpp' ) if true # find_program('sway', required : false).found() diff --git a/src/modules/network.cpp b/src/modules/network.cpp index b140a95..2639a05 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -3,12 +3,8 @@ #include #include #include "util/format.hpp" - -#include -//#include -#include +#include "util/rfkill.hpp" #include -#include namespace { @@ -227,58 +223,15 @@ void waybar::modules::Network::worker() { const std::string waybar::modules::Network::getNetworkState() const { if (ifid_ == -1) { - if (isDisabled(RFKILL_TYPE_WLAN)) - return "disabled"; - return "disconnected"; - } + if (waybar::util::isDisabled(RFKILL_TYPE_WLAN)) + return "disabled"; + return "disconnected"; + } if (ipaddr_.empty()) return "linked"; if (essid_.empty()) return "ethernet"; return "wifi"; } -bool waybar::modules::Network::isDisabled(enum rfkill_type rfkill_type) const { - struct rfkill_event event; - ssize_t len; - int fd; - int ret; - ret = false; - - fd = open("/dev/rfkill", O_RDONLY); - if (fd < 0) { - perror("Can't open RFKILL control device"); - return false; - } - - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - perror("Can't set RFKILL control device to non-blocking"); - close(fd); - return false; - } - - while(true) { - len = read(fd, &event, sizeof(event)); - if (len < 0) { - if (errno == EAGAIN) - return 1; - perror("Reading of RFKILL events failed"); - return false; - } - - if (len != RFKILL_EVENT_SIZE_V1) { - fprintf(stderr, "Wrong size of RFKILL event\n"); - return false; - } - - if(event.type == rfkill_type) { - ret = event.soft || event.hard; - break; - } - } - - close(fd); - return ret; -} - auto waybar::modules::Network::update() -> void { std::lock_guard lock(mutex_); std::string tooltip_format; diff --git a/src/util/rfkill.cpp b/src/util/rfkill.cpp new file mode 100644 index 0000000..d1b38ec --- /dev/null +++ b/src/util/rfkill.cpp @@ -0,0 +1,49 @@ +#include "util/rfkill.hpp" +#include +#include +#include +#include +#include + +bool waybar::util::isDisabled(enum rfkill_type rfkill_type) { + struct rfkill_event event; + ssize_t len; + int fd; + int ret; + ret = false; + + fd = open("/dev/rfkill", O_RDONLY); + if (fd < 0) { + //perror("Can't open RFKILL control device"); + return false; + } + + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + //perror("Can't set RFKILL control device to non-blocking"); + close(fd); + return false; + } + + while(true) { + len = read(fd, &event, sizeof(event)); + if (len < 0) { + if (errno == EAGAIN) + return 1; + //perror("Reading of RFKILL events failed"); + return false; + } + + if (len != RFKILL_EVENT_SIZE_V1) { + //fprintf(stderr, "Wrong size of RFKILL event\n"); + return false; + } + + if(event.type == rfkill_type) { + ret = event.soft || event.hard; + break; + } + } + + close(fd); + return ret; +} From 89cb9673d42c0d4eb97e134a40cce16a76b4ec1f Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Wed, 22 Jan 2020 11:37:47 +0100 Subject: [PATCH 06/40] bluetooth module working --- include/modules/bluetooth.hpp | 6 ++++- include/util/rfkill.hpp | 2 +- src/modules/bluetooth.cpp | 44 ++++++++++++++++++++++------------- src/modules/network.cpp | 2 +- src/util/rfkill.cpp | 2 +- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index 4329861..d0fdce8 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -3,6 +3,9 @@ #include #include "ALabel.hpp" +#include +#include "util/sleeper_thread.hpp" + namespace waybar::modules { class Bluetooth : public ALabel { @@ -12,7 +15,8 @@ class Bluetooth : public ALabel { auto update() -> void; private: - ; + std::string status_; + util::SleeperThread thread_; }; } // namespace waybar::modules diff --git a/include/util/rfkill.hpp b/include/util/rfkill.hpp index 53f558c..f309b6f 100644 --- a/include/util/rfkill.hpp +++ b/include/util/rfkill.hpp @@ -2,7 +2,7 @@ #include -namespace waybar::util { +namespace waybar::util::rfkill { bool isDisabled(enum rfkill_type rfkill_type); diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index ab8bdda..dff42cd 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -2,28 +2,40 @@ #include "util/rfkill.hpp" #include +#include + waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) - : ALabel(config, "bluetooth", id, "{status}", 10) { - dp.emit(); + : ALabel(config, "bluetooth", id, "{status}", 10), + status_("disabled") { + thread_ = [this] { + dp.emit(); + auto now = std::chrono::system_clock::now(); + auto timeout = std::chrono::floor(now + interval_); + auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); + thread_.sleep_until(timeout - diff); + }; + //dp.emit(); } auto waybar::modules::Bluetooth::update() -> void { - auto text = "enabled"; - if (waybar::util::isDisabled(RFKILL_TYPE_BLUETOOTH)) { - text = "disabled"; + status_ = "enabled"; + if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_BLUETOOTH)) { + status_ = "disabled"; } else { - text = "enabled"; + status_ = "enabled"; } - label_.set_markup(text); + label_.set_markup( + fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); + label_.get_style_context()->add_class(status_); - if (tooltipEnabled()) { - if (config_["tooltip-format"].isString()) { - auto tooltip_format = config_["tooltip-format"].asString(); - auto tooltip_text = fmt::format(tooltip_format, localtime); - label_.set_tooltip_text(tooltip_text); - } else { - label_.set_tooltip_text(text); - } - } + //if (tooltipEnabled()) { + //if (config_["tooltip-format"].isString()) { + //auto tooltip_format = config_["tooltip-format"].asString(); + ////auto tooltip_text = fmt::format(tooltip_format, localtime); + //label_.set_tooltip_text(tooltip_text); + //} else { + //label_.set_tooltip_text(text); + //} + //} } diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 2639a05..636db67 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -223,7 +223,7 @@ void waybar::modules::Network::worker() { const std::string waybar::modules::Network::getNetworkState() const { if (ifid_ == -1) { - if (waybar::util::isDisabled(RFKILL_TYPE_WLAN)) + if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_WLAN)) return "disabled"; return "disconnected"; } diff --git a/src/util/rfkill.cpp b/src/util/rfkill.cpp index d1b38ec..2b0e42d 100644 --- a/src/util/rfkill.cpp +++ b/src/util/rfkill.cpp @@ -5,7 +5,7 @@ #include #include -bool waybar::util::isDisabled(enum rfkill_type rfkill_type) { +bool waybar::util::rfkill::isDisabled(enum rfkill_type rfkill_type) { struct rfkill_event event; ssize_t len; int fd; From e3bf6b968c8ff9f12cd38d2944007fff36270949 Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Thu, 23 Jan 2020 17:17:29 +0100 Subject: [PATCH 07/40] bluetooth module handles rfkill events instantly --- include/modules/bluetooth.hpp | 7 ++-- include/modules/network.hpp | 3 ++ include/util/rfkill.hpp | 16 +++++++-- src/modules/bluetooth.cpp | 16 ++++----- src/modules/network.cpp | 6 ++-- src/util/rfkill.cpp | 66 +++++++++++++++++++++++++++++++++-- 6 files changed, 97 insertions(+), 17 deletions(-) diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index d0fdce8..9dbb7fa 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -5,6 +5,7 @@ #include #include "util/sleeper_thread.hpp" +#include "util/rfkill.hpp" namespace waybar::modules { @@ -15,8 +16,10 @@ class Bluetooth : public ALabel { auto update() -> void; private: - std::string status_; - util::SleeperThread thread_; + std::string status_; + util::SleeperThread thread_; + + util::Rfkill rfkill_; }; } // namespace waybar::modules diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 91e4ddb..2d9d72c 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -11,6 +11,7 @@ #include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" +#include "util/rfkill.hpp" namespace waybar::modules { @@ -71,6 +72,8 @@ class Network : public ALabel { util::SleeperThread thread_; util::SleeperThread thread_timer_; + + util::Rfkill rfkill_; }; } // namespace waybar::modules diff --git a/include/util/rfkill.hpp b/include/util/rfkill.hpp index f309b6f..b2fccce 100644 --- a/include/util/rfkill.hpp +++ b/include/util/rfkill.hpp @@ -2,8 +2,20 @@ #include -namespace waybar::util::rfkill { +namespace waybar::util { -bool isDisabled(enum rfkill_type rfkill_type); +class Rfkill { + public: + Rfkill(enum rfkill_type rfkill_type); + ~Rfkill() = default; + bool isDisabled() const; + void waitForEvent(); + int getState(); + + private: + enum rfkill_type rfkill_type_; + int state_ = 0; + int prev_state_ = 0; +}; } // namespace waybar::util diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index dff42cd..9e6d797 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -1,25 +1,23 @@ #include "modules/bluetooth.hpp" #include "util/rfkill.hpp" #include - #include +#include + waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) : ALabel(config, "bluetooth", id, "{status}", 10), - status_("disabled") { + status_("disabled"), + rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_BLUETOOTH))) { thread_ = [this] { dp.emit(); - auto now = std::chrono::system_clock::now(); - auto timeout = std::chrono::floor(now + interval_); - auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); - thread_.sleep_until(timeout - diff); + rfkill_.waitForEvent(); }; - //dp.emit(); } auto waybar::modules::Bluetooth::update() -> void { status_ = "enabled"; - if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_BLUETOOTH)) { + if (rfkill_.getState()) { status_ = "disabled"; } else { status_ = "enabled"; @@ -35,7 +33,7 @@ auto waybar::modules::Bluetooth::update() -> void { ////auto tooltip_text = fmt::format(tooltip_format, localtime); //label_.set_tooltip_text(tooltip_text); //} else { - //label_.set_tooltip_text(text); + //label_.set_tooltip_text(status_); //} //} } diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 63e3be9..31619bf 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -87,7 +87,9 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf cidr_(-1), signal_strength_dbm_(0), signal_strength_(0), - frequency_(0) { + frequency_(0), + rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_WLAN))) { + auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY); if (down_octets) { @@ -224,7 +226,7 @@ void waybar::modules::Network::worker() { const std::string waybar::modules::Network::getNetworkState() const { if (ifid_ == -1) { - if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_WLAN)) + if (rfkill_.isDisabled()) return "disabled"; return "disconnected"; } diff --git a/src/util/rfkill.cpp b/src/util/rfkill.cpp index 2b0e42d..92aee02 100644 --- a/src/util/rfkill.cpp +++ b/src/util/rfkill.cpp @@ -3,9 +3,71 @@ #include #include #include +#include #include +#include -bool waybar::util::rfkill::isDisabled(enum rfkill_type rfkill_type) { +waybar::util::Rfkill::Rfkill(const enum rfkill_type rfkill_type) + : rfkill_type_(rfkill_type) { +} + +void waybar::util::Rfkill::waitForEvent() { + struct rfkill_event event; + struct pollfd p; + ssize_t len; + int fd, n; + + fd = open("/dev/rfkill", O_RDONLY); + if (fd < 0) { + //perror("Can't open RFKILL control device"); + return; + } + + memset(&p, 0, sizeof(p)); + p.fd = fd; + p.events = POLLIN | POLLHUP; + + while (1) { + n = poll(&p, 1, -1); + if (n < 0) { + //perror("Failed to poll RFKILL control device"); + break; + } + + if (n == 0) + continue; + + len = read(fd, &event, sizeof(event)); + if (len < 0) { + //perror("Reading of RFKILL events failed"); + break; + } + + if (len != RFKILL_EVENT_SIZE_V1) { + //fprintf(stderr, "Wrong size of RFKILL event\n"); + continue; + } + + if(event.type == rfkill_type_) { + state_ = event.soft || event.hard; + if (prev_state_ != state_) { + prev_state_ = state_; + break; + } + //ret = event.soft || event.hard; + } + } + + close(fd); + return; +} + + +int waybar::util::Rfkill::getState() { + return state_; +} + +bool waybar::util::Rfkill::isDisabled() const { struct rfkill_event event; ssize_t len; int fd; @@ -38,7 +100,7 @@ bool waybar::util::rfkill::isDisabled(enum rfkill_type rfkill_type) { return false; } - if(event.type == rfkill_type) { + if(event.type == rfkill_type_) { ret = event.soft || event.hard; break; } From c045288ce4cb22f1888b4fa7f3b37ed56d42c1df Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Sun, 26 Jan 2020 05:34:31 +0100 Subject: [PATCH 08/40] add man page for bluetooth, fix bluetooth race-condition --- include/modules/bluetooth.hpp | 1 + include/modules/network.hpp | 1 + include/util/rfkill.hpp | 5 +- man/waybar-bluetooth.5.scd | 94 +++++++++++++++++++++++++++++++++++ man/waybar-network.5.scd | 10 ++++ src/modules/bluetooth.cpp | 38 ++++++++------ src/modules/network.cpp | 18 +++++-- src/util/rfkill.cpp | 64 ++++-------------------- 8 files changed, 153 insertions(+), 78 deletions(-) create mode 100644 man/waybar-bluetooth.5.scd diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index 9dbb7fa..04c213d 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -18,6 +18,7 @@ class Bluetooth : public ALabel { private: std::string status_; util::SleeperThread thread_; + util::SleeperThread intervall_thread_; util::Rfkill rfkill_; }; diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 2d9d72c..edb5aa6 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -72,6 +72,7 @@ class Network : public ALabel { util::SleeperThread thread_; util::SleeperThread thread_timer_; + util::SleeperThread thread_rfkill_; util::Rfkill rfkill_; }; diff --git a/include/util/rfkill.hpp b/include/util/rfkill.hpp index b2fccce..67a9807 100644 --- a/include/util/rfkill.hpp +++ b/include/util/rfkill.hpp @@ -5,12 +5,11 @@ namespace waybar::util { class Rfkill { - public: + public:; Rfkill(enum rfkill_type rfkill_type); ~Rfkill() = default; - bool isDisabled() const; void waitForEvent(); - int getState(); + int getState() const; private: enum rfkill_type rfkill_type_; diff --git a/man/waybar-bluetooth.5.scd b/man/waybar-bluetooth.5.scd new file mode 100644 index 0000000..7f6876b --- /dev/null +++ b/man/waybar-bluetooth.5.scd @@ -0,0 +1,94 @@ +waybar-bluetooth(5) + +# NAME + +waybar - bluetooth module + +# DESCRIPTION + +The *bluetooth* module displays information about the status of the device's bluetooth device. + +# CONFIGURATION + +Addressed by *bluetooth* + +*interval*: ++ + typeof: integer ++ + default: 60 ++ + The interval in which the network information gets polled (e.g. signal strength). + +*format*: ++ + typeof: string ++ + default: *{icon}* ++ + The format, how information should be displayed. This format is used when other formats aren't specified. + +*format-icons*: ++ + typeof: array/object ++ + Based on the device status, the corresponding icon gets selected. ++ + The order is *low* to *high*. Or by the state if it is an object. + +*rotate*: ++ + typeof: integer ++ + Positive value to rotate the text label. + +*max-length*: ++ + typeof: integer ++ + The maximum length in character the module should display. + +*on-click*: ++ + typeof: string ++ + Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + +*on-click-right*: ++ + typeof: string ++ + Command to execute when you right clicked on the module. + +*on-scroll-up*: ++ + typeof: string ++ + Command to execute when scrolling up on the module. + +*on-scroll-down*: ++ + typeof: string ++ + Command to execute when scrolling down on the module. + +*smooth-scrolling-threshold*: ++ + typeof: double ++ + Threshold to be used when scrolling. + +*tooltip*: ++ + typeof: bool ++ + default: *true* ++ + Option to disable tooltip on hover. + +*tooltip-format*: ++ + typeof: string ++ + The format, how information should be displayed in the tooltip. This format is used when other formats aren't specified. + +# FORMAT REPLACEMENTS + +*{status}*: Status of the bluetooth device. + +*{icon}*: Icon, as defined in *format-icons*. + +# EXAMPLES + +``` +"bluetooth": { + "format": "{icon}", + "format-alt": "bluetooth: {status}", + "interval": 30, + "format-icons": { + "enabled": "", + "disabled": "" + } + "tooltip-format": "{status}" +} +``` + +# STYLE + +- *#bluetooth* diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index a557aa3..ad4c906 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -47,6 +47,10 @@ Addressed by *network* typeof: string ++ This format is used when the displayed interface is disconnected. +*format-disabled*: ++ + typeof: string ++ + This format is used when the displayed interface is disabled. + *format-icons*: ++ typeof: array/object ++ Based on the current signal strength, the corresponding icon gets selected. ++ @@ -105,6 +109,10 @@ Addressed by *network* typeof: string ++ This format is used when the displayed interface is disconnected. +*tooltip-format-disabled*: ++ + typeof: string ++ + This format is used when the displayed interface is disabled. + # FORMAT REPLACEMENTS *{ifname}*: Name of the network interface. @@ -142,6 +150,7 @@ Addressed by *network* "format-wifi": "{essid} ({signalStrength}%) ", "format-ethernet": "{ifname} ", "format-disconnected": "", //An empty format will hide the module. + "format-disconnected": "", "tooltip-format": "{ifname}", "tooltip-format-wifi": "{essid} ({signalStrength}%) ", "tooltip-format-ethernet": "{ifname} ", @@ -154,6 +163,7 @@ Addressed by *network* - *#network* - *#network.disconnected* +- *#network.disabled* - *#network.linked* - *#network.ethernet* - *#network.wifi* diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 9e6d797..b390976 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -3,20 +3,24 @@ #include #include -#include - waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) - : ALabel(config, "bluetooth", id, "{status}", 10), + : ALabel(config, "bluetooth", id, "{icon}", 10), status_("disabled"), - rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_BLUETOOTH))) { + rfkill_{RFKILL_TYPE_BLUETOOTH} { thread_ = [this] { dp.emit(); rfkill_.waitForEvent(); }; + intervall_thread_ = [this] { + auto now = std::chrono::system_clock::now(); + auto timeout = std::chrono::floor(now + interval_); + auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); + thread_.sleep_until(timeout - diff); + dp.emit(); + }; } auto waybar::modules::Bluetooth::update() -> void { - status_ = "enabled"; if (rfkill_.getState()) { status_ = "disabled"; } else { @@ -24,16 +28,18 @@ auto waybar::modules::Bluetooth::update() -> void { } label_.set_markup( - fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); - label_.get_style_context()->add_class(status_); + fmt::format( + format_, + fmt::arg("status", status_), + fmt::arg("icon", getIcon(0, status_)))); - //if (tooltipEnabled()) { - //if (config_["tooltip-format"].isString()) { - //auto tooltip_format = config_["tooltip-format"].asString(); - ////auto tooltip_text = fmt::format(tooltip_format, localtime); - //label_.set_tooltip_text(tooltip_text); - //} else { - //label_.set_tooltip_text(status_); - //} - //} + if (tooltipEnabled()) { + if (config_["tooltip-format"].isString()) { + auto tooltip_format = config_["tooltip-format"].asString(); + auto tooltip_text = fmt::format(tooltip_format, status_); + label_.set_tooltip_text(tooltip_text); + } else { + label_.set_tooltip_text(status_); + } + } } diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 31619bf..d2065bd 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -3,9 +3,9 @@ #include #include #include +#include #include "util/format.hpp" #include "util/rfkill.hpp" -#include namespace { @@ -88,8 +88,7 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf signal_strength_dbm_(0), signal_strength_(0), frequency_(0), - rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_WLAN))) { - + rfkill_{RFKILL_TYPE_WLAN} { auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY); if (down_octets) { @@ -199,6 +198,7 @@ void waybar::modules::Network::createInfoSocket() { } void waybar::modules::Network::worker() { + // update via here not working thread_timer_ = [this] { { std::lock_guard lock(mutex_); @@ -209,6 +209,16 @@ void waybar::modules::Network::worker() { } thread_timer_.sleep_for(interval_); }; + thread_rfkill_ = [this] { + rfkill_.waitForEvent(); + { + std::lock_guard lock(mutex_); + if (ifid_ > 0) { + getInfo(); + dp.emit(); + } + } + }; thread_ = [this] { std::array events{}; @@ -226,7 +236,7 @@ void waybar::modules::Network::worker() { const std::string waybar::modules::Network::getNetworkState() const { if (ifid_ == -1) { - if (rfkill_.isDisabled()) + if (rfkill_.getState()) return "disabled"; return "disconnected"; } diff --git a/src/util/rfkill.cpp b/src/util/rfkill.cpp index 92aee02..a4f9c71 100644 --- a/src/util/rfkill.cpp +++ b/src/util/rfkill.cpp @@ -1,11 +1,12 @@ #include "util/rfkill.hpp" +#include #include #include #include #include #include #include -#include +#include waybar::util::Rfkill::Rfkill(const enum rfkill_type rfkill_type) : rfkill_type_(rfkill_type) { @@ -19,7 +20,7 @@ void waybar::util::Rfkill::waitForEvent() { fd = open("/dev/rfkill", O_RDONLY); if (fd < 0) { - //perror("Can't open RFKILL control device"); + throw std::runtime_error("Can't open RFKILL control device"); return; } @@ -30,7 +31,7 @@ void waybar::util::Rfkill::waitForEvent() { while (1) { n = poll(&p, 1, -1); if (n < 0) { - //perror("Failed to poll RFKILL control device"); + throw std::runtime_error("Failed to poll RFKILL control device"); break; } @@ -39,22 +40,18 @@ void waybar::util::Rfkill::waitForEvent() { len = read(fd, &event, sizeof(event)); if (len < 0) { - //perror("Reading of RFKILL events failed"); + throw std::runtime_error("Reading of RFKILL events failed"); break; } if (len != RFKILL_EVENT_SIZE_V1) { - //fprintf(stderr, "Wrong size of RFKILL event\n"); + throw std::runtime_error("Wrong size of RFKILL event"); continue; } - if(event.type == rfkill_type_) { + if(event.type == rfkill_type_ && event.op == RFKILL_OP_CHANGE) { state_ = event.soft || event.hard; - if (prev_state_ != state_) { - prev_state_ = state_; - break; - } - //ret = event.soft || event.hard; + break; } } @@ -63,49 +60,6 @@ void waybar::util::Rfkill::waitForEvent() { } -int waybar::util::Rfkill::getState() { +int waybar::util::Rfkill::getState() const { return state_; } - -bool waybar::util::Rfkill::isDisabled() const { - struct rfkill_event event; - ssize_t len; - int fd; - int ret; - ret = false; - - fd = open("/dev/rfkill", O_RDONLY); - if (fd < 0) { - //perror("Can't open RFKILL control device"); - return false; - } - - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - //perror("Can't set RFKILL control device to non-blocking"); - close(fd); - return false; - } - - while(true) { - len = read(fd, &event, sizeof(event)); - if (len < 0) { - if (errno == EAGAIN) - return 1; - //perror("Reading of RFKILL events failed"); - return false; - } - - if (len != RFKILL_EVENT_SIZE_V1) { - //fprintf(stderr, "Wrong size of RFKILL event\n"); - return false; - } - - if(event.type == rfkill_type_) { - ret = event.soft || event.hard; - break; - } - } - - close(fd); - return ret; -} From 6ae9f436a9df953b67cda2b9cf731c7aa646dd97 Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Thu, 30 Jan 2020 00:25:37 +0100 Subject: [PATCH 09/40] add copyright notice for rfkill util --- src/util/rfkill.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/util/rfkill.cpp b/src/util/rfkill.cpp index a4f9c71..2d5ad7f 100644 --- a/src/util/rfkill.cpp +++ b/src/util/rfkill.cpp @@ -1,3 +1,21 @@ +/* https://git.kernel.org/pub/scm/linux/kernel/git/jberg/rfkill.git/ + * + * Copyright 2009 Johannes Berg + * Copyright 2009 Marcel Holtmann + * Copyright 2009 Tim Gardner + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include "util/rfkill.hpp" #include #include From dd7d78cd605ae067f66d742a119c4f1507bd4638 Mon Sep 17 00:00:00 2001 From: Marc <39213657+marcplustwo@users.noreply.github.com> Date: Sun, 23 Feb 2020 23:09:05 +0100 Subject: [PATCH 10/40] changes requested --- include/util/rfkill.hpp | 3 +-- man/waybar-bluetooth.5.scd | 2 +- src/modules/network.cpp | 1 - src/util/rfkill.cpp | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/util/rfkill.hpp b/include/util/rfkill.hpp index 67a9807..5dbf3ce 100644 --- a/include/util/rfkill.hpp +++ b/include/util/rfkill.hpp @@ -9,12 +9,11 @@ class Rfkill { Rfkill(enum rfkill_type rfkill_type); ~Rfkill() = default; void waitForEvent(); - int getState() const; + bool getState() const; private: enum rfkill_type rfkill_type_; int state_ = 0; - int prev_state_ = 0; }; } // namespace waybar::util diff --git a/man/waybar-bluetooth.5.scd b/man/waybar-bluetooth.5.scd index 7f6876b..a07e544 100644 --- a/man/waybar-bluetooth.5.scd +++ b/man/waybar-bluetooth.5.scd @@ -15,7 +15,7 @@ Addressed by *bluetooth* *interval*: ++ typeof: integer ++ default: 60 ++ - The interval in which the network information gets polled (e.g. signal strength). + The interval in which the bluetooth state gets updated. *format*: ++ typeof: string ++ diff --git a/src/modules/network.cpp b/src/modules/network.cpp index b993f2c..0cf16c0 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "util/format.hpp" #include "util/rfkill.hpp" diff --git a/src/util/rfkill.cpp b/src/util/rfkill.cpp index 2d5ad7f..df77598 100644 --- a/src/util/rfkill.cpp +++ b/src/util/rfkill.cpp @@ -78,6 +78,6 @@ void waybar::util::Rfkill::waitForEvent() { } -int waybar::util::Rfkill::getState() const { +bool waybar::util::Rfkill::getState() const { return state_; } From 03130b75654335ff31251c6dcca0a211b2bfa635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Tue, 3 Mar 2020 22:32:02 +0100 Subject: [PATCH 11/40] systemd service: fix start up ordering the service needs to have After=wayland-session.target otherwise it'll be started in parallel to the compositor which might not be fully configured --- resources/waybar.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/waybar.service.in b/resources/waybar.service.in index 1c086bf..03262a3 100644 --- a/resources/waybar.service.in +++ b/resources/waybar.service.in @@ -2,6 +2,7 @@ Description=Highly customizable Wayland bar for Sway and Wlroots based compositors. Documentation=https://github.com/Alexays/Waybar/wiki/ PartOf=wayland-session.target +After=wayland-session.target [Service] Type=dbus From dd0144c3cd285cc818fb31d239c7e759d6bef823 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Wed, 4 Mar 2020 06:47:12 -0800 Subject: [PATCH 12/40] fix(bar): set exclusive zone early for gtk-layer-shell If the bar is using initial size from the config (i.e both width and height are set and resize is not required), GtkWindow configure event is is not emitted. Initialize exclusive zone earlier for that case. Fixes #609 --- src/bar.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bar.cpp b/src/bar.cpp index 7b9e930..431a564 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -175,6 +175,11 @@ void waybar::Bar::initGtkLayerShell() { gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right); gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top); gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom); + + if (width_ > 1 && height_ > 1) { + /* configure events are not emitted if the bar is using initial size */ + setExclusiveZone(width_, height_); + } } #endif From 3945c7766891148c339a77118b7c1dbe709af407 Mon Sep 17 00:00:00 2001 From: Jordan Cohen Date: Thu, 5 Mar 2020 08:57:19 -0500 Subject: [PATCH 13/40] readme: adding libspdlog-dev to list of ubuntu dependencies, also sorting and cleaning up list to make it easier to read and copy --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d8b7545..be45818 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,24 @@ libmpdclient [MPD module] On Ubuntu 19.10 you can install all the relevant dependencies using this command: ``` -sudo apt install libgtkmm-3.0-dev libjsoncpp-dev libinput-dev libsigc++-2.0-dev libpulse-dev libnl-3-dev libdbusmenu-gtk3-dev libnl-genl-3-dev libfmt-dev clang-tidy libmpdclient-dev libwayland-dev libgtk-3-dev gobject-introspection libgirepository1.0-dev scdoc +sudo apt install \ + clang-tidy \ + gobject-introspection \ + libdbusmenu-gtk3-dev \ + libfmt-dev \ + libgirepository1.0-dev \ + libgtk-3-dev \ + libgtkmm-3.0-dev \ + libinput-dev \ + libjsoncpp-dev \ + libmpdclient-dev \ + libnl-3-dev \ + libnl-genl-3-dev \ + libpulse-dev \ + libsigc++-2.0-dev \ + libspdlog-dev \ + libwayland-dev \ + scdoc ``` From 2f975f870a715f6691ebd2fc12d6ad75dc752316 Mon Sep 17 00:00:00 2001 From: BoostCookie Date: Thu, 12 Mar 2020 22:04:00 +0100 Subject: [PATCH 14/40] Added support for absolute device paths for the temperature module. --- man/waybar-temperature.5.scd | 8 ++++++++ src/modules/temperature.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index f867686..eeae546 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -20,6 +20,14 @@ Addressed by *temperature* typeof: string ++ The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*. +*hwmon-path-abs*: ++ + typeof: string ++ + The path of the hwmon-directory of the device, e.g. */sys/devices/pci0000:00/0000:00:18.3/hwmon*. (Note that the subdirectory *hwmon/hwmon#*, where *#* is a number is not part of the path!) Has to be used together with *input-filename*. + +*input-filename*: ++ + typeof: string ++ + The temperature filename of your *hwmon-path-abs*, e.g. *temp1_input* + *critical-threshold*: ++ typeof: integer ++ The threshold before it is considered critical (Celsius). diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index 78391a0..f2dd958 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -1,9 +1,12 @@ #include "modules/temperature.hpp" +#include waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config) : ALabel(config, "temperature", id, "{temperatureC}°C", 10) { if (config_["hwmon-path"].isString()) { file_path_ = config_["hwmon-path"].asString(); + } else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) { + file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString(); } else { auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone); From d405f28622dfc8e7979e5e7c523c11d3a373a4ba Mon Sep 17 00:00:00 2001 From: BoostCookie <62076789+BoostCookie@users.noreply.github.com> Date: Fri, 13 Mar 2020 16:42:05 +0100 Subject: [PATCH 15/40] Indent now uses spaces. --- src/modules/temperature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index f2dd958..c1b6ebc 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -6,7 +6,7 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val if (config_["hwmon-path"].isString()) { file_path_ = config_["hwmon-path"].asString(); } else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) { - file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString(); + file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString(); } else { auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone); From 5e712ca255232bba6b84ae3845e4ab9b4d0d8902 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 14 Mar 2020 16:25:33 -0400 Subject: [PATCH 16/40] Switch default Makefile rule from run to build This commit makes it so that running `make` without arguments builds rather than builds and runs, which is unconventional and surprising behaviour. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bb6b334..d7182c1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: build build-debug run clean default install -default: run +default: build build: meson build From 19743f3085cc6fc865af33f0aa08d91d64499c0c Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Fri, 20 Mar 2020 17:37:22 -0400 Subject: [PATCH 17/40] fix(memory): provide better free memory approximation on old kernels The approximation should include SReclaimable, and subtract Shmem. To prevent the parsing code from ballooning in size, this commit also refactors the parsing into a map. --- include/modules/memory.hpp | 3 +-- src/modules/memory.cpp | 41 ++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index be66611..5b0f51b 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -17,8 +17,7 @@ class Memory : public ALabel { static inline const std::string data_dir_ = "/proc/meminfo"; void parseMeminfo(); - unsigned long memtotal_; - unsigned long memfree_; + std::unordered_map meminfo_; util::SleeperThread thread_; }; diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index eeb92bf..6aa7036 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -10,11 +10,23 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config auto waybar::modules::Memory::update() -> void { parseMeminfo(); - if (memtotal_ > 0 && memfree_ >= 0) { - auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2); - int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_; - auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2); - auto available_ram_gigabytes = memfree_ / std::pow(1024, 2); + + unsigned long memtotal = meminfo_["MemTotal"]; + unsigned long memfree; + if (meminfo_.count("MemAvailable")) { + // New kernels (3.4+) have an accurate available memory field. + memfree = meminfo_["MemAvailable"]; + } else { + // Old kernel; give a best-effort approximation of available memory. + memfree = meminfo_["MemFree"] + meminfo_["Buffers"] + meminfo_["Cached"] + + meminfo_["SReclaimable"] - meminfo_["Shmem"]; + } + + if (memtotal > 0 && memfree >= 0) { + auto total_ram_gigabytes = memtotal / std::pow(1024, 2); + int used_ram_percentage = 100 * (memtotal - memfree) / memtotal; + auto used_ram_gigabytes = (memtotal - memfree) / std::pow(1024, 2); + auto available_ram_gigabytes = memfree / std::pow(1024, 2); getState(used_ram_percentage); label_.set_markup(fmt::format(format_, @@ -33,7 +45,6 @@ auto waybar::modules::Memory::update() -> void { } void waybar::modules::Memory::parseMeminfo() { - int64_t memfree = -1, membuffer = -1, memcache = -1, memavail = -1; std::ifstream info(data_dir_); if (!info.is_open()) { throw std::runtime_error("Can't open " + data_dir_); @@ -44,23 +55,9 @@ void waybar::modules::Memory::parseMeminfo() { if (posDelim == std::string::npos) { continue; } + std::string name = line.substr(0, posDelim); int64_t value = std::stol(line.substr(posDelim + 1)); - - if (name.compare("MemTotal") == 0) { - memtotal_ = value; - } else if (name.compare("MemAvailable") == 0) { - memavail = value; - } else if (name.compare("MemFree") == 0) { - memfree = value; - } else if (name.compare("Buffers") == 0) { - membuffer = value; - } else if (name.compare("Cached") == 0) { - memcache = value; - } - if (memtotal_ > 0 && (memavail >= 0 || (memfree > -1 && membuffer > -1 && memcache > -1))) { - break; - } + meminfo_[name] = value; } - memfree_ = memavail >= 0 ? memavail : memfree + membuffer + memcache; } From cb2f5c154c1177da05e16f4c7c62312d6c80e352 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:25:27 +0100 Subject: [PATCH 18/40] feat(custon): restart_interval for continuous script --- man/waybar-custom.5.scd | 6 ++++++ src/modules/custom.cpp | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 0ae7f4c..92eda6c 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -33,6 +33,12 @@ Addressed by *custom/* You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. +*restart_interval*: ++ + typeof: integer ++ + The restart interval (in seconds). + Can't be used with the *interval* option, so only with continuous scripts. + Once the scripts exit, it'll be re-executed after the *restart_interval*. + *signal*: ++ typeof: integer ++ The signal number used to update the module. diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index ca09508..cbc865d 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -55,12 +55,21 @@ void waybar::modules::Custom::continuousWorker() { exit_code = WEXITSTATUS(util::command::close(fp_, pid_)); fp_ = nullptr; } - thread_.stop(); if (exit_code != 0) { output_ = {exit_code, ""}; dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } + if (config_["restart_interval"].isUInt()) { + pid_ = -1; + fp_ = util::command::open(cmd, pid_); + if (!fp_) { + throw std::runtime_error("Unable to open " + cmd); + } + thread_.sleep_for(std::chrono::seconds(config_["restart_interval"].asUInt()); + } else { + thread_.stop(); + } return; } std::string output = buff; From d12ad1128ec606c6c46e851eaa69c2d50393cde2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:30:22 +0100 Subject: [PATCH 19/40] fix: man --- man/waybar-custom.5.scd | 4 ++-- src/modules/custom.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 92eda6c..905dbc1 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -33,11 +33,11 @@ Addressed by *custom/* You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. -*restart_interval*: ++ +*restart-interval*: ++ typeof: integer ++ The restart interval (in seconds). Can't be used with the *interval* option, so only with continuous scripts. - Once the scripts exit, it'll be re-executed after the *restart_interval*. + Once the script exit, it'll be re-executed after the *restart-interval*. *signal*: ++ typeof: integer ++ diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index cbc865d..c81f192 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -60,13 +60,13 @@ void waybar::modules::Custom::continuousWorker() { dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } - if (config_["restart_interval"].isUInt()) { + if (config_["restart-interval"].isUInt()) { pid_ = -1; fp_ = util::command::open(cmd, pid_); if (!fp_) { throw std::runtime_error("Unable to open " + cmd); } - thread_.sleep_for(std::chrono::seconds(config_["restart_interval"].asUInt()); + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()); } else { thread_.stop(); } From ff36154c4bfd23651ba5bcc8e966f825b09ffad7 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:31:04 +0100 Subject: [PATCH 20/40] fix: typo --- src/modules/custom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index c81f192..24cfa71 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -66,7 +66,7 @@ void waybar::modules::Custom::continuousWorker() { if (!fp_) { throw std::runtime_error("Unable to open " + cmd); } - thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()); + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); } else { thread_.stop(); } From 9acf5587fa2e7d3575b06682a8b8d936a995e861 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:53:09 +0100 Subject: [PATCH 21/40] refactor(pulseaudio): fallback to default muted format --- src/modules/pulseaudio.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 3e9a95e..d79e6ae 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -215,7 +215,11 @@ auto waybar::modules::Pulseaudio::update() -> void { } else { label_.get_style_context()->remove_class("bluetooth"); } - if (muted_ ) { + if (muted_) { + // Check muted bluetooth format exist, otherwise fallback to default muted format + if (format_name != "format" && !config_[format_name + "-muted"].isString()) { + format_name = "format"; + } format_name = format_name + "-muted"; label_.get_style_context()->add_class("muted"); } else { From 10b152ac3e28c59c2ec818c5b34351f620420e44 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 26 Mar 2020 09:18:47 +0100 Subject: [PATCH 22/40] fix: process last line, restart-interval --- src/modules/custom.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 24cfa71..71140bf 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -49,6 +49,7 @@ void waybar::modules::Custom::continuousWorker() { thread_ = [&] { char* buff = nullptr; size_t len = 0; + bool restart = false; if (getline(&buff, &len, fp_) == -1) { int exit_code = 1; if (fp_) { @@ -61,16 +62,11 @@ void waybar::modules::Custom::continuousWorker() { spdlog::error("{} stopped unexpectedly, is it endless?", name_); } if (config_["restart-interval"].isUInt()) { - pid_ = -1; - fp_ = util::command::open(cmd, pid_); - if (!fp_) { - throw std::runtime_error("Unable to open " + cmd); - } - thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); + restart = true; } else { thread_.stop(); + return; } - return; } std::string output = buff; @@ -80,6 +76,14 @@ void waybar::modules::Custom::continuousWorker() { } output_ = {0, output}; dp.emit(); + if (restart) { + pid_ = -1; + fp_ = util::command::open(cmd, pid_); + if (!fp_) { + throw std::runtime_error("Unable to open " + cmd); + } + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); + } }; } From af96150f5c0d466045a325a80b7ad8820ccff419 Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Sat, 28 Mar 2020 01:35:21 +0900 Subject: [PATCH 23/40] restore SIGCHLD settings to SIG_DFL. --- include/util/command.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/util/command.hpp b/include/util/command.hpp index 69b1fd4..8db7bfb 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -88,6 +88,7 @@ inline int32_t forkExec(std::string cmd) { // Child executes the command if (!pid) { setpgid(pid, pid); + signal(SIGCHLD, SIG_DFL); execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0); exit(0); } else { From ec451b5908558388608be6bc94794ee4c9f77b81 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Mar 2020 10:36:24 +0200 Subject: [PATCH 24/40] fix(command): check WIFEXITED --- include/util/command.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/util/command.hpp b/include/util/command.hpp index 8db7bfb..f3dd4e1 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -72,7 +72,10 @@ inline struct res exec(std::string cmd) { if (!fp) return {-1, ""}; auto output = command::read(fp); auto stat = command::close(fp, pid); - return {WEXITSTATUS(stat), output}; + if (WIFEXITED(stat)) { + return {WEXITSTATUS(stat), output}; + } + return {-1, output}; } inline int32_t forkExec(std::string cmd) { From bb2c16386b512d5684422045c5c46b872a8f5797 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 4 Apr 2020 21:13:25 +0200 Subject: [PATCH 25/40] feat: format-icon for persistent workspaces --- man/waybar-sway-workspaces.5.scd | 1 + src/modules/sway/workspaces.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index fe38d23..c92b512 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -75,6 +75,7 @@ Additional to workspace name matching, the following *format-icons* can be set. - *default*: Will be shown, when no string matches is found. - *urgent*: Will be shown, when workspace is flagged as urgent - *focused*: Will be shown, when workspace is focused +- *persistent*: Will be shown, when workspace is persistent one. # PERSISTENT WORKSPACES diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index fe87f5e..297935a 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -205,6 +205,8 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node if (config_["format-icons"][key].isString() && node[key].asBool()) { return config_["format-icons"][key].asString(); } + } else if (config_["format_icons"]["persistent"].isString() && node["target_output"].isString()) { + return config_["format-icons"]["persistent"].asString(); } else if (config_["format-icons"][key].isString()) { return config_["format-icons"][key].asString(); } From d5bd3be8de0f7f20f97628969fb328ffb5822b07 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2020 16:12:25 +0200 Subject: [PATCH 26/40] chore: use native git --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index b8185c2..717f36f 100644 --- a/meson.build +++ b/meson.build @@ -25,7 +25,7 @@ else cpp_link_args += ['-lstdc++fs'] endif -git = find_program('git', required: false) +git = find_program('git', native: true, required: false) if not git.found() add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp') From 8e0f3c7ddfb93491d158045677b70498cc616340 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2020 16:56:51 +0200 Subject: [PATCH 27/40] feat: full-at (#649) * feat: full-at * fix(man): typo --- man/waybar-battery.5.scd | 4 ++++ src/modules/battery.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index f96f85c..8bcd2e8 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -18,6 +18,10 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: string ++ The adapter to monitor, as in /sys/class/power_supply/ instead of auto detect. +*full-at* ++ + typeof: integer ++ + Define the max percentage of the battery, usefull for an old battery, e.g. 96 + *interval* ++ typeof: integer ++ default: 60 ++ diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index dfd6753..e7e831c 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -115,6 +115,16 @@ const std::tuple waybar::modules::Battery::getInfos time_remaining = -(float)(total_energy_full - total_energy) / total_power; } uint16_t capacity = total / batteries_.size(); + // Handle full-at + if (config_["full-at"].isUInt()) { + auto full_at = config_["full-at"].asUInt(); + if (full_at < 100) { + capacity = static_cast(capacity / full_at) * 100; + if (capacity > full_at) { + capacity = full_at; + } + } + } return {capacity, time_remaining, status}; } catch (const std::exception& e) { spdlog::error("Battery: {}", e.what()); From 5c5031fd69a511339a1e3b098de77b3c62ecf0de Mon Sep 17 00:00:00 2001 From: JohnHolmesII Date: Sun, 5 Apr 2020 11:42:27 -0700 Subject: [PATCH 28/40] pulse: do not die when a server hasn't been started. wait first. --- src/modules/pulseaudio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index d79e6ae..25c2a20 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -21,7 +21,7 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value if (context_ == nullptr) { throw std::runtime_error("pa_context_new() failed."); } - if (pa_context_connect(context_, nullptr, PA_CONTEXT_NOAUTOSPAWN, nullptr) < 0) { + if (pa_context_connect(context_, nullptr, PA_CONTEXT_NOFAIL, nullptr) < 0) { auto err = fmt::format("pa_context_connect() failed: {}", pa_strerror(pa_context_errno(context_))); throw std::runtime_error(err); From 27fbea2b5afde7fd601aa4e2afb2b3a74c9110bf Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 12:42:04 +0200 Subject: [PATCH 29/40] refactor(workspaces): default value unstripped, fix man --- man/waybar-sway-workspaces.5.scd | 6 ++++-- src/modules/sway/workspaces.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index c92b512..f9ef31d 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -19,7 +19,7 @@ Addressed by *sway/workspaces* *format*: ++ typeof: string ++ - default: {name} ++ + default: {value} ++ The format, how information should be displayed. *format-icons*: ++ @@ -62,7 +62,9 @@ Addressed by *sway/workspaces* # FORMAT REPLACEMENTS -*{name}*: Name of the workspace, as defined by sway. +*{value}*: Name of the workspace, as defined by sway. + +*{name}*: Number stripped from workspace value. *{icon}*: Icon, as defined in *format-icons*. diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 297935a..6aeaaca 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -157,12 +157,13 @@ auto Workspaces::update() -> void { if (needReorder) { box_.reorder_child(button, it - workspaces_.begin()); } - std::string output = getIcon((*it)["name"].asString(), *it); + std::string output = (*it)["name"].asString(); if (config_["format"].isString()) { auto format = config_["format"].asString(); output = fmt::format(format, - fmt::arg("icon", output), - fmt::arg("name", trimWorkspaceName((*it)["name"].asString())), + fmt::arg("icon", getIcon(output, *it)), + fmt::arg("value", output) + fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString())); } if (!config_["disable-markup"].asBool()) { From 7c4ea397749f8afc78d88b2f624b2a0b30a3b81a Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 12:49:41 +0200 Subject: [PATCH 30/40] fix: add missing comma --- src/modules/sway/workspaces.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 6aeaaca..f61c98a 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -162,7 +162,7 @@ auto Workspaces::update() -> void { auto format = config_["format"].asString(); output = fmt::format(format, fmt::arg("icon", getIcon(output, *it)), - fmt::arg("value", output) + fmt::arg("value", output), fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString())); } From ac3126b6cf1d30fb4adedd16f17eefa836b2d860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pla=C3=A7ais?= Date: Fri, 10 Apr 2020 15:45:29 +0200 Subject: [PATCH 31/40] feat(layout): add pugixml dependency to dockerfiles --- Dockerfiles/alpine | 2 +- Dockerfiles/archlinux | 2 +- Dockerfiles/debian | 2 +- Dockerfiles/fedora | 2 +- Dockerfiles/opensuse | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfiles/alpine b/Dockerfiles/alpine index 78a78b6..fec63c2 100644 --- a/Dockerfiles/alpine +++ b/Dockerfiles/alpine @@ -2,4 +2,4 @@ FROM alpine:latest -RUN apk add --no-cache git meson alpine-sdk libinput-dev wayland-dev wayland-protocols mesa-dev libxkbcommon-dev eudev-dev pixman-dev gtkmm3-dev jsoncpp-dev libnl3-dev pulseaudio-dev libmpdclient-dev scdoc +RUN apk add --no-cache git meson alpine-sdk libinput-dev wayland-dev wayland-protocols mesa-dev libxkbcommon-dev eudev-dev pixman-dev gtkmm3-dev jsoncpp-dev pugixml libnl3-dev pulseaudio-dev libmpdclient-dev scdoc diff --git a/Dockerfiles/archlinux b/Dockerfiles/archlinux index 9197fb8..b640ce7 100644 --- a/Dockerfiles/archlinux +++ b/Dockerfiles/archlinux @@ -3,4 +3,4 @@ FROM archlinux/base:latest RUN pacman -Syu --noconfirm && \ - pacman -S git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp scdoc --noconfirm + pacman -S git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp pugixml scdoc --noconfirm diff --git a/Dockerfiles/debian b/Dockerfiles/debian index 8d7a065..eedbcfb 100644 --- a/Dockerfiles/debian +++ b/Dockerfiles/debian @@ -3,5 +3,5 @@ FROM debian:sid RUN apt-get update && \ - apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc && \ + apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libpugixml-dev libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc && \ apt-get clean diff --git a/Dockerfiles/fedora b/Dockerfiles/fedora index af88607..7bd9d76 100644 --- a/Dockerfiles/fedora +++ b/Dockerfiles/fedora @@ -2,6 +2,6 @@ FROM fedora:30 -RUN dnf install sway meson git libinput-devel wayland-devel wayland-protocols-devel egl-wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-libgbm-devel libxkbcommon-devel libudev-devel pixman-devel gtkmm30-devel jsoncpp-devel scdoc -y && \ +RUN dnf install sway meson git libinput-devel wayland-devel wayland-protocols-devel pugixml-devel egl-wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-libgbm-devel libxkbcommon-devel libudev-devel pixman-devel gtkmm30-devel jsoncpp-devel scdoc -y && \ dnf group install "C Development Tools and Libraries" -y && \ dnf clean all -y diff --git a/Dockerfiles/opensuse b/Dockerfiles/opensuse index c54777e..af1be95 100644 --- a/Dockerfiles/opensuse +++ b/Dockerfiles/opensuse @@ -4,4 +4,4 @@ FROM opensuse/tumbleweed:latest RUN zypper -n up && \ zypper -n install -t pattern devel_C_C++ && \ - zypper -n install git meson clang libinput10 libinput-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc + zypper -n install git meson clang libinput10 libinput-devel libpugixml1 libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc From 8f6273e9d005114676c51cf788165d6204c6e229 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Apr 2020 12:08:21 +0200 Subject: [PATCH 32/40] refactor(config): comment default config layer --- resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/config b/resources/config index 237c787..832f76c 100644 --- a/resources/config +++ b/resources/config @@ -1,5 +1,5 @@ { - "layer": "top", // Waybar at top layer + // "layer": "top", // Waybar at top layer // "position": "bottom", // Waybar position (top|bottom|left|right) "height": 30, // Waybar height (to be removed for auto height) // "width": 1280, // Waybar width From b9338c72c9dddac9d38c76b23aa3502557982a19 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Apr 2020 12:24:49 +0200 Subject: [PATCH 33/40] chore: 0.9.2 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 717f36f..1dab13d 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'waybar', 'cpp', 'c', - version: '0.9.1', + version: '0.9.2', license: 'MIT', default_options : [ 'cpp_std=c++17', From b40cdcb5bd995a117e581343c69512536bf1ff31 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Apr 2020 18:30:21 +0200 Subject: [PATCH 34/40] refactor: call parent update --- src/ALabel.cpp | 2 +- src/AModule.cpp | 5 ++++- src/modules/backlight.cpp | 2 ++ src/modules/battery.cpp | 7 ++----- src/modules/clock.cpp | 7 ++----- src/modules/cpu.cpp | 7 ++----- src/modules/custom.cpp | 7 ++----- src/modules/disk.cpp | 2 ++ src/modules/idle_inhibitor.cpp | 7 ++----- src/modules/memory.cpp | 7 ++----- src/modules/mpd.cpp | 8 +++----- src/modules/network.cpp | 8 +++----- src/modules/pulseaudio.cpp | 10 ++++------ src/modules/sway/mode.cpp | 2 ++ src/modules/sway/window.cpp | 2 ++ src/modules/sway/workspaces.cpp | 2 ++ src/modules/temperature.cpp | 7 ++----- 17 files changed, 39 insertions(+), 53 deletions(-) diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 3d9f2b2..e251f0d 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -31,7 +31,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st } auto ALabel::update() -> void { - // Nothing here + AModule::update(); } std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) { diff --git a/src/AModule.cpp b/src/AModule.cpp index da43259..3066bfc 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -29,7 +29,10 @@ AModule::~AModule() { } auto AModule::update() -> void { - pid_.push_back(util::command::forkExec(config_["on-update"].asString())); + // Run user-provided update handler if configured + if (config_["on-update"].isString()) { + pid_.push_back(util::command::forkExec(config_["on-update"].asString())); + } } bool AModule::handleToggle(GdkEventButton* const& e) { diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 8b63bd6..759c7c6 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -192,6 +192,8 @@ auto waybar::modules::Backlight::update() -> void { } previous_best_ = best == nullptr ? std::nullopt : std::optional{*best}; previous_format_ = format_; + // Call parent update + ALabel::update(); } template diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index b50c38a..632abd9 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -149,11 +149,6 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai } auto waybar::modules::Battery::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - auto [capacity, time_remaining, status] = getInfos(); if (status == "Unknown") { status = getAdapterStatus(capacity); @@ -192,4 +187,6 @@ auto waybar::modules::Battery::update() -> void { fmt::arg("icon", getIcon(capacity, state)), fmt::arg("time", formatTimeRemaining(time_remaining)))); } + // Call parent update + ALabel::update(); } diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5a781ef..4e05868 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -13,11 +13,6 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } auto waybar::modules::Clock::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - tzset(); // Update timezone information auto now = std::chrono::system_clock::now(); auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); @@ -33,4 +28,6 @@ auto waybar::modules::Clock::update() -> void { label_.set_tooltip_text(text); } } + // Call parent update + ALabel::update(); } diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 33d0d53..a0f646f 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -10,11 +10,6 @@ waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config) } auto waybar::modules::Cpu::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both auto cpu_load = getCpuLoad(); auto [cpu_usage, tooltip] = getCpuUsage(); @@ -23,6 +18,8 @@ auto waybar::modules::Cpu::update() -> void { } label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage))); getState(cpu_usage); + // Call parent update + ALabel::update(); } uint16_t waybar::modules::Cpu::getCpuLoad() { diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 1853b2f..7a66447 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -93,11 +93,6 @@ bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) { } auto waybar::modules::Custom::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - // Hide label if output is empty if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) { event_box_.hide(); @@ -133,6 +128,8 @@ auto waybar::modules::Custom::update() -> void { event_box_.show(); } } + // Call parent update + ALabel::update(); } void waybar::modules::Custom::parseOutputRaw() { diff --git a/src/modules/disk.cpp b/src/modules/disk.cpp index 811fe72..87240de 100644 --- a/src/modules/disk.cpp +++ b/src/modules/disk.cpp @@ -73,4 +73,6 @@ auto waybar::modules::Disk::update() -> void { )); } event_box_.show(); + // Call parent update + ALabel::update(); } diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index c39e011..d94e957 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -26,17 +26,14 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { } auto waybar::modules::IdleInhibitor::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - label_.set_markup( fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); label_.get_style_context()->add_class(status_); if (tooltipEnabled()) { label_.set_tooltip_text(status_); } + // Call parent update + ALabel::update(); } bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index 3e1ed74..c5b8b40 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -9,11 +9,6 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config } auto waybar::modules::Memory::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - parseMeminfo(); if (memtotal_ > 0 && memfree_ >= 0) { auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2); @@ -35,6 +30,8 @@ auto waybar::modules::Memory::update() -> void { } else { event_box_.hide(); } + // Call parent update + ALabel::update(); } void waybar::modules::Memory::parseMeminfo() { diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index f61dfc4..6dca5ee 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -35,11 +35,6 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config) } auto waybar::modules::MPD::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - std::lock_guard guard(connection_lock_); tryConnect(); @@ -61,6 +56,9 @@ auto waybar::modules::MPD::update() -> void { } setLabel(); + + // Call parent update + ALabel::update(); } std::thread waybar::modules::MPD::event_listener() { diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 9513a93..54a92ba 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -228,11 +228,6 @@ const std::string waybar::modules::Network::getNetworkState() const { } auto waybar::modules::Network::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - std::lock_guard lock(mutex_); std::string tooltip_format; auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); @@ -314,6 +309,9 @@ auto waybar::modules::Network::update() -> void { label_.set_tooltip_text(text); } } + + // Call parent update + ALabel::update(); } // Based on https://gist.github.com/Yawning/c70d804d4b8ae78cc698 diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index e336825..06c0ad8 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -196,11 +196,6 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const { } auto waybar::modules::Pulseaudio::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - auto format = format_; std::string format_name = "format"; if (monitor_.find("a2dp_sink") != std::string::npos) { @@ -215,7 +210,7 @@ auto waybar::modules::Pulseaudio::update() -> void { } else { label_.get_style_context()->remove_class("muted"); } - format = + format = config_[format_name].isString() ? config_[format_name].asString() : format; // TODO: find a better way to split source/sink std::string format_source = "{volume}%"; @@ -234,4 +229,7 @@ auto waybar::modules::Pulseaudio::update() -> void { if (tooltipEnabled()) { label_.set_tooltip_text(desc_); } + + // Call parent update + ALabel::update(); } diff --git a/src/modules/sway/mode.cpp b/src/modules/sway/mode.cpp index cd02c0c..33e4f72 100644 --- a/src/modules/sway/mode.cpp +++ b/src/modules/sway/mode.cpp @@ -51,6 +51,8 @@ auto Mode::update() -> void { } event_box_.show(); } + // Call parent update + ALabel::update(); } } // namespace waybar::modules::sway diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 2e4ec46..1f90eba 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -64,6 +64,8 @@ auto Window::update() -> void { if (tooltipEnabled()) { label_.set_tooltip_text(window_); } + // Call parent update + ALabel::update(); } std::tuple Window::getFocusedNode( diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index b65e47d..d0c8cc3 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -176,6 +176,8 @@ auto Workspaces::update() -> void { } onButtonReady(*it, button); } + // Call parent update + AModule::update(); } Gtk::Button &Workspaces::addButton(const Json::Value &node) { diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index d17c2ad..5508fd2 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -19,11 +19,6 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val } auto waybar::modules::Temperature::update() -> void { - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - auto [temperature_c, temperature_f] = getTemperature(); auto critical = isCritical(temperature_c); auto format = format_; @@ -38,6 +33,8 @@ auto waybar::modules::Temperature::update() -> void { fmt::arg("temperatureC", temperature_c), fmt::arg("temperatureF", temperature_f), fmt::arg("icon", getIcon(temperature_c, "", max_temp)))); + // Call parent update + ALabel::update(); } std::tuple waybar::modules::Temperature::getTemperature() { From 687c50dc137c43eb519a227db03625f1a2ffbc97 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Apr 2020 18:31:07 +0200 Subject: [PATCH 35/40] refactor: remove old stuff --- src/modules/backlight.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 759c7c6..6349dbb 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -175,11 +175,6 @@ auto waybar::modules::Backlight::update() -> void { return; } - // Run user-provided update handler if configured - if (config_["on-update"].isString()) { - AModule::update(); - } - const auto percent = best->get_max() == 0 ? 100 : best->get_actual() * 100 / best->get_max(); label_.set_markup(fmt::format( format_, fmt::arg("percent", std::to_string(percent)), fmt::arg("icon", getIcon(percent)))); From d1c4897f3196bf1d1a24cac7fe27349a6cc25161 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Apr 2020 18:35:41 +0200 Subject: [PATCH 36/40] feat: update man --- man/waybar-backlight.5.scd | 6 +++++- man/waybar-battery.5.scd | 6 +++++- man/waybar-clock.5.scd | 4 ++++ man/waybar-cpu.5.scd | 4 ++++ man/waybar-custom.5.scd | 4 ++++ man/waybar-disk.5.scd | 4 ++++ man/waybar-idle-inhibitor.5.scd | 4 ++++ man/waybar-memory.5.scd | 4 ++++ man/waybar-mpd.5.scd | 4 ++++ man/waybar-network.5.scd | 4 ++++ man/waybar-pulseaudio.5.scd | 4 ++++ man/waybar-sway-mode.5.scd | 4 ++++ man/waybar-sway-window.5.scd | 4 ++++ man/waybar-sway-workspaces.5.scd | 4 ++++ man/waybar-temperature.5.scd | 4 ++++ man/waybar-tray.5.scd | 4 ++++ src/modules/sni/tray.cpp | 2 ++ 17 files changed, 68 insertions(+), 2 deletions(-) diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index 5f2bb82..2ebfe7c 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -40,10 +40,14 @@ The *backlight* module displays the current backlight level. typeof: string ++ Command to execute when middle-clicked on the module using mousewheel. -*on-click-right* ++ +*on-click-right*: ++ typeof: string ++ Command to execute when the module is right clicked. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up* ++ typeof: string ++ Command to execute when performing a scroll up on the module. diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 8bcd2e8..3b67fd7 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -62,10 +62,14 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: string ++ Command to execute when middle-clicked on the module using mousewheel. -*on-click-right* ++ +*on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index 6684d89..3610f19 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -51,6 +51,10 @@ The *clock* module displays the current date and time. typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index 27dde96..cb83134 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -44,6 +44,10 @@ The *cpu* module displays the current cpu utilization. typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 905dbc1..121585a 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -73,6 +73,10 @@ Addressed by *custom/* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-disk.5.scd b/man/waybar-disk.5.scd index 25d00b1..1a9320c 100644 --- a/man/waybar-disk.5.scd +++ b/man/waybar-disk.5.scd @@ -47,6 +47,10 @@ Addressed by *disk* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 1fba291..9d231d8 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -39,6 +39,10 @@ screensaving, also known as "presentation mode". typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index 70718e1..81c6216 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -46,6 +46,10 @@ Addressed by *memory* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index fc3b1b3..1ee7a98 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -89,6 +89,10 @@ Addressed by *mpd* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index a557aa3..6bf2c94 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -72,6 +72,10 @@ Addressed by *network* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index 487888a..c3f50e0 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -67,6 +67,10 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. This replaces the default behaviour of volume control. diff --git a/man/waybar-sway-mode.5.scd b/man/waybar-sway-mode.5.scd index 85a25d1..958a1ed 100644 --- a/man/waybar-sway-mode.5.scd +++ b/man/waybar-sway-mode.5.scd @@ -37,6 +37,10 @@ Addressed by *sway/mode* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 6a9d4e3..4863a76 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -37,6 +37,10 @@ Addressed by *sway/window* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index f9ef31d..18fe6f4 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -60,6 +60,10 @@ Addressed by *sway/workspaces* default: empty ++ Lists workspaces that should always be shown, even when non existent +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + # FORMAT REPLACEMENTS *{value}*: Name of the workspace, as defined by sway. diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index eeae546..7c25e88 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -70,6 +70,10 @@ Addressed by *temperature* typeof: string ++ Command to execute when you right clicked on the module. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + *on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. diff --git a/man/waybar-tray.5.scd b/man/waybar-tray.5.scd index bb4510d..cd0e93f 100644 --- a/man/waybar-tray.5.scd +++ b/man/waybar-tray.5.scd @@ -20,6 +20,10 @@ Addressed by *tray* typeof: integer ++ Defines the spacing between the tray icons. +*on-update*: ++ + typeof: string ++ + Command to execute when the module is updated. + # EXAMPLES ``` diff --git a/src/modules/sni/tray.cpp b/src/modules/sni/tray.cpp index e16837f..ae3702c 100644 --- a/src/modules/sni/tray.cpp +++ b/src/modules/sni/tray.cpp @@ -40,6 +40,8 @@ auto Tray::update() -> void { } else { box_.show_all(); } + // Call parent update + AModule::update(); } } // namespace waybar::modules::SNI From acc3ae6e625bb1d34a53ab28d7a19b72f64611bc Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Apr 2020 18:41:44 +0200 Subject: [PATCH 37/40] refactor(man): add missing : --- man/waybar-backlight.5.scd | 18 +++++++++--------- man/waybar-battery.5.scd | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index 2ebfe7c..e6116e3 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -10,29 +10,29 @@ The *backlight* module displays the current backlight level. # CONFIGURATION -*interval* ++ +*interval*: ++ typeof: integer ++ default: 2 ++ The interval in which information gets polled. -*format* ++ +*format*: ++ typeof: string ++ default: {percent}% ++ The format, how information should be displayed. On {} data gets inserted. -*max-length* ++ +*max-length*: ++ typeof: integer ++ The maximum length in characters the module should display. -*rotate* ++ +*rotate*: ++ typeof: integer ++ Positive value to rotate the text label. -*states* ++ +*states*: ++ typeof: array ++ A number of backlight states which get activated on certain brightness levels. -*on-click* ++ +*on-click*: ++ typeof: string ++ Command to execute when the module is clicked. @@ -48,15 +48,15 @@ The *backlight* module displays the current backlight level. typeof: string ++ Command to execute when the module is updated. -*on-scroll-up* ++ +*on-scroll-up*: ++ typeof: string ++ Command to execute when performing a scroll up on the module. -*on-scroll-down* ++ +*on-scroll-down*: ++ typeof: string Command to execute when performing a scroll down on the module. -*smooth-scrolling-threshold* ++ +*smooth-scrolling-threshold*: ++ typeof: double Threshold to be used when scrolling. diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 3b67fd7..75d4108 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -10,33 +10,33 @@ The *battery* module displays the current capacity and state (eg. charging) of y # CONFIGURATION -*bat* ++ +*bat*: ++ typeof: string ++ The battery to monitor, as in /sys/class/power_supply/ instead of auto detect. -*adapter* ++ +*adapter*: ++ typeof: string ++ The adapter to monitor, as in /sys/class/power_supply/ instead of auto detect. -*full-at* ++ +*full-at*: ++ typeof: integer ++ Define the max percentage of the battery, usefull for an old battery, e.g. 96 -*interval* ++ +*interval*: ++ typeof: integer ++ default: 60 ++ The interval in which the information gets polled. -*states* ++ +*states*: ++ typeof: array ++ A number of battery states which get activated on certain capacity levels. See *waybar-states(5)*. -*format* ++ +*format*: ++ typeof: string ++ default: {capacity}% ++ The format, how the time should be displayed. -*format-time* ++ +*format-time*: ++ typeof: string ++ default: {H} h {M} min ++ The format, how the time should be displayed. @@ -78,11 +78,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: string ++ Command to execute when scrolling down on the module. -*smooth-scrolling-threshold* ++ +*smooth-scrolling-threshold*: ++ typeof: double ++ Threshold to be used when scrolling. -*tooltip* ++ +*tooltip*: ++ typeof: bool ++ default: true ++ Option to disable tooltip on hover. From 345c7da384ad238960d8ef3dcba9659430f0644c Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 13 Apr 2020 17:07:16 +0200 Subject: [PATCH 38/40] chore: update fedora base --- .travis.yml | 1 + Dockerfiles/fedora | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a853829..fd94669 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ env: - distro: archlinux - distro: fedora - distro: alpine + - distro: opensuse before_install: - docker pull alexays/waybar:${distro} diff --git a/Dockerfiles/fedora b/Dockerfiles/fedora index 7bd9d76..d75083c 100644 --- a/Dockerfiles/fedora +++ b/Dockerfiles/fedora @@ -1,6 +1,6 @@ # vim: ft=Dockerfile -FROM fedora:30 +FROM fedora:32 RUN dnf install sway meson git libinput-devel wayland-devel wayland-protocols-devel pugixml-devel egl-wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-libgbm-devel libxkbcommon-devel libudev-devel pixman-devel gtkmm30-devel jsoncpp-devel scdoc -y && \ dnf group install "C Development Tools and Libraries" -y && \ From 09ec40e38dcbb1553ed62a3ad2a3f8b47f5c5247 Mon Sep 17 00:00:00 2001 From: Danilo Spinella Date: Mon, 13 Apr 2020 18:02:50 +0200 Subject: [PATCH 39/40] fix(memory): add missing unordered_map include --- include/modules/memory.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index 5b0f51b..59f0e78 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" From 4e19ec93dc607f7949499c354ed6369c63d5fd35 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 17 Apr 2020 09:09:30 +0200 Subject: [PATCH 40/40] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index be45818..00e56e5 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ - Local time - Battery - Network +- Bluetooth - Pulseaudio - Disk - Memory