Skip to content

Commit 162b41c

Browse files
committed
modules/power-profiles-daemon: apply clang-tidy suggestions
1 parent 968f469 commit 162b41c

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

include/modules/power_profiles_daemon.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77

88
namespace waybar::modules {
99

10-
typedef struct {
10+
struct Profile {
1111
std::string name;
1212
std::string driver;
13-
} Profile;
13+
};
1414

1515
class PowerProfilesDaemon : public ALabel {
1616
public:
1717
PowerProfilesDaemon(const std::string&, const Json::Value&);
18-
~PowerProfilesDaemon();
18+
~PowerProfilesDaemon() override;
1919
auto update() -> void override;
20-
void profileChanged_cb(const Gio::DBus::Proxy::MapChangedProperties&,
21-
const std::vector<Glib::ustring>&);
20+
void profileChangedCb(const Gio::DBus::Proxy::MapChangedProperties&,
21+
const std::vector<Glib::ustring>&);
2222
void populateInitState();
23-
virtual bool handleToggle(GdkEventButton* const& e);
23+
bool handleToggle(GdkEventButton* const& e) override;
2424

2525
private:
2626
// Look for a profile name in the list of available profiles and
2727
// switch activeProfile_ to it.
28-
void switchToProfile_(std::string);
28+
void switchToProfile(std::string const&);
2929
// Used to toggle/display the profiles
3030
std::vector<Profile> availableProfiles_;
3131
// Points to the active profile in the profiles list
3232
std::vector<Profile>::iterator activeProfile_;
3333
// Current CSS class applied to the label
3434
std::string currentStyle_;
3535
// DBus Proxy used to track the current active profile
36-
Glib::RefPtr<Gio::DBus::Proxy> power_profiles_proxy_;
36+
Glib::RefPtr<Gio::DBus::Proxy> powerProfilesProxy_;
3737
sigc::connection powerProfileChangeSignal_;
3838
};
3939

src/modules/power_profiles_daemon.cpp

+20-19
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
2727
// adresses for compatibility sake.
2828
//
2929
// Revisit this in 2026, systems should be updated by then.
30-
power_profiles_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(
30+
powerProfilesProxy_ = Gio::DBus::Proxy::create_for_bus_sync(
3131
Gio::DBus::BusType::BUS_TYPE_SYSTEM, "net.hadess.PowerProfiles", "/net/hadess/PowerProfiles",
3232
"net.hadess.PowerProfiles");
33-
if (!power_profiles_proxy_) {
33+
if (!powerProfilesProxy_) {
3434
spdlog::error("PowerProfilesDaemon: DBus error, cannot connect to net.hasdess.PowerProfile");
3535
} else {
3636
// Connect active profile callback
37-
powerProfileChangeSignal_ = power_profiles_proxy_->signal_properties_changed().connect(
38-
sigc::mem_fun(*this, &PowerProfilesDaemon::profileChanged_cb));
37+
powerProfileChangeSignal_ = powerProfilesProxy_->signal_properties_changed().connect(
38+
sigc::mem_fun(*this, &PowerProfilesDaemon::profileChangedCb));
3939
populateInitState();
4040
dp.emit();
4141
}
@@ -45,9 +45,9 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
4545
// vector to store the profiles ain't the smartest move
4646
// complexity-wise, but it makes toggling between the mode easy. This
4747
// vector is 3 elements max, we'll be fine :P
48-
void PowerProfilesDaemon::switchToProfile_(std::string str) {
49-
auto pred = [str](Profile p) { return p.name == str; };
50-
activeProfile_ = std::find_if(availableProfiles_.begin(), availableProfiles_.end(), pred);
48+
void PowerProfilesDaemon::switchToProfile(std::string const& str) {
49+
auto pred = [str](Profile const& p) { return p.name == str; };
50+
this->activeProfile_ = std::find_if(availableProfiles_.begin(), availableProfiles_.end(), pred);
5151
if (activeProfile_ == availableProfiles_.end()) {
5252
throw std::runtime_error("FATAL, can't find the active profile in the available profiles list");
5353
}
@@ -56,13 +56,14 @@ void PowerProfilesDaemon::switchToProfile_(std::string str) {
5656
void PowerProfilesDaemon::populateInitState() {
5757
// Retrieve current active profile
5858
Glib::Variant<std::string> profileStr;
59-
power_profiles_proxy_->get_cached_property(profileStr, "ActiveProfile");
59+
powerProfilesProxy_->get_cached_property(profileStr, "ActiveProfile");
6060

6161
// Retrieve profiles list, it's aa{sv}.
6262
using ProfilesType = std::vector<std::map<Glib::ustring, Glib::Variant<std::string>>>;
6363
Glib::Variant<ProfilesType> profilesVariant;
64-
power_profiles_proxy_->get_cached_property(profilesVariant, "Profiles");
65-
Glib::ustring name, driver;
64+
powerProfilesProxy_->get_cached_property(profilesVariant, "Profiles");
65+
Glib::ustring name;
66+
Glib::ustring driver;
6667
Profile profile;
6768
for (auto& variantDict : profilesVariant.get()) {
6869
if (auto p = variantDict.find("Profile"); p != variantDict.end()) {
@@ -77,7 +78,7 @@ void PowerProfilesDaemon::populateInitState() {
7778

7879
// Find the index of the current activated mode (to toggle)
7980
std::string str = profileStr.get();
80-
switchToProfile_(str);
81+
switchToProfile(str);
8182

8283
update();
8384
}
@@ -86,20 +87,20 @@ PowerProfilesDaemon::~PowerProfilesDaemon() {
8687
if (powerProfileChangeSignal_.connected()) {
8788
powerProfileChangeSignal_.disconnect();
8889
}
89-
if (power_profiles_proxy_) {
90-
power_profiles_proxy_.reset();
90+
if (powerProfilesProxy_) {
91+
powerProfilesProxy_.reset();
9192
}
9293
}
9394

94-
void PowerProfilesDaemon::profileChanged_cb(
95+
void PowerProfilesDaemon::profileChangedCb(
9596
const Gio::DBus::Proxy::MapChangedProperties& changedProperties,
9697
const std::vector<Glib::ustring>& invalidatedProperties) {
9798
if (auto activeProfileVariant = changedProperties.find("ActiveProfile");
9899
activeProfileVariant != changedProperties.end()) {
99100
std::string activeProfile =
100101
Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second)
101102
.get();
102-
switchToProfile_(activeProfile);
103+
switchToProfile(activeProfile);
103104
update();
104105
}
105106
}
@@ -125,7 +126,7 @@ auto PowerProfilesDaemon::update() -> void {
125126
}
126127

127128
bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
128-
if (e->type == GdkEventType::GDK_BUTTON_PRESS && power_profiles_proxy_) {
129+
if (e->type == GdkEventType::GDK_BUTTON_PRESS && powerProfilesProxy_) {
129130
activeProfile_++;
130131
if (activeProfile_ == availableProfiles_.end()) {
131132
activeProfile_ = availableProfiles_.begin();
@@ -134,10 +135,10 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
134135
using VarStr = Glib::Variant<Glib::ustring>;
135136
using SetPowerProfileVar = Glib::Variant<std::tuple<Glib::ustring, Glib::ustring, VarStr>>;
136137
VarStr activeProfileVariant = VarStr::create(activeProfile_->name);
137-
auto call_args = SetPowerProfileVar::create(
138+
auto callArgs = SetPowerProfileVar::create(
138139
std::make_tuple("net.hadess.PowerProfiles", "ActiveProfile", activeProfileVariant));
139-
auto container = Glib::VariantBase::cast_dynamic<Glib::VariantContainerBase>(call_args);
140-
power_profiles_proxy_->call_sync("org.freedesktop.DBus.Properties.Set", container);
140+
auto container = Glib::VariantBase::cast_dynamic<Glib::VariantContainerBase>(callArgs);
141+
powerProfilesProxy_->call_sync("org.freedesktop.DBus.Properties.Set", container);
141142

142143
update();
143144
}

0 commit comments

Comments
 (0)