Skip to content

Commit 968f469

Browse files
committed
modules/power-profiles-daemon: run clang format
1 parent c38d05b commit 968f469

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

Diff for: include/modules/power_profiles_daemon.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pragma once
1+
#pragma once
22

33
#include <fmt/format.h>
44

@@ -12,14 +12,16 @@ typedef struct {
1212
std::string driver;
1313
} Profile;
1414

15-
class PowerProfilesDaemon : public ALabel {
15+
class PowerProfilesDaemon : public ALabel {
1616
public:
1717
PowerProfilesDaemon(const std::string&, const Json::Value&);
1818
~PowerProfilesDaemon();
1919
auto update() -> void override;
20-
void profileChanged_cb( const Gio::DBus::Proxy::MapChangedProperties&, const std::vector<Glib::ustring>&);
20+
void profileChanged_cb(const Gio::DBus::Proxy::MapChangedProperties&,
21+
const std::vector<Glib::ustring>&);
2122
void populateInitState();
2223
virtual bool handleToggle(GdkEventButton* const& e);
24+
2325
private:
2426
// Look for a profile name in the list of available profiles and
2527
// switch activeProfile_ to it.
@@ -35,4 +37,4 @@ class PowerProfilesDaemon : public ALabel {
3537
sigc::connection powerProfileChangeSignal_;
3638
};
3739

38-
}
40+
} // namespace waybar::modules

Diff for: src/modules/power_profiles_daemon.cpp

+22-21
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
#include <fmt/core.h>
1010
#endif
1111

12-
#include <spdlog/spdlog.h>
1312
#include <glibmm.h>
1413
#include <glibmm/variant.h>
15-
16-
14+
#include <spdlog/spdlog.h>
1715

1816
namespace waybar::modules {
1917

2018
PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Value& config)
21-
: ALabel(config, "power-profiles-daemon", id, "{profile}", 0, false, true)
22-
{
19+
: ALabel(config, "power-profiles-daemon", id, "{profile}", 0, false, true) {
2320
// NOTE: the DBus adresses are under migration. They should be
2421
// changed to org.freedesktop.UPower.PowerProfiles at some point.
2522
//
@@ -30,15 +27,15 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
3027
// adresses for compatibility sake.
3128
//
3229
// Revisit this in 2026, systems should be updated by then.
33-
power_profiles_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BusType::BUS_TYPE_SYSTEM,
34-
"net.hadess.PowerProfiles", "/net/hadess/PowerProfiles",
35-
"net.hadess.PowerProfiles");
30+
power_profiles_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(
31+
Gio::DBus::BusType::BUS_TYPE_SYSTEM, "net.hadess.PowerProfiles", "/net/hadess/PowerProfiles",
32+
"net.hadess.PowerProfiles");
3633
if (!power_profiles_proxy_) {
3734
spdlog::error("PowerProfilesDaemon: DBus error, cannot connect to net.hasdess.PowerProfile");
3835
} else {
3936
// Connect active profile callback
40-
powerProfileChangeSignal_ = power_profiles_proxy_->signal_properties_changed()
41-
.connect(sigc::mem_fun(*this, &PowerProfilesDaemon::profileChanged_cb));
37+
powerProfileChangeSignal_ = power_profiles_proxy_->signal_properties_changed().connect(
38+
sigc::mem_fun(*this, &PowerProfilesDaemon::profileChanged_cb));
4239
populateInitState();
4340
dp.emit();
4441
}
@@ -67,14 +64,14 @@ void PowerProfilesDaemon::populateInitState() {
6764
power_profiles_proxy_->get_cached_property(profilesVariant, "Profiles");
6865
Glib::ustring name, driver;
6966
Profile profile;
70-
for (auto & variantDict: profilesVariant.get()) {
67+
for (auto& variantDict : profilesVariant.get()) {
7168
if (auto p = variantDict.find("Profile"); p != variantDict.end()) {
7269
name = p->second.get();
7370
}
7471
if (auto d = variantDict.find("Driver"); d != variantDict.end()) {
7572
driver = d->second.get();
7673
}
77-
profile = { name, driver };
74+
profile = {name, driver};
7875
availableProfiles_.push_back(profile);
7976
}
8077

@@ -94,16 +91,20 @@ PowerProfilesDaemon::~PowerProfilesDaemon() {
9491
}
9592
}
9693

97-
void PowerProfilesDaemon::profileChanged_cb(const Gio::DBus::Proxy::MapChangedProperties& changedProperties,
98-
const std::vector<Glib::ustring>& invalidatedProperties) {
99-
if (auto activeProfileVariant = changedProperties.find("ActiveProfile"); activeProfileVariant != changedProperties.end()) {
100-
std::string activeProfile = Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second).get();
94+
void PowerProfilesDaemon::profileChanged_cb(
95+
const Gio::DBus::Proxy::MapChangedProperties& changedProperties,
96+
const std::vector<Glib::ustring>& invalidatedProperties) {
97+
if (auto activeProfileVariant = changedProperties.find("ActiveProfile");
98+
activeProfileVariant != changedProperties.end()) {
99+
std::string activeProfile =
100+
Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second)
101+
.get();
101102
switchToProfile_(activeProfile);
102103
update();
103104
}
104105
}
105106

106-
auto PowerProfilesDaemon::update () -> void {
107+
auto PowerProfilesDaemon::update() -> void {
107108
auto profile = (*activeProfile_);
108109
// Set label
109110
fmt::dynamic_format_arg_store<fmt::format_context> store;
@@ -123,7 +124,6 @@ auto PowerProfilesDaemon::update () -> void {
123124
ALabel::update();
124125
}
125126

126-
127127
bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
128128
if (e->type == GdkEventType::GDK_BUTTON_PRESS && power_profiles_proxy_) {
129129
activeProfile_++;
@@ -132,9 +132,10 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
132132
}
133133

134134
using VarStr = Glib::Variant<Glib::ustring>;
135-
using SetPowerProfileVar = Glib::Variant<std::tuple<Glib::ustring,Glib::ustring,VarStr>>;
135+
using SetPowerProfileVar = Glib::Variant<std::tuple<Glib::ustring, Glib::ustring, VarStr>>;
136136
VarStr activeProfileVariant = VarStr::create(activeProfile_->name);
137-
auto call_args = SetPowerProfileVar::create(std::make_tuple("net.hadess.PowerProfiles", "ActiveProfile", activeProfileVariant));
137+
auto call_args = SetPowerProfileVar::create(
138+
std::make_tuple("net.hadess.PowerProfiles", "ActiveProfile", activeProfileVariant));
138139
auto container = Glib::VariantBase::cast_dynamic<Glib::VariantContainerBase>(call_args);
139140
power_profiles_proxy_->call_sync("org.freedesktop.DBus.Properties.Set", container);
140141

@@ -143,4 +144,4 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
143144
return true;
144145
}
145146

146-
}
147+
} // namespace waybar::modules

0 commit comments

Comments
 (0)