Skip to content

Commit

Permalink
Use labels instead of buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhat committed Jul 29, 2023
1 parent 7469890 commit 9c387e3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions include/modules/cpu_frequency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/cpu_usage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/modules/cpu_frequency/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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);
Expand All @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/cpu_usage/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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];
Expand All @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions src/modules/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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);
Expand All @@ -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() {
Expand All @@ -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");
}

0 comments on commit 9c387e3

Please sign in to comment.