modules: Revert button to label

This commit is contained in:
Simon Plakolb 2022-11-24 12:28:52 +01:00
parent 74fa131ebe
commit 5e9bbe5c76
43 changed files with 270 additions and 265 deletions

View File

@ -5,7 +5,7 @@
#include <string_view> #include <string_view>
#include <vector> #include <vector>
#include "AButton.hpp" #include "ALabel.hpp"
#include "util/json.hpp" #include "util/json.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
@ -14,7 +14,7 @@ struct udev_device;
namespace waybar::modules { namespace waybar::modules {
class Backlight : public AButton { class Backlight : public ALabel {
class BacklightDev { class BacklightDev {
public: public:
BacklightDev() = default; BacklightDev() = default;

View File

@ -15,7 +15,7 @@
#include <string> #include <string>
#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 {
@ -26,7 +26,7 @@ namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem; namespace fs = std::filesystem;
#endif #endif
class Battery : public AButton { class Battery : public ALabel {
public: public:
Battery(const std::string&, const Json::Value&); Battery(const std::string&, const Json::Value&);
~Battery(); ~Battery();

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "AButton.hpp" #include "ALabel.hpp"
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
#include "util/rfkill.hpp" #include "util/rfkill.hpp"
#endif #endif
@ -12,7 +12,7 @@
namespace waybar::modules { namespace waybar::modules {
class Bluetooth : public AButton { class Bluetooth : public ALabel {
struct ControllerInfo { struct ControllerInfo {
std::string path; std::string path;
std::string address; std::string address;

View File

@ -2,7 +2,7 @@
#include <date/tz.h> #include <date/tz.h>
#include "AButton.hpp" #include "ALabel.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
namespace waybar { namespace waybar {
@ -14,7 +14,7 @@ namespace modules {
const std::string kCalendarPlaceholder = "calendar"; const std::string kCalendarPlaceholder = "calendar";
const std::string KTimezonedTimeListPlaceholder = "timezoned_time_list"; const std::string KTimezonedTimeListPlaceholder = "timezoned_time_list";
class Clock : public AButton { class Clock : public ALabel {
public: public:
Clock(const std::string&, const Json::Value&); Clock(const std::string&, const Json::Value&);
~Clock() = default; ~Clock() = default;

View File

@ -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 Cpu : public AButton { class Cpu : public ALabel {
public: public:
Cpu(const std::string&, const Json::Value&); Cpu(const std::string&, const Json::Value&);
~Cpu() = default; ~Cpu() = default;

View File

@ -5,14 +5,14 @@
#include <csignal> #include <csignal>
#include <string> #include <string>
#include "AButton.hpp" #include "ALabel.hpp"
#include "util/command.hpp" #include "util/command.hpp"
#include "util/json.hpp" #include "util/json.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
namespace waybar::modules { namespace waybar::modules {
class Custom : public AButton { class Custom : public ALabel {
public: public:
Custom(const std::string&, const std::string&, const Json::Value&); Custom(const std::string&, const std::string&, const Json::Value&);
~Custom(); ~Custom();

View File

@ -5,13 +5,13 @@
#include <fstream> #include <fstream>
#include "AButton.hpp" #include "ALabel.hpp"
#include "util/format.hpp" #include "util/format.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
namespace waybar::modules { namespace waybar::modules {
class Disk : public AButton { class Disk : public ALabel {
public: public:
Disk(const std::string&, const Json::Value&); Disk(const std::string&, const Json::Value&);
~Disk() = default; ~Disk() = default;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <list>
#include <functional> #include <functional>
#include <list>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>

View File

@ -1,14 +1,13 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "AButton.hpp" #include "ALabel.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "modules/hyprland/backend.hpp" #include "modules/hyprland/backend.hpp"
#include "util/json.hpp" #include "util/json.hpp"
namespace waybar::modules::hyprland { namespace waybar::modules::hyprland {
class Language : public waybar::AButton, class Language : public waybar::ALabel, public EventHandler {
public EventHandler {
public: public:
Language(const std::string&, const waybar::Bar&, const Json::Value&); Language(const std::string&, const waybar::Bar&, const Json::Value&);
~Language(); ~Language();

View File

@ -9,8 +9,7 @@
namespace waybar::modules::hyprland { namespace waybar::modules::hyprland {
class Window : public waybar::ALabel, class Window : public waybar::ALabel, public EventHandler {
public EventHandler {
public: public:
Window(const std::string&, const waybar::Bar&, const Json::Value&); Window(const std::string&, const waybar::Bar&, const Json::Value&);
~Window(); ~Window();

View File

@ -2,13 +2,13 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "AButton.hpp" #include "ALabel.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "client.hpp" #include "client.hpp"
namespace waybar::modules { namespace waybar::modules {
class IdleInhibitor : public AButton { class IdleInhibitor : public ALabel {
sigc::connection timeout_; sigc::connection timeout_;
public: public:

View File

@ -4,12 +4,12 @@
#include <memory> #include <memory>
#include "AButton.hpp" #include "ALabel.hpp"
#include "bar.hpp" #include "bar.hpp"
namespace waybar::modules { namespace waybar::modules {
class Inhibitor : public AButton { class Inhibitor : public ALabel {
public: public:
Inhibitor(const std::string&, const waybar::Bar&, const Json::Value&); Inhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
~Inhibitor() override; ~Inhibitor() override;

View File

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

View File

@ -7,12 +7,12 @@
#include <condition_variable> #include <condition_variable>
#include <thread> #include <thread>
#include "AButton.hpp" #include "ALabel.hpp"
#include "modules/mpd/state.hpp" #include "modules/mpd/state.hpp"
namespace waybar::modules { namespace waybar::modules {
class MPD : public AButton { class MPD : public ALabel {
friend class detail::Context; friend class detail::Context;
// State machine // State machine

View File

@ -7,7 +7,7 @@
#include <condition_variable> #include <condition_variable>
#include <thread> #include <thread>
#include "AButton.hpp" #include "ALabel.hpp"
namespace waybar::modules { namespace waybar::modules {
class MPD; class MPD;

View File

@ -10,7 +10,7 @@
#include <optional> #include <optional>
#include "AButton.hpp" #include "ALabel.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
#include "util/rfkill.hpp" #include "util/rfkill.hpp"
@ -18,7 +18,7 @@
namespace waybar::modules { namespace waybar::modules {
class Network : public AButton { class Network : public ALabel {
public: public:
Network(const std::string&, const Json::Value&); Network(const std::string&, const Json::Value&);
~Network(); ~Network();

View File

@ -7,11 +7,11 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include "AButton.hpp" #include "ALabel.hpp"
namespace waybar::modules { namespace waybar::modules {
class Pulseaudio : public AButton { class Pulseaudio : public ALabel {
public: public:
Pulseaudio(const std::string&, const Json::Value&); Pulseaudio(const std::string&, const Json::Value&);
~Pulseaudio(); ~Pulseaudio();

View File

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

View File

@ -4,12 +4,12 @@
#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 Sndio : public AButton { class Sndio : public ALabel {
public: public:
Sndio(const std::string &, const Json::Value &); Sndio(const std::string &, const Json::Value &);
~Sndio(); ~Sndio();

View File

@ -6,7 +6,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include "AButton.hpp" #include "ALabel.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "client.hpp" #include "client.hpp"
#include "modules/sway/ipc/client.hpp" #include "modules/sway/ipc/client.hpp"
@ -14,7 +14,7 @@
namespace waybar::modules::sway { namespace waybar::modules::sway {
class Language : public AButton, public sigc::trackable { class Language : public ALabel, public sigc::trackable {
public: public:
Language(const std::string& id, const Json::Value& config); Language(const std::string& id, const Json::Value& config);
~Language() = default; ~Language() = default;

View File

@ -2,7 +2,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "AButton.hpp" #include "ALabel.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "client.hpp" #include "client.hpp"
#include "modules/sway/ipc/client.hpp" #include "modules/sway/ipc/client.hpp"
@ -10,7 +10,7 @@
namespace waybar::modules::sway { namespace waybar::modules::sway {
class Mode : public AButton, public sigc::trackable { class Mode : public ALabel, public sigc::trackable {
public: public:
Mode(const std::string&, const Json::Value&); Mode(const std::string&, const Json::Value&);
~Mode() = default; ~Mode() = default;

View File

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

View File

@ -6,11 +6,11 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include "AButton.hpp" #include "ALabel.hpp"
namespace waybar::modules { namespace waybar::modules {
class Wireplumber : public AButton { class Wireplumber : public ALabel {
public: public:
Wireplumber(const std::string&, const Json::Value&); Wireplumber(const std::string&, const Json::Value&);
~Wireplumber(); ~Wireplumber();
@ -34,7 +34,6 @@ class Wireplumber : public AButton {
double volume_; double volume_;
uint32_t node_id_{0}; uint32_t node_id_{0};
std::string node_name_; std::string node_name_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -92,7 +92,7 @@ bool waybar::modules::Backlight::BacklightDev::get_powered() const { return powe
void waybar::modules::Backlight::BacklightDev::set_powered(bool powered) { powered_ = powered; } void waybar::modules::Backlight::BacklightDev::set_powered(bool powered) { powered_ = powered; }
waybar::modules::Backlight::Backlight(const std::string &id, const Json::Value &config) waybar::modules::Backlight::Backlight(const std::string &id, const Json::Value &config)
: AButton(config, "backlight", id, "{percent}%", 2), : ALabel(config, "backlight", id, "{percent}%", 2),
preferred_device_(config["device"].isString() ? config["device"].asString() : "") { preferred_device_(config["device"].isString() ? config["device"].asString() : "") {
// Get initial state // Get initial state
{ {
@ -181,7 +181,7 @@ auto waybar::modules::Backlight::update() -> void {
event_box_.show(); event_box_.show();
const uint8_t percent = const uint8_t percent =
best->get_max() == 0 ? 100 : round(best->get_actual() * 100.0f / best->get_max()); best->get_max() == 0 ? 100 : round(best->get_actual() * 100.0f / best->get_max());
label_->set_markup(fmt::format(format_, fmt::arg("percent", std::to_string(percent)), label_.set_markup(fmt::format(format_, fmt::arg("percent", std::to_string(percent)),
fmt::arg("icon", getIcon(percent)))); fmt::arg("icon", getIcon(percent))));
getState(percent); getState(percent);
} else { } else {
@ -191,12 +191,12 @@ auto waybar::modules::Backlight::update() -> void {
if (!previous_best_.has_value()) { if (!previous_best_.has_value()) {
return; return;
} }
label_->set_markup(""); label_.set_markup("");
} }
previous_best_ = best == nullptr ? std::nullopt : std::optional{*best}; previous_best_ = best == nullptr ? std::nullopt : std::optional{*best};
previous_format_ = format_; previous_format_ = format_;
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
template <class ForwardIt> template <class ForwardIt>

View File

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
waybar::modules::Battery::Battery(const std::string& id, const Json::Value& config) waybar::modules::Battery::Battery(const std::string& id, const Json::Value& config)
: AButton(config, "battery", id, "{capacity}%", 60) { : ALabel(config, "battery", id, "{capacity}%", 60) {
#if defined(__linux__) #if defined(__linux__)
battery_watch_fd_ = inotify_init1(IN_CLOEXEC); battery_watch_fd_ = inotify_init1(IN_CLOEXEC);
if (battery_watch_fd_ == -1) { if (battery_watch_fd_ == -1) {
@ -613,14 +613,14 @@ auto waybar::modules::Battery::update() -> void {
} else if (config_["tooltip-format"].isString()) { } else if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
button_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("timeTo", tooltip_text_default), label_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("timeTo", tooltip_text_default),
fmt::arg("power", power), fmt::arg("capacity", capacity), fmt::arg("power", power), fmt::arg("capacity", capacity),
fmt::arg("time", time_remaining_formatted))); fmt::arg("time", time_remaining_formatted)));
} }
if (!old_status_.empty()) { if (!old_status_.empty()) {
button_.get_style_context()->remove_class(old_status_); label_.get_style_context()->remove_class(old_status_);
} }
button_.get_style_context()->add_class(status); label_.get_style_context()->add_class(status);
old_status_ = status; old_status_ = status;
if (!state.empty() && config_["format-" + status + "-" + state].isString()) { if (!state.empty() && config_["format-" + status + "-" + state].isString()) {
format = config_["format-" + status + "-" + state].asString(); format = config_["format-" + status + "-" + state].asString();
@ -634,10 +634,10 @@ auto waybar::modules::Battery::update() -> void {
} else { } else {
event_box_.show(); event_box_.show();
auto icons = std::vector<std::string>{status + "-" + state, status, state}; auto icons = std::vector<std::string>{status + "-" + state, status, state};
label_->set_markup(fmt::format(format, fmt::arg("capacity", capacity), fmt::arg("power", power), label_.set_markup(fmt::format(format, fmt::arg("capacity", capacity), fmt::arg("power", power),
fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("icon", getIcon(capacity, icons)),
fmt::arg("time", time_remaining_formatted))); fmt::arg("time", time_remaining_formatted)));
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }

View File

@ -80,7 +80,7 @@ auto getUcharProperty(GDBusProxy* proxy, const char* property_name) -> unsigned
} // namespace } // namespace
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
: AButton(config, "bluetooth", id, " {status}", 10), : ALabel(config, "bluetooth", id, " {status}", 10),
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
rfkill_{RFKILL_TYPE_BLUETOOTH}, rfkill_{RFKILL_TYPE_BLUETOOTH},
#endif #endif
@ -190,10 +190,10 @@ auto waybar::modules::Bluetooth::update() -> void {
format_.empty() ? event_box_.hide() : event_box_.show(); format_.empty() ? event_box_.hide() : event_box_.show();
auto update_style_context = [this](const std::string& style_class, bool in_next_state) { auto update_style_context = [this](const std::string& style_class, bool in_next_state) {
if (in_next_state && !button_.get_style_context()->has_class(style_class)) { if (in_next_state && !label_.get_style_context()->has_class(style_class)) {
button_.get_style_context()->add_class(style_class); label_.get_style_context()->add_class(style_class);
} else if (!in_next_state && button_.get_style_context()->has_class(style_class)) { } else if (!in_next_state && label_.get_style_context()->has_class(style_class)) {
button_.get_style_context()->remove_class(style_class); label_.get_style_context()->remove_class(style_class);
} }
}; };
update_style_context("discoverable", cur_controller_.discoverable); update_style_context("discoverable", cur_controller_.discoverable);
@ -205,7 +205,7 @@ auto waybar::modules::Bluetooth::update() -> void {
update_style_context(state, true); update_style_context(state, true);
state_ = state; state_ = state;
label_->set_markup(fmt::format( label_.set_markup(fmt::format(
format_, fmt::arg("status", state_), fmt::arg("num_connections", connected_devices_.size()), format_, fmt::arg("status", state_), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("controller_address", cur_controller_.address), fmt::arg("controller_address", cur_controller_.address),
fmt::arg("controller_address_type", cur_controller_.address_type), fmt::arg("controller_address_type", cur_controller_.address_type),
@ -246,7 +246,7 @@ auto waybar::modules::Bluetooth::update() -> void {
device_enumerate_.erase(0, 1); device_enumerate_.erase(0, 1);
} }
} }
button_.set_tooltip_text(fmt::format( label_.set_tooltip_text(fmt::format(
tooltip_format, fmt::arg("status", state_), tooltip_format, fmt::arg("status", state_),
fmt::arg("num_connections", connected_devices_.size()), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("controller_address", cur_controller_.address), fmt::arg("controller_address", cur_controller_.address),
@ -260,7 +260,7 @@ auto waybar::modules::Bluetooth::update() -> void {
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
// NOTE: only for when the org.bluez.Battery1 interface is added/removed after/before a device is // NOTE: only for when the org.bluez.Battery1 interface is added/removed after/before a device is

View File

@ -18,7 +18,7 @@
using waybar::waybar_time; using waybar::waybar_time;
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
: AButton(config, "clock", id, "{:%H:%M}", 60, false, false, true), : ALabel(config, "clock", id, "{:%H:%M}", 60, false, false, true),
current_time_zone_idx_(0), current_time_zone_idx_(0),
is_calendar_in_tooltip_(false), is_calendar_in_tooltip_(false),
is_timezoned_list_in_tooltip_(false) { is_timezoned_list_in_tooltip_(false) {
@ -107,7 +107,7 @@ auto waybar::modules::Clock::update() -> void {
} else { } else {
text = fmt::format(format_, wtime); text = fmt::format(format_, wtime);
} }
label_->set_markup(text); label_.set_markup(text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
@ -119,12 +119,12 @@ auto waybar::modules::Clock::update() -> void {
text = text =
fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines), fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines),
fmt::arg(KTimezonedTimeListPlaceholder.c_str(), timezoned_time_lines)); fmt::arg(KTimezonedTimeListPlaceholder.c_str(), timezoned_time_lines));
button_.set_tooltip_markup(text); label_.set_tooltip_markup(text);
} }
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
bool waybar::modules::Clock::handleScroll(GdkEventScroll* e) { bool waybar::modules::Clock::handleScroll(GdkEventScroll* e) {

View File

@ -10,7 +10,7 @@
#endif #endif
waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config) waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
: AButton(config, "cpu", id, "{usage}%", 10) { : ALabel(config, "cpu", id, "{usage}%", 10) {
thread_ = [this] { thread_ = [this] {
dp.emit(); dp.emit();
thread_.sleep_for(interval_); thread_.sleep_for(interval_);
@ -23,7 +23,7 @@ auto waybar::modules::Cpu::update() -> void {
auto [cpu_usage, tooltip] = getCpuUsage(); auto [cpu_usage, tooltip] = getCpuUsage();
auto [max_frequency, min_frequency, avg_frequency] = getCpuFrequency(); auto [max_frequency, min_frequency, avg_frequency] = getCpuFrequency();
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];
@ -52,11 +52,11 @@ auto waybar::modules::Cpu::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();
} }
double waybar::modules::Cpu::getCpuLoad() { double waybar::modules::Cpu::getCpuLoad() {

View File

@ -4,7 +4,7 @@
waybar::modules::Custom::Custom(const std::string& name, const std::string& id, waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
const Json::Value& config) const Json::Value& config)
: AButton(config, "custom-" + name, id, "{}"), : ALabel(config, "custom-" + name, id, "{}"),
name_(name), name_(name),
id_(id), id_(id),
percentage_(0), percentage_(0),
@ -104,13 +104,13 @@ void waybar::modules::Custom::handleEvent() {
} }
bool waybar::modules::Custom::handleScroll(GdkEventScroll* e) { bool waybar::modules::Custom::handleScroll(GdkEventScroll* e) {
auto ret = AButton::handleScroll(e); auto ret = ALabel::handleScroll(e);
handleEvent(); handleEvent();
return ret; return ret;
} }
bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) { bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) {
auto ret = AButton::handleToggle(e); auto ret = ALabel::handleToggle(e);
handleEvent(); handleEvent();
return ret; return ret;
} }
@ -132,33 +132,33 @@ auto waybar::modules::Custom::update() -> void {
if (str.empty()) { if (str.empty()) {
event_box_.hide(); event_box_.hide();
} else { } else {
label_->set_markup(str); label_.set_markup(str);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (text_ == tooltip_) { if (text_ == tooltip_) {
if (button_.get_tooltip_markup() != str) { if (label_.get_tooltip_markup() != str) {
button_.set_tooltip_markup(str); label_.set_tooltip_markup(str);
} }
} else { } else {
if (button_.get_tooltip_markup() != tooltip_) { if (label_.get_tooltip_markup() != tooltip_) {
button_.set_tooltip_markup(tooltip_); label_.set_tooltip_markup(tooltip_);
} }
} }
} }
auto classes = button_.get_style_context()->list_classes(); auto classes = label_.get_style_context()->list_classes();
for (auto const& c : classes) { for (auto const& c : classes) {
if (c == id_) continue; if (c == id_) continue;
button_.get_style_context()->remove_class(c); label_.get_style_context()->remove_class(c);
} }
for (auto const& c : class_) { for (auto const& c : class_) {
button_.get_style_context()->add_class(c); label_.get_style_context()->add_class(c);
} }
button_.get_style_context()->add_class("flat"); label_.get_style_context()->add_class("flat");
button_.get_style_context()->add_class("text-button"); label_.get_style_context()->add_class("text-button");
event_box_.show(); event_box_.show();
} }
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
void waybar::modules::Custom::parseOutputRaw() { void waybar::modules::Custom::parseOutputRaw() {

View File

@ -3,7 +3,7 @@
using namespace waybar::util; using namespace waybar::util;
waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config) waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config)
: AButton(config, "disk", id, "{}%", 30), path_("/") { : ALabel(config, "disk", id, "{}%", 30), path_("/") {
thread_ = [this] { thread_ = [this] {
dp.emit(); dp.emit();
thread_.sleep_for(interval_); thread_.sleep_for(interval_);
@ -58,7 +58,7 @@ auto waybar::modules::Disk::update() -> void {
event_box_.hide(); event_box_.hide();
} else { } else {
event_box_.show(); event_box_.show();
label_->set_markup( label_.set_markup(
fmt::format(format, stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free), fmt::format(format, stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free),
fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks),
fmt::arg("used", used), fmt::arg("percentage_used", percentage_used), fmt::arg("used", used), fmt::arg("percentage_used", percentage_used),
@ -70,12 +70,12 @@ auto waybar::modules::Disk::update() -> void {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
button_.set_tooltip_text( label_.set_tooltip_text(
fmt::format(tooltip_format, stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free), fmt::format(tooltip_format, stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free),
fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks),
fmt::arg("used", used), fmt::arg("percentage_used", percentage_used), fmt::arg("used", used), fmt::arg("percentage_used", percentage_used),
fmt::arg("total", total), fmt::arg("path", path_))); fmt::arg("total", total), fmt::arg("path", path_)));
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }

View File

@ -11,7 +11,7 @@
namespace waybar::modules::hyprland { namespace waybar::modules::hyprland {
Language::Language(const std::string& id, const Bar& bar, const Json::Value& config) Language::Language(const std::string& id, const Bar& bar, const Json::Value& config)
: AButton(config, "language", id, "{}", 0, true), bar_(bar) { : ALabel(config, "language", id, "{}", 0, true), bar_(bar) {
modulesReady = true; modulesReady = true;
if (!gIPC.get()) { if (!gIPC.get()) {
@ -21,8 +21,8 @@ Language::Language(const std::string& id, const Bar& bar, const Json::Value& con
// get the active layout when open // get the active layout when open
initLanguage(); initLanguage();
button_.hide(); label_.hide();
AButton::update(); ALabel::update();
// register for hyprland ipc // register for hyprland ipc
gIPC->registerForIPC("activelayout", this); gIPC->registerForIPC("activelayout", this);
@ -38,13 +38,13 @@ auto Language::update() -> void {
std::lock_guard<std::mutex> lg(mutex_); std::lock_guard<std::mutex> lg(mutex_);
if (!format_.empty()) { if (!format_.empty()) {
button_.show(); label_.show();
label_->set_markup(layoutName_); label_.set_markup(layoutName_);
} else { } else {
button_.hide(); label_.hide();
} }
AButton::update(); ALabel::update();
} }
void Language::onEvent(const std::string& ev) { void Language::onEvent(const std::string& ev) {

View File

@ -8,7 +8,7 @@ bool waybar::modules::IdleInhibitor::status = false;
waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar,
const Json::Value& config) const Json::Value& config)
: AButton(config, "idle_inhibitor", id, "{status}", 0, false, true), : ALabel(config, "idle_inhibitor", id, "{status}", 0, false, true),
bar_(bar), bar_(bar),
idle_inhibitor_(nullptr), idle_inhibitor_(nullptr),
pid_(-1) { pid_(-1) {
@ -49,13 +49,13 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
auto waybar::modules::IdleInhibitor::update() -> void { auto waybar::modules::IdleInhibitor::update() -> void {
// Check status // Check status
if (status) { if (status) {
button_.get_style_context()->remove_class("deactivated"); label_.get_style_context()->remove_class("deactivated");
if (idle_inhibitor_ == nullptr) { if (idle_inhibitor_ == nullptr) {
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor(
waybar::Client::inst()->idle_inhibit_manager, bar_.surface); waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
} }
} else { } else {
button_.get_style_context()->remove_class("activated"); label_.get_style_context()->remove_class("activated");
if (idle_inhibitor_ != nullptr) { if (idle_inhibitor_ != nullptr) {
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
idle_inhibitor_ = nullptr; idle_inhibitor_ = nullptr;
@ -63,11 +63,11 @@ auto waybar::modules::IdleInhibitor::update() -> void {
} }
std::string status_text = status ? "activated" : "deactivated"; std::string status_text = status ? "activated" : "deactivated";
label_->set_markup(fmt::format(format_, fmt::arg("status", status_text), label_.set_markup(fmt::format(format_, fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text)))); fmt::arg("icon", getIcon(0, status_text))));
button_.get_style_context()->add_class(status_text); label_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
button_.set_tooltip_markup( label_.set_tooltip_markup(
status ? fmt::format(config_["tooltip-format-activated"].isString() status ? fmt::format(config_["tooltip-format-activated"].isString()
? config_["tooltip-format-activated"].asString() ? config_["tooltip-format-activated"].asString()
: "{status}", : "{status}",
@ -80,7 +80,7 @@ auto waybar::modules::IdleInhibitor::update() -> void {
fmt::arg("icon", getIcon(0, status_text)))); fmt::arg("icon", getIcon(0, status_text))));
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
void waybar::modules::IdleInhibitor::toggleStatus() { void waybar::modules::IdleInhibitor::toggleStatus() {
@ -124,6 +124,6 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
} }
} }
AButton::handleToggle(e); ALabel::handleToggle(e);
return true; return true;
} }

View File

@ -98,7 +98,7 @@ auto getInhibitors(const Json::Value& config) -> std::string {
namespace waybar::modules { namespace waybar::modules {
Inhibitor::Inhibitor(const std::string& id, const Bar& bar, const Json::Value& config) Inhibitor::Inhibitor(const std::string& id, const Bar& bar, const Json::Value& config)
: AButton(config, "inhibitor", id, "{status}", true), : ALabel(config, "inhibitor", id, "{status}", true),
dbus_(::dbus()), dbus_(::dbus()),
inhibitors_(::getInhibitors(config)) { inhibitors_(::getInhibitors(config)) {
event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
@ -117,16 +117,16 @@ auto Inhibitor::activated() -> bool { return handle_ != -1; }
auto Inhibitor::update() -> void { auto Inhibitor::update() -> void {
std::string status_text = activated() ? "activated" : "deactivated"; std::string status_text = activated() ? "activated" : "deactivated";
button_.get_style_context()->remove_class(activated() ? "deactivated" : "activated"); label_.get_style_context()->remove_class(activated() ? "deactivated" : "activated");
label_->set_markup(fmt::format(format_, fmt::arg("status", status_text), label_.set_markup(fmt::format(format_, fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text)))); fmt::arg("icon", getIcon(0, status_text))));
button_.get_style_context()->add_class(status_text); label_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
button_.set_tooltip_text(status_text); label_.set_tooltip_text(status_text);
} }
return AButton::update(); return ALabel::update();
} }
auto Inhibitor::handleToggle(GdkEventButton* const& e) -> bool { auto Inhibitor::handleToggle(GdkEventButton* const& e) -> bool {
@ -142,7 +142,7 @@ auto Inhibitor::handleToggle(GdkEventButton* const& e) -> bool {
} }
} }
return AButton::handleToggle(e); return ALabel::handleToggle(e);
} }
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -1,7 +1,7 @@
#include "modules/memory.hpp" #include "modules/memory.hpp"
waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config) waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config)
: AButton(config, "memory", id, "{}%", 30) { : ALabel(config, "memory", id, "{}%", 30) {
thread_ = [this] { thread_ = [this] {
dp.emit(); dp.emit();
thread_.sleep_for(interval_); thread_.sleep_for(interval_);
@ -55,7 +55,7 @@ auto waybar::modules::Memory::update() -> void {
} else { } else {
event_box_.show(); event_box_.show();
auto icons = std::vector<std::string>{state}; auto icons = std::vector<std::string>{state};
label_->set_markup(fmt::format( label_.set_markup(fmt::format(
format, used_ram_percentage, fmt::arg("icon", getIcon(used_ram_percentage, icons)), format, used_ram_percentage, fmt::arg("icon", getIcon(used_ram_percentage, icons)),
fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes),
fmt::arg("percentage", used_ram_percentage), fmt::arg("percentage", used_ram_percentage),
@ -67,7 +67,7 @@ auto waybar::modules::Memory::update() -> void {
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
button_.set_tooltip_text(fmt::format( label_.set_tooltip_text(fmt::format(
tooltip_format, used_ram_percentage, fmt::arg("total", total_ram_gigabytes), tooltip_format, used_ram_percentage, fmt::arg("total", total_ram_gigabytes),
fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes),
fmt::arg("percentage", used_ram_percentage), fmt::arg("percentage", used_ram_percentage),
@ -75,12 +75,12 @@ auto waybar::modules::Memory::update() -> void {
fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes), fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes),
fmt::arg("swapAvail", available_swap_gigabytes))); fmt::arg("swapAvail", available_swap_gigabytes)));
} else { } else {
button_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1)); label_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1));
} }
} }
} else { } else {
event_box_.hide(); event_box_.hide();
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }

View File

@ -15,7 +15,7 @@ namespace waybar::modules {
#endif #endif
waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config) waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
: AButton(config, "mpd", id, "{album} - {artist} - {title}", 5, false, true), : ALabel(config, "mpd", id, "{album} - {artist} - {title}", 5, false, true),
module_name_(id.empty() ? "mpd" : "mpd#" + id), module_name_(id.empty() ? "mpd" : "mpd#" + id),
server_(nullptr), server_(nullptr),
port_(config_["port"].isUInt() ? config["port"].asUInt() : 0), port_(config_["port"].isUInt() ? config["port"].asUInt() : 0),
@ -47,7 +47,7 @@ auto waybar::modules::MPD::update() -> void {
context_.update(); context_.update();
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
void waybar::modules::MPD::queryMPD() { void waybar::modules::MPD::queryMPD() {
@ -88,15 +88,15 @@ std::string waybar::modules::MPD::getFilename() const {
void waybar::modules::MPD::setLabel() { void waybar::modules::MPD::setLabel() {
if (connection_ == nullptr) { if (connection_ == nullptr) {
button_.get_style_context()->add_class("disconnected"); label_.get_style_context()->add_class("disconnected");
button_.get_style_context()->remove_class("stopped"); label_.get_style_context()->remove_class("stopped");
button_.get_style_context()->remove_class("playing"); label_.get_style_context()->remove_class("playing");
button_.get_style_context()->remove_class("paused"); label_.get_style_context()->remove_class("paused");
auto format = config_["format-disconnected"].isString() auto format = config_["format-disconnected"].isString()
? config_["format-disconnected"].asString() ? config_["format-disconnected"].asString()
: "disconnected"; : "disconnected";
label_->set_markup(format); label_.set_markup(format);
if (tooltipEnabled()) { if (tooltipEnabled()) {
std::string tooltip_format; std::string tooltip_format;
@ -104,11 +104,11 @@ void waybar::modules::MPD::setLabel() {
? config_["tooltip-format-disconnected"].asString() ? config_["tooltip-format-disconnected"].asString()
: "MPD (disconnected)"; : "MPD (disconnected)";
// Nothing to format // Nothing to format
button_.set_tooltip_text(tooltip_format); label_.set_tooltip_text(tooltip_format);
} }
return; return;
} else { } else {
button_.get_style_context()->remove_class("disconnected"); label_.get_style_context()->remove_class("disconnected");
} }
auto format = format_; auto format = format_;
@ -121,19 +121,19 @@ void waybar::modules::MPD::setLabel() {
if (stopped()) { if (stopped()) {
format = format =
config_["format-stopped"].isString() ? config_["format-stopped"].asString() : "stopped"; config_["format-stopped"].isString() ? config_["format-stopped"].asString() : "stopped";
button_.get_style_context()->add_class("stopped"); label_.get_style_context()->add_class("stopped");
button_.get_style_context()->remove_class("playing"); label_.get_style_context()->remove_class("playing");
button_.get_style_context()->remove_class("paused"); label_.get_style_context()->remove_class("paused");
} else { } else {
button_.get_style_context()->remove_class("stopped"); label_.get_style_context()->remove_class("stopped");
if (playing()) { if (playing()) {
button_.get_style_context()->add_class("playing"); label_.get_style_context()->add_class("playing");
button_.get_style_context()->remove_class("paused"); label_.get_style_context()->remove_class("paused");
} else if (paused()) { } else if (paused()) {
format = config_["format-paused"].isString() ? config_["format-paused"].asString() format = config_["format-paused"].isString() ? config_["format-paused"].asString()
: config_["format"].asString(); : config_["format"].asString();
button_.get_style_context()->add_class("paused"); label_.get_style_context()->add_class("paused");
button_.get_style_context()->remove_class("playing"); label_.get_style_context()->remove_class("playing");
} }
stateIcon = getStateIcon(); stateIcon = getStateIcon();
@ -169,7 +169,7 @@ void waybar::modules::MPD::setLabel() {
if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt()); if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt());
try { try {
label_->set_markup(fmt::format( label_.set_markup(fmt::format(
format, fmt::arg("artist", artist.raw()), fmt::arg("albumArtist", album_artist.raw()), format, fmt::arg("artist", artist.raw()), fmt::arg("albumArtist", album_artist.raw()),
fmt::arg("album", album.raw()), fmt::arg("title", title.raw()), fmt::arg("date", date), fmt::arg("album", album.raw()), fmt::arg("title", title.raw()), fmt::arg("date", date),
fmt::arg("volume", volume), fmt::arg("elapsedTime", elapsedTime), fmt::arg("volume", volume), fmt::arg("elapsedTime", elapsedTime),
@ -196,7 +196,7 @@ void waybar::modules::MPD::setLabel() {
fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon), fmt::arg("queueLength", queue_length), fmt::arg("stateIcon", stateIcon),
fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon), fmt::arg("consumeIcon", consumeIcon), fmt::arg("randomIcon", randomIcon),
fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon)); fmt::arg("repeatIcon", repeatIcon), fmt::arg("singleIcon", singleIcon));
button_.set_tooltip_text(tooltip_text); label_.set_tooltip_text(tooltip_text);
} catch (fmt::format_error const& e) { } catch (fmt::format_error const& e) {
spdlog::warn("mpd: format error (tooltip): {}", e.what()); spdlog::warn("mpd: format error (tooltip): {}", e.what());
} }

View File

@ -78,7 +78,7 @@ waybar::modules::Network::readBandwidthUsage() {
} }
waybar::modules::Network::Network(const std::string &id, const Json::Value &config) waybar::modules::Network::Network(const std::string &id, const Json::Value &config)
: AButton(config, "network", id, DEFAULT_FORMAT, 60), : ALabel(config, "network", id, DEFAULT_FORMAT, 60),
ifid_(-1), ifid_(-1),
family_(config["family"] == "ipv6" ? AF_INET6 : AF_INET), family_(config["family"] == "ipv6" ? AF_INET6 : AF_INET),
efd_(-1), efd_(-1),
@ -95,11 +95,11 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
#endif #endif
frequency_(0.0) { frequency_(0.0) {
// Start with some "text" in the module's label_-> update() will then // Start with some "text" in the module's label_. update() will then
// update it. Since the text should be different, update() will be able // update it. Since the text should be different, update() will be able
// to show or hide the event_box_. This is to work around the case where // to show or hide the event_box_. This is to work around the case where
// the module start with no text, but the the event_box_ is shown. // the module start with no text, but the the event_box_ is shown.
label_->set_markup("<s></s>"); label_.set_markup("<s></s>");
auto bandwidth = readBandwidthUsage(); auto bandwidth = readBandwidthUsage();
if (bandwidth.has_value()) { if (bandwidth.has_value()) {
@ -309,8 +309,8 @@ auto waybar::modules::Network::update() -> void {
if (!alt_) { if (!alt_) {
auto state = getNetworkState(); auto state = getNetworkState();
if (!state_.empty() && button_.get_style_context()->has_class(state_)) { if (!state_.empty() && label_.get_style_context()->has_class(state_)) {
button_.get_style_context()->remove_class(state_); label_.get_style_context()->remove_class(state_);
} }
if (config_["format-" + state].isString()) { if (config_["format-" + state].isString()) {
default_format_ = config_["format-" + state].asString(); default_format_ = config_["format-" + state].asString();
@ -322,8 +322,8 @@ auto waybar::modules::Network::update() -> void {
if (config_["tooltip-format-" + state].isString()) { if (config_["tooltip-format-" + state].isString()) {
tooltip_format = config_["tooltip-format-" + state].asString(); tooltip_format = config_["tooltip-format-" + state].asString();
} }
if (!button_.get_style_context()->has_class(state)) { if (!label_.get_style_context()->has_class(state)) {
button_.get_style_context()->add_class(state); label_.get_style_context()->add_class(state);
} }
format_ = default_format_; format_ = default_format_;
state_ = state; state_ = state;
@ -349,8 +349,8 @@ auto waybar::modules::Network::update() -> void {
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / interval_.count(), "B/s")), fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / interval_.count(), "B/s")),
fmt::arg("bandwidthTotalBytes", fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / interval_.count(), "B/s"))); pow_format((bandwidth_up + bandwidth_down) / interval_.count(), "B/s")));
if (text.compare(label_->get_label()) != 0) { if (text.compare(label_.get_label()) != 0) {
label_->set_markup(text); label_.set_markup(text);
if (text.empty()) { if (text.empty()) {
event_box_.hide(); event_box_.hide();
} else { } else {
@ -382,16 +382,16 @@ auto waybar::modules::Network::update() -> void {
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / interval_.count(), "B/s")), fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / interval_.count(), "B/s")),
fmt::arg("bandwidthTotalBytes", fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / interval_.count(), "B/s"))); pow_format((bandwidth_up + bandwidth_down) / interval_.count(), "B/s")));
if (button_.get_tooltip_text() != tooltip_text) { if (label_.get_tooltip_text() != tooltip_text) {
button_.set_tooltip_markup(tooltip_text); label_.set_tooltip_markup(tooltip_text);
} }
} else if (button_.get_tooltip_text() != text) { } else if (label_.get_tooltip_text() != text) {
button_.set_tooltip_markup(text); label_.set_tooltip_markup(text);
} }
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
bool waybar::modules::Network::checkInterface(std::string name) { bool waybar::modules::Network::checkInterface(std::string name) {

View File

@ -1,7 +1,7 @@
#include "modules/pulseaudio.hpp" #include "modules/pulseaudio.hpp"
waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value &config) waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value &config)
: AButton(config, "pulseaudio", id, "{volume}%"), : ALabel(config, "pulseaudio", id, "{volume}%"),
mainloop_(nullptr), mainloop_(nullptr),
mainloop_api_(nullptr), mainloop_api_(nullptr),
context_(nullptr), context_(nullptr),
@ -263,9 +263,9 @@ auto waybar::modules::Pulseaudio::update() -> void {
monitor_.find("a2dp-sink") != std::string::npos || // PipeWire monitor_.find("a2dp-sink") != std::string::npos || // PipeWire
monitor_.find("bluez") != std::string::npos) { monitor_.find("bluez") != std::string::npos) {
format_name = format_name + "-bluetooth"; format_name = format_name + "-bluetooth";
button_.get_style_context()->add_class("bluetooth"); label_.get_style_context()->add_class("bluetooth");
} else { } else {
button_.get_style_context()->remove_class("bluetooth"); label_.get_style_context()->remove_class("bluetooth");
} }
if (muted_) { if (muted_) {
// Check muted bluetooth format exist, otherwise fallback to default muted format // Check muted bluetooth format exist, otherwise fallback to default muted format
@ -273,29 +273,29 @@ auto waybar::modules::Pulseaudio::update() -> void {
format_name = "format"; format_name = "format";
} }
format_name = format_name + "-muted"; format_name = format_name + "-muted";
button_.get_style_context()->add_class("muted"); label_.get_style_context()->add_class("muted");
button_.get_style_context()->add_class("sink-muted"); label_.get_style_context()->add_class("sink-muted");
} else { } else {
button_.get_style_context()->remove_class("muted"); label_.get_style_context()->remove_class("muted");
button_.get_style_context()->remove_class("sink-muted"); label_.get_style_context()->remove_class("sink-muted");
} }
format = config_[format_name].isString() ? config_[format_name].asString() : format; format = config_[format_name].isString() ? config_[format_name].asString() : format;
} }
// TODO: find a better way to split source/sink // TODO: find a better way to split source/sink
std::string format_source = "{volume}%"; std::string format_source = "{volume}%";
if (source_muted_) { if (source_muted_) {
button_.get_style_context()->add_class("source-muted"); label_.get_style_context()->add_class("source-muted");
if (config_["format-source-muted"].isString()) { if (config_["format-source-muted"].isString()) {
format_source = config_["format-source-muted"].asString(); format_source = config_["format-source-muted"].asString();
} }
} else { } else {
button_.get_style_context()->remove_class("source-muted"); label_.get_style_context()->remove_class("source-muted");
if (config_["format-source-muted"].isString()) { if (config_["format-source-muted"].isString()) {
format_source = config_["format-source"].asString(); format_source = config_["format-source"].asString();
} }
} }
format_source = fmt::format(format_source, fmt::arg("volume", source_volume_)); format_source = fmt::format(format_source, fmt::arg("volume", source_volume_));
label_->set_markup(fmt::format( label_.set_markup(fmt::format(
format, fmt::arg("desc", desc_), fmt::arg("volume", volume_), format, fmt::arg("desc", desc_), fmt::arg("volume", volume_),
fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_), fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_),
fmt::arg("source_desc", source_desc_), fmt::arg("icon", getIcon(volume_, getPulseIcon())))); fmt::arg("source_desc", source_desc_), fmt::arg("icon", getIcon(volume_, getPulseIcon()))));
@ -306,16 +306,16 @@ auto waybar::modules::Pulseaudio::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
button_.set_tooltip_text(fmt::format( label_.set_tooltip_text(fmt::format(
tooltip_format, fmt::arg("desc", desc_), fmt::arg("volume", volume_), tooltip_format, fmt::arg("desc", desc_), fmt::arg("volume", volume_),
fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_), fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_),
fmt::arg("source_desc", source_desc_), fmt::arg("source_desc", source_desc_),
fmt::arg("icon", getIcon(volume_, getPulseIcon())))); fmt::arg("icon", getIcon(volume_, getPulseIcon()))));
} else { } else {
button_.set_tooltip_text(desc_); label_.set_tooltip_text(desc_);
} }
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }

View File

@ -3,7 +3,7 @@
#include <time.h> #include <time.h>
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
: AButton(config, "clock", id, "{:%H:%M}", 60) { : ALabel(config, "clock", id, "{:%H:%M}", 60) {
thread_ = [this] { thread_ = [this] {
dp.emit(); dp.emit();
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
@ -19,17 +19,17 @@ auto waybar::modules::Clock::update() -> void {
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
auto text = fmt::format(format_, localtime); auto text = fmt::format(format_, localtime);
label_->set_markup(text); label_.set_markup(text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
auto tooltip_text = fmt::format(tooltip_format, localtime); auto tooltip_text = fmt::format(tooltip_format, localtime);
button_.set_tooltip_text(tooltip_text); label_.set_tooltip_text(tooltip_text);
} else { } else {
button_.set_tooltip_text(text); label_.set_tooltip_text(text);
} }
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }

View File

@ -41,7 +41,7 @@ auto Sndio::connect_to_sndio() -> void {
} }
Sndio::Sndio(const std::string &id, const Json::Value &config) Sndio::Sndio(const std::string &id, const Json::Value &config)
: AButton(config, "sndio", id, "{volume}%", 1, false, true), : ALabel(config, "sndio", id, "{volume}%", 1, false, true),
hdl_(nullptr), hdl_(nullptr),
pfds_(0), pfds_(0),
addr_(0), addr_(0),
@ -105,14 +105,14 @@ auto Sndio::update() -> void {
unsigned int vol = 100. * static_cast<double>(volume_) / static_cast<double>(maxval_); unsigned int vol = 100. * static_cast<double>(volume_) / static_cast<double>(maxval_);
if (volume_ == 0) { if (volume_ == 0) {
button_.get_style_context()->add_class("muted"); label_.get_style_context()->add_class("muted");
} else { } else {
button_.get_style_context()->remove_class("muted"); label_.get_style_context()->remove_class("muted");
} }
label_->set_markup(fmt::format(format, fmt::arg("volume", vol), fmt::arg("raw_value", volume_))); label_.set_markup(fmt::format(format, fmt::arg("volume", vol), fmt::arg("raw_value", volume_)));
AButton::update(); ALabel::update();
} }
auto Sndio::set_desc(struct sioctl_desc *d, unsigned int val) -> void { auto Sndio::set_desc(struct sioctl_desc *d, unsigned int val) -> void {

View File

@ -18,7 +18,7 @@ const std::string Language::XKB_LAYOUT_NAMES_KEY = "xkb_layout_names";
const std::string Language::XKB_ACTIVE_LAYOUT_NAME_KEY = "xkb_active_layout_name"; const std::string Language::XKB_ACTIVE_LAYOUT_NAME_KEY = "xkb_active_layout_name";
Language::Language(const std::string& id, const Json::Value& config) Language::Language(const std::string& id, const Json::Value& config)
: AButton(config, "language", id, "{}", 0, true) { : ALabel(config, "language", id, "{}", 0, true) {
is_variant_displayed = format_.find("{variant}") != std::string::npos; is_variant_displayed = format_.find("{variant}") != std::string::npos;
if (format_.find("{}") != std::string::npos || format_.find("{short}") != std::string::npos) { if (format_.find("{}") != std::string::npos || format_.find("{short}") != std::string::npos) {
displayed_short_flag |= static_cast<std::byte>(DispayedShortFlag::ShortName); displayed_short_flag |= static_cast<std::byte>(DispayedShortFlag::ShortName);
@ -99,7 +99,7 @@ auto Language::update() -> void {
format_, fmt::arg("short", layout_.short_name), format_, fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name), fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name),
fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag()))); fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag())));
label_->set_markup(display_layout); label_.set_markup(display_layout);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltip_format_ != "") { if (tooltip_format_ != "") {
auto tooltip_display_layout = trim( auto tooltip_display_layout = trim(
@ -107,22 +107,22 @@ auto Language::update() -> void {
fmt::arg("shortDescription", layout_.short_description), fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant), fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant),
fmt::arg("flag", layout_.country_flag()))); fmt::arg("flag", layout_.country_flag())));
button_.set_tooltip_markup(tooltip_display_layout); label_.set_tooltip_markup(tooltip_display_layout);
} else { } else {
button_.set_tooltip_markup(display_layout); label_.set_tooltip_markup(display_layout);
} }
} }
event_box_.show(); event_box_.show();
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
auto Language::set_current_layout(std::string current_layout) -> void { auto Language::set_current_layout(std::string current_layout) -> void {
button_.get_style_context()->remove_class(layout_.short_name); label_.get_style_context()->remove_class(layout_.short_name);
layout_ = layouts_map_[current_layout]; layout_ = layouts_map_[current_layout];
button_.get_style_context()->add_class(layout_.short_name); label_.get_style_context()->add_class(layout_.short_name);
} }
auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) -> void { auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) -> void {

View File

@ -5,7 +5,7 @@
namespace waybar::modules::sway { namespace waybar::modules::sway {
Mode::Mode(const std::string& id, const Json::Value& config) Mode::Mode(const std::string& id, const Json::Value& config)
: AButton(config, "mode", id, "{}", 0, true) { : ALabel(config, "mode", id, "{}", 0, true) {
ipc_.subscribe(R"(["mode"])"); ipc_.subscribe(R"(["mode"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent)); ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
// Launch worker // Launch worker
@ -42,14 +42,14 @@ auto Mode::update() -> void {
if (mode_.empty()) { if (mode_.empty()) {
event_box_.hide(); event_box_.hide();
} else { } else {
label_->set_markup(fmt::format(format_, mode_)); label_.set_markup(fmt::format(format_, mode_));
if (tooltipEnabled()) { if (tooltipEnabled()) {
button_.set_tooltip_text(mode_); label_.set_tooltip_text(mode_);
} }
event_box_.show(); event_box_.show();
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
} // namespace waybar::modules::sway } // namespace waybar::modules::sway

View File

@ -7,7 +7,7 @@
#endif #endif
waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config) waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config)
: AButton(config, "temperature", id, "{temperatureC}°C", 10) { : ALabel(config, "temperature", id, "{temperatureC}°C", 10) {
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
// try to read sysctl? // try to read sysctl?
#else #else
@ -42,9 +42,9 @@ auto waybar::modules::Temperature::update() -> void {
auto format = format_; auto format = format_;
if (critical) { if (critical) {
format = config_["format-critical"].isString() ? config_["format-critical"].asString() : format; format = config_["format-critical"].isString() ? config_["format-critical"].asString() : format;
button_.get_style_context()->add_class("critical"); label_.get_style_context()->add_class("critical");
} else { } else {
button_.get_style_context()->remove_class("critical"); label_.get_style_context()->remove_class("critical");
} }
if (format.empty()) { if (format.empty()) {
@ -55,7 +55,7 @@ auto waybar::modules::Temperature::update() -> void {
} }
auto max_temp = config_["critical-threshold"].isInt() ? config_["critical-threshold"].asInt() : 0; auto max_temp = config_["critical-threshold"].isInt() ? config_["critical-threshold"].asInt() : 0;
label_->set_markup(fmt::format(format, fmt::arg("temperatureC", temperature_c), label_.set_markup(fmt::format(format, fmt::arg("temperatureC", temperature_c),
fmt::arg("temperatureF", temperature_f), fmt::arg("temperatureF", temperature_f),
fmt::arg("temperatureK", temperature_k), fmt::arg("temperatureK", temperature_k),
fmt::arg("icon", getIcon(temperature_c, "", max_temp)))); fmt::arg("icon", getIcon(temperature_c, "", max_temp))));
@ -64,12 +64,12 @@ auto waybar::modules::Temperature::update() -> void {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
button_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("temperatureC", temperature_c), label_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("temperatureC", temperature_c),
fmt::arg("temperatureF", temperature_f), fmt::arg("temperatureF", temperature_f),
fmt::arg("temperatureK", temperature_k))); fmt::arg("temperatureK", temperature_k)));
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }
float waybar::modules::Temperature::getTemperature() { float waybar::modules::Temperature::getTemperature() {

View File

@ -1,7 +1,7 @@
#include "modules/wireplumber.hpp" #include "modules/wireplumber.hpp"
waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Value& config) waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Value& config)
: AButton(config, "wireplumber", id, "{volume}%"), : ALabel(config, "wireplumber", id, "{volume}%"),
wp_core_(nullptr), wp_core_(nullptr),
apis_(nullptr), apis_(nullptr),
om_(nullptr), om_(nullptr),
@ -33,7 +33,6 @@ waybar::modules::Wireplumber::~Wireplumber() {
g_clear_pointer(&apis_, g_ptr_array_unref); g_clear_pointer(&apis_, g_ptr_array_unref);
g_clear_object(&om_); g_clear_object(&om_);
g_clear_object(&wp_core_); g_clear_object(&wp_core_);
} }
uint32_t waybar::modules::Wireplumber::getDefaultNodeId(waybar::modules::Wireplumber* self) { uint32_t waybar::modules::Wireplumber::getDefaultNodeId(waybar::modules::Wireplumber* self) {
@ -55,7 +54,9 @@ uint32_t waybar::modules::Wireplumber::getDefaultNodeId(waybar::modules::Wireplu
} }
void waybar::modules::Wireplumber::updateNodeName(waybar::modules::Wireplumber* self) { void waybar::modules::Wireplumber::updateNodeName(waybar::modules::Wireplumber* self) {
auto proxy = static_cast<WpPipewireObject *>(wp_object_manager_lookup(self->om_, WP_TYPE_GLOBAL_PROXY, WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "object.id", "=u", self->node_id_, NULL)); auto proxy = static_cast<WpPipewireObject*>(wp_object_manager_lookup(
self->om_, WP_TYPE_GLOBAL_PROXY, WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "object.id", "=u",
self->node_id_, NULL));
if (!proxy) { if (!proxy) {
throw std::runtime_error(fmt::format("Object '{}' not found\n", self->node_id_)); throw std::runtime_error(fmt::format("Object '{}' not found\n", self->node_id_));
@ -85,7 +86,8 @@ void waybar::modules::Wireplumber::updateVolume(waybar::modules::Wireplumber* se
} }
void waybar::modules::Wireplumber::onObjectManagerInstalled(waybar::modules::Wireplumber* self) { void waybar::modules::Wireplumber::onObjectManagerInstalled(waybar::modules::Wireplumber* self) {
self->node_id_ = self->config_["node-id"].isInt() ? self->config_["node-id"].asInt() : getDefaultNodeId(self); self->node_id_ =
self->config_["node-id"].isInt() ? self->config_["node-id"].asInt() : getDefaultNodeId(self);
g_autoptr(WpPlugin) mixer_api = wp_plugin_find(self->wp_core_, "mixer-api"); g_autoptr(WpPlugin) mixer_api = wp_plugin_find(self->wp_core_, "mixer-api");
@ -94,7 +96,8 @@ void waybar::modules::Wireplumber::onObjectManagerInstalled(waybar::modules::Wir
g_signal_connect_swapped(mixer_api, "changed", (GCallback)updateVolume, self); g_signal_connect_swapped(mixer_api, "changed", (GCallback)updateVolume, self);
} }
void waybar::modules::Wireplumber::onPluginActivated(WpObject* p, GAsyncResult* res, waybar::modules::Wireplumber* self) { void waybar::modules::Wireplumber::onPluginActivated(WpObject* p, GAsyncResult* res,
waybar::modules::Wireplumber* self) {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
if (!wp_object_activate_finish(p, res, &error)) { if (!wp_object_activate_finish(p, res, &error)) {
@ -110,23 +113,27 @@ void waybar::modules::Wireplumber::activatePlugins() {
for (uint16_t i = 0; i < apis_->len; i++) { for (uint16_t i = 0; i < apis_->len; i++) {
WpPlugin* plugin = static_cast<WpPlugin*>(g_ptr_array_index(apis_, i)); WpPlugin* plugin = static_cast<WpPlugin*>(g_ptr_array_index(apis_, i));
pending_plugins_++; pending_plugins_++;
wp_object_activate(WP_OBJECT(plugin), WP_PLUGIN_FEATURE_ENABLED, NULL, (GAsyncReadyCallback)onPluginActivated, this); wp_object_activate(WP_OBJECT(plugin), WP_PLUGIN_FEATURE_ENABLED, NULL,
(GAsyncReadyCallback)onPluginActivated, this);
} }
} }
void waybar::modules::Wireplumber::prepare() { void waybar::modules::Wireplumber::prepare() {
wp_object_manager_add_interest(om_, WP_TYPE_NODE, NULL); wp_object_manager_add_interest(om_, WP_TYPE_NODE, NULL);
wp_object_manager_request_object_features(om_, WP_TYPE_GLOBAL_PROXY, WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL); wp_object_manager_request_object_features(om_, WP_TYPE_GLOBAL_PROXY,
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
} }
void waybar::modules::Wireplumber::loadRequiredApiModules() { void waybar::modules::Wireplumber::loadRequiredApiModules() {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
if (!wp_core_load_component(wp_core_, "libwireplumber-module-default-nodes-api", "module", NULL, &error)) { if (!wp_core_load_component(wp_core_, "libwireplumber-module-default-nodes-api", "module", NULL,
&error)) {
throw std::runtime_error(error->message); throw std::runtime_error(error->message);
} }
if (!wp_core_load_component(wp_core_, "libwireplumber-module-mixer-api", "module", NULL, &error)) { if (!wp_core_load_component(wp_core_, "libwireplumber-module-mixer-api", "module", NULL,
&error)) {
throw std::runtime_error(error->message); throw std::runtime_error(error->message);
} }
@ -144,13 +151,14 @@ auto waybar::modules::Wireplumber::update() -> void {
if (muted_) { if (muted_) {
format = config_["format-muted"].isString() ? config_["format-muted"].asString() : format; format = config_["format-muted"].isString() ? config_["format-muted"].asString() : format;
button_.get_style_context()->add_class("muted"); label_.get_style_context()->add_class("muted");
} else { } else {
button_.get_style_context()->remove_class("muted"); label_.get_style_context()->remove_class("muted");
} }
std::string markup = fmt::format(format, fmt::arg("node_name", node_name_), fmt::arg("volume", volume_)); std::string markup =
label_->set_markup(markup); fmt::format(format, fmt::arg("node_name", node_name_), fmt::arg("volume", volume_));
label_.set_markup(markup);
getState(volume_); getState(volume_);
@ -160,13 +168,13 @@ auto waybar::modules::Wireplumber::update() -> void {
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
button_.set_tooltip_text(fmt::format( label_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("node_name", node_name_),
tooltip_format, fmt::arg("node_name", node_name_), fmt::arg("volume", volume_))); fmt::arg("volume", volume_)));
} else { } else {
button_.set_tooltip_text(node_name_); label_.set_tooltip_text(node_name_);
} }
} }
// Call parent update // Call parent update
AButton::update(); ALabel::update();
} }