@@ -27,15 +27,15 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
27
27
// adresses for compatibility sake.
28
28
//
29
29
// 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 (
31
31
Gio::DBus::BusType::BUS_TYPE_SYSTEM, " net.hadess.PowerProfiles" , " /net/hadess/PowerProfiles" ,
32
32
" net.hadess.PowerProfiles" );
33
- if (!power_profiles_proxy_ ) {
33
+ if (!powerProfilesProxy_ ) {
34
34
spdlog::error (" PowerProfilesDaemon: DBus error, cannot connect to net.hasdess.PowerProfile" );
35
35
} else {
36
36
// 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 ));
39
39
populateInitState ();
40
40
dp.emit ();
41
41
}
@@ -45,9 +45,9 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
45
45
// vector to store the profiles ain't the smartest move
46
46
// complexity-wise, but it makes toggling between the mode easy. This
47
47
// 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);
51
51
if (activeProfile_ == availableProfiles_.end ()) {
52
52
throw std::runtime_error (" FATAL, can't find the active profile in the available profiles list" );
53
53
}
@@ -56,13 +56,14 @@ void PowerProfilesDaemon::switchToProfile_(std::string str) {
56
56
void PowerProfilesDaemon::populateInitState () {
57
57
// Retrieve current active profile
58
58
Glib::Variant<std::string> profileStr;
59
- power_profiles_proxy_ ->get_cached_property (profileStr, " ActiveProfile" );
59
+ powerProfilesProxy_ ->get_cached_property (profileStr, " ActiveProfile" );
60
60
61
61
// Retrieve profiles list, it's aa{sv}.
62
62
using ProfilesType = std::vector<std::map<Glib::ustring, Glib::Variant<std::string>>>;
63
63
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;
66
67
Profile profile;
67
68
for (auto & variantDict : profilesVariant.get ()) {
68
69
if (auto p = variantDict.find (" Profile" ); p != variantDict.end ()) {
@@ -77,7 +78,7 @@ void PowerProfilesDaemon::populateInitState() {
77
78
78
79
// Find the index of the current activated mode (to toggle)
79
80
std::string str = profileStr.get ();
80
- switchToProfile_ (str);
81
+ switchToProfile (str);
81
82
82
83
update ();
83
84
}
@@ -86,20 +87,20 @@ PowerProfilesDaemon::~PowerProfilesDaemon() {
86
87
if (powerProfileChangeSignal_.connected ()) {
87
88
powerProfileChangeSignal_.disconnect ();
88
89
}
89
- if (power_profiles_proxy_ ) {
90
- power_profiles_proxy_ .reset ();
90
+ if (powerProfilesProxy_ ) {
91
+ powerProfilesProxy_ .reset ();
91
92
}
92
93
}
93
94
94
- void PowerProfilesDaemon::profileChanged_cb (
95
+ void PowerProfilesDaemon::profileChangedCb (
95
96
const Gio::DBus::Proxy::MapChangedProperties& changedProperties,
96
97
const std::vector<Glib::ustring>& invalidatedProperties) {
97
98
if (auto activeProfileVariant = changedProperties.find (" ActiveProfile" );
98
99
activeProfileVariant != changedProperties.end ()) {
99
100
std::string activeProfile =
100
101
Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second )
101
102
.get ();
102
- switchToProfile_ (activeProfile);
103
+ switchToProfile (activeProfile);
103
104
update ();
104
105
}
105
106
}
@@ -125,7 +126,7 @@ auto PowerProfilesDaemon::update() -> void {
125
126
}
126
127
127
128
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_ ) {
129
130
activeProfile_++;
130
131
if (activeProfile_ == availableProfiles_.end ()) {
131
132
activeProfile_ = availableProfiles_.begin ();
@@ -134,10 +135,10 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
134
135
using VarStr = Glib::Variant<Glib::ustring>;
135
136
using SetPowerProfileVar = Glib::Variant<std::tuple<Glib::ustring, Glib::ustring, VarStr>>;
136
137
VarStr activeProfileVariant = VarStr::create (activeProfile_->name );
137
- auto call_args = SetPowerProfileVar::create (
138
+ auto callArgs = SetPowerProfileVar::create (
138
139
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);
141
142
142
143
update ();
143
144
}
0 commit comments