9
9
#include < fmt/core.h>
10
10
#endif
11
11
12
- #include < spdlog/spdlog.h>
13
12
#include < glibmm.h>
14
13
#include < glibmm/variant.h>
15
-
16
-
14
+ #include < spdlog/spdlog.h>
17
15
18
16
namespace waybar ::modules {
19
17
20
18
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 ) {
23
20
// NOTE: the DBus adresses are under migration. They should be
24
21
// changed to org.freedesktop.UPower.PowerProfiles at some point.
25
22
//
@@ -30,15 +27,15 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
30
27
// adresses for compatibility sake.
31
28
//
32
29
// 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" );
36
33
if (!power_profiles_proxy_) {
37
34
spdlog::error (" PowerProfilesDaemon: DBus error, cannot connect to net.hasdess.PowerProfile" );
38
35
} else {
39
36
// 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));
42
39
populateInitState ();
43
40
dp.emit ();
44
41
}
@@ -67,14 +64,14 @@ void PowerProfilesDaemon::populateInitState() {
67
64
power_profiles_proxy_->get_cached_property (profilesVariant, " Profiles" );
68
65
Glib::ustring name, driver;
69
66
Profile profile;
70
- for (auto & variantDict: profilesVariant.get ()) {
67
+ for (auto & variantDict : profilesVariant.get ()) {
71
68
if (auto p = variantDict.find (" Profile" ); p != variantDict.end ()) {
72
69
name = p->second .get ();
73
70
}
74
71
if (auto d = variantDict.find (" Driver" ); d != variantDict.end ()) {
75
72
driver = d->second .get ();
76
73
}
77
- profile = { name, driver };
74
+ profile = {name, driver};
78
75
availableProfiles_.push_back (profile);
79
76
}
80
77
@@ -94,16 +91,20 @@ PowerProfilesDaemon::~PowerProfilesDaemon() {
94
91
}
95
92
}
96
93
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 ();
101
102
switchToProfile_ (activeProfile);
102
103
update ();
103
104
}
104
105
}
105
106
106
- auto PowerProfilesDaemon::update () -> void {
107
+ auto PowerProfilesDaemon::update () -> void {
107
108
auto profile = (*activeProfile_);
108
109
// Set label
109
110
fmt::dynamic_format_arg_store<fmt::format_context> store;
@@ -123,7 +124,6 @@ auto PowerProfilesDaemon::update () -> void {
123
124
ALabel::update ();
124
125
}
125
126
126
-
127
127
bool PowerProfilesDaemon::handleToggle (GdkEventButton* const & e) {
128
128
if (e->type == GdkEventType::GDK_BUTTON_PRESS && power_profiles_proxy_) {
129
129
activeProfile_++;
@@ -132,9 +132,10 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
132
132
}
133
133
134
134
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>>;
136
136
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));
138
139
auto container = Glib::VariantBase::cast_dynamic<Glib::VariantContainerBase>(call_args);
139
140
power_profiles_proxy_->call_sync (" org.freedesktop.DBus.Properties.Set" , container);
140
141
@@ -143,4 +144,4 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
143
144
return true ;
144
145
}
145
146
146
- }
147
+ } // namespace waybar::modules
0 commit comments