From ecc32ddd185b112b101891200d127dc319a58ca5 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Tue, 2 Feb 2021 20:01:01 -0800 Subject: [PATCH] refactor(bluetooth): remove Bluetooth::status_ The string was always overwritten in `update()`; don't need to store temporary value in the class. --- include/modules/bluetooth.hpp | 4 ---- src/modules/bluetooth.cpp | 21 +++++++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index 716df0eb..4d7b7c84 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -1,8 +1,5 @@ #pragma once -#include -#include - #include "ALabel.hpp" #include "util/rfkill.hpp" #include "util/sleeper_thread.hpp" @@ -16,7 +13,6 @@ class Bluetooth : public ALabel { auto update() -> void; private: - std::string status_; util::SleeperThread thread_; util::Rfkill rfkill_; }; diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 9939cc19..0df404d3 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -1,9 +1,9 @@ #include "modules/bluetooth.hpp" +#include + waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) - : ALabel(config, "bluetooth", id, "{icon}", 10), - status_("disabled"), - rfkill_{RFKILL_TYPE_BLUETOOTH} { + : ALabel(config, "bluetooth", id, "{icon}", 10), rfkill_{RFKILL_TYPE_BLUETOOTH} { rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update))); thread_ = [this] { auto now = std::chrono::system_clock::now(); @@ -15,25 +15,18 @@ waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& } auto waybar::modules::Bluetooth::update() -> void { - if (rfkill_.getState()) { - status_ = "disabled"; - } else { - status_ = "enabled"; - } + std::string status = rfkill_.getState() ? "disabled" : "enabled"; label_.set_markup( - fmt::format( - format_, - fmt::arg("status", status_), - fmt::arg("icon", getIcon(0, 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, status_); + auto tooltip_text = fmt::format(tooltip_format, status); label_.set_tooltip_text(tooltip_text); } else { - label_.set_tooltip_text(status_); + label_.set_tooltip_text(status); } } }