Use labels instead of buttons

This commit is contained in:
Mann mit Hut 2023-04-14 01:25:13 +02:00
parent 888adb57ec
commit 982ffde002
No known key found for this signature in database
GPG Key ID: 02D4D60B8250CB8C
6 changed files with 19 additions and 19 deletions

View File

@ -9,12 +9,12 @@
#include <utility>
#include <vector>
#include "AButton.hpp"
#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
class CpuFrequency : public AButton {
class CpuFrequency : public ALabel {
public:
CpuFrequency(const std::string&, const Json::Value&);
~CpuFrequency() = default;

View File

@ -9,12 +9,12 @@
#include <utility>
#include <vector>
#include "AButton.hpp"
#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
class CpuUsage : public AButton {
class CpuUsage : public ALabel {
public:
CpuUsage(const std::string&, const Json::Value&);
~CpuUsage() = default;

View File

@ -9,12 +9,12 @@
#include <utility>
#include <vector>
#include "AButton.hpp"
#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
class Load : public AButton {
class Load : public ALabel {
public:
Load(const std::string&, const Json::Value&);
~Load() = default;

View File

@ -10,7 +10,7 @@
#endif
waybar::modules::CpuFrequency::CpuFrequency(const std::string& id, const Json::Value& config)
: AButton(config, "cpu_frequency", id, "{avg_frequency}", 10) {
: ALabel(config, "cpu_frequency", id, "{avg_frequency}", 10) {
thread_ = [this] {
dp.emit();
thread_.sleep_for(interval_);
@ -24,7 +24,7 @@ auto waybar::modules::CpuFrequency::update() -> void {
auto tooltip =
fmt::format("Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n",
min_frequency, avg_frequency, max_frequency);
button_.set_tooltip_text(tooltip);
label_.set_tooltip_text(tooltip);
}
auto format = format_;
auto state = getState(avg_frequency);
@ -42,11 +42,11 @@ auto waybar::modules::CpuFrequency::update() -> void {
store.push_back(fmt::arg("max_frequency", max_frequency));
store.push_back(fmt::arg("min_frequency", min_frequency));
store.push_back(fmt::arg("avg_frequency", avg_frequency));
label_->set_markup(fmt::vformat(format, store));
label_.set_markup(fmt::vformat(format, store));
}
// Call parent update
AButton::update();
ALabel::update();
}
std::tuple<float, float, float> waybar::modules::CpuFrequency::getCpuFrequency() {

View File

@ -10,7 +10,7 @@
#endif
waybar::modules::CpuUsage::CpuUsage(const std::string& id, const Json::Value& config)
: AButton(config, "cpu_usage", id, "{usage}%", 10) {
: ALabel(config, "cpu_usage", id, "{usage}%", 10) {
thread_ = [this] {
dp.emit();
thread_.sleep_for(interval_);
@ -21,7 +21,7 @@ auto waybar::modules::CpuUsage::update() -> void {
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
auto [cpu_usage, tooltip] = getCpuUsage();
if (tooltipEnabled()) {
button_.set_tooltip_text(tooltip);
label_.set_tooltip_text(tooltip);
}
auto format = format_;
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];
@ -45,11 +45,11 @@ auto waybar::modules::CpuUsage::update() -> void {
auto icon_format = fmt::format("icon{}", core_i);
store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons)));
}
label_->set_markup(fmt::vformat(format, store));
label_.set_markup(fmt::vformat(format, store));
}
// Call parent update
AButton::update();
ALabel::update();
}
std::tuple<std::vector<uint16_t>, std::string> waybar::modules::CpuUsage::getCpuUsage() {

View File

@ -10,7 +10,7 @@
#endif
waybar::modules::Load::Load(const std::string& id, const Json::Value& config)
: AButton(config, "load", id, "{load1}", 10) {
: ALabel(config, "load", id, "{load1}", 10) {
thread_ = [this] {
dp.emit();
thread_.sleep_for(interval_);
@ -22,7 +22,7 @@ auto waybar::modules::Load::update() -> void {
auto [load1, load5, load15] = getLoad();
if (tooltipEnabled()) {
auto tooltip = fmt::format("Load 1: {}\nLoad 5: {}\nLoad 15: {}", load1, load5, load15);
button_.set_tooltip_text(tooltip);
label_.set_tooltip_text(tooltip);
}
auto format = format_;
auto state = getState(load1);
@ -42,11 +42,11 @@ auto waybar::modules::Load::update() -> void {
store.push_back(fmt::arg("icon1", getIcon(load1, icons)));
store.push_back(fmt::arg("icon5", getIcon(load5, icons)));
store.push_back(fmt::arg("icon15", getIcon(load15, icons)));
label_->set_markup(fmt::vformat(format, store));
label_.set_markup(fmt::vformat(format, store));
}
// Call parent update
AButton::update();
ALabel::update();
}
std::tuple<double, double, double> waybar::modules::Load::getLoad() {
@ -57,5 +57,5 @@ std::tuple<double, double, double> waybar::modules::Load::getLoad() {
double load15 = std::ceil(load[2] * 100.0) / 100.0;
return {load1, load5, load15};
}
throw std::runtime_error("Can't get Cpu load");
throw std::runtime_error("Can't get Load");
}