Use labels instead of buttons
This commit is contained in:
parent
888adb57ec
commit
982ffde002
|
@ -9,12 +9,12 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "AButton.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
class CpuFrequency : public AButton {
|
class CpuFrequency : public ALabel {
|
||||||
public:
|
public:
|
||||||
CpuFrequency(const std::string&, const Json::Value&);
|
CpuFrequency(const std::string&, const Json::Value&);
|
||||||
~CpuFrequency() = default;
|
~CpuFrequency() = default;
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "AButton.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
class CpuUsage : public AButton {
|
class CpuUsage : public ALabel {
|
||||||
public:
|
public:
|
||||||
CpuUsage(const std::string&, const Json::Value&);
|
CpuUsage(const std::string&, const Json::Value&);
|
||||||
~CpuUsage() = default;
|
~CpuUsage() = default;
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "AButton.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
class Load : public AButton {
|
class Load : public ALabel {
|
||||||
public:
|
public:
|
||||||
Load(const std::string&, const Json::Value&);
|
Load(const std::string&, const Json::Value&);
|
||||||
~Load() = default;
|
~Load() = default;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
waybar::modules::CpuFrequency::CpuFrequency(const std::string& id, const Json::Value& config)
|
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] {
|
thread_ = [this] {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
thread_.sleep_for(interval_);
|
thread_.sleep_for(interval_);
|
||||||
|
@ -24,7 +24,7 @@ auto waybar::modules::CpuFrequency::update() -> void {
|
||||||
auto tooltip =
|
auto tooltip =
|
||||||
fmt::format("Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n",
|
fmt::format("Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n",
|
||||||
min_frequency, avg_frequency, max_frequency);
|
min_frequency, avg_frequency, max_frequency);
|
||||||
button_.set_tooltip_text(tooltip);
|
label_.set_tooltip_text(tooltip);
|
||||||
}
|
}
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
auto state = getState(avg_frequency);
|
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("max_frequency", max_frequency));
|
||||||
store.push_back(fmt::arg("min_frequency", min_frequency));
|
store.push_back(fmt::arg("min_frequency", min_frequency));
|
||||||
store.push_back(fmt::arg("avg_frequency", avg_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
|
// Call parent update
|
||||||
AButton::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<float, float, float> waybar::modules::CpuFrequency::getCpuFrequency() {
|
std::tuple<float, float, float> waybar::modules::CpuFrequency::getCpuFrequency() {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
waybar::modules::CpuUsage::CpuUsage(const std::string& id, const Json::Value& config)
|
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] {
|
thread_ = [this] {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
thread_.sleep_for(interval_);
|
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
|
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
|
||||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
button_.set_tooltip_text(tooltip);
|
label_.set_tooltip_text(tooltip);
|
||||||
}
|
}
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];
|
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);
|
auto icon_format = fmt::format("icon{}", core_i);
|
||||||
store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons)));
|
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
|
// Call parent update
|
||||||
AButton::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::vector<uint16_t>, std::string> waybar::modules::CpuUsage::getCpuUsage() {
|
std::tuple<std::vector<uint16_t>, std::string> waybar::modules::CpuUsage::getCpuUsage() {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
waybar::modules::Load::Load(const std::string& id, const Json::Value& config)
|
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] {
|
thread_ = [this] {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
thread_.sleep_for(interval_);
|
thread_.sleep_for(interval_);
|
||||||
|
@ -22,7 +22,7 @@ auto waybar::modules::Load::update() -> void {
|
||||||
auto [load1, load5, load15] = getLoad();
|
auto [load1, load5, load15] = getLoad();
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
auto tooltip = fmt::format("Load 1: {}\nLoad 5: {}\nLoad 15: {}", load1, load5, load15);
|
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 format = format_;
|
||||||
auto state = getState(load1);
|
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("icon1", getIcon(load1, icons)));
|
||||||
store.push_back(fmt::arg("icon5", getIcon(load5, icons)));
|
store.push_back(fmt::arg("icon5", getIcon(load5, icons)));
|
||||||
store.push_back(fmt::arg("icon15", getIcon(load15, 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
|
// Call parent update
|
||||||
AButton::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<double, double, double> waybar::modules::Load::getLoad() {
|
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;
|
double load15 = std::ceil(load[2] * 100.0) / 100.0;
|
||||||
return {load1, load5, load15};
|
return {load1, load5, load15};
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Can't get Cpu load");
|
throw std::runtime_error("Can't get Load");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue