modules/power-profiles-daemon: run clang format
This commit is contained in:
parent
c38d05b04f
commit
968f469289
|
@ -17,9 +17,11 @@ class PowerProfilesDaemon : public ALabel {
|
|||
PowerProfilesDaemon(const std::string&, const Json::Value&);
|
||||
~PowerProfilesDaemon();
|
||||
auto update() -> void override;
|
||||
void profileChanged_cb( const Gio::DBus::Proxy::MapChangedProperties&, const std::vector<Glib::ustring>&);
|
||||
void profileChanged_cb(const Gio::DBus::Proxy::MapChangedProperties&,
|
||||
const std::vector<Glib::ustring>&);
|
||||
void populateInitState();
|
||||
virtual bool handleToggle(GdkEventButton* const& e);
|
||||
|
||||
private:
|
||||
// Look for a profile name in the list of available profiles and
|
||||
// switch activeProfile_ to it.
|
||||
|
@ -35,4 +37,4 @@ class PowerProfilesDaemon : public ALabel {
|
|||
sigc::connection powerProfileChangeSignal_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
|
|
@ -9,17 +9,14 @@
|
|||
#include <fmt/core.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <glibmm.h>
|
||||
#include <glibmm/variant.h>
|
||||
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "power-profiles-daemon", id, "{profile}", 0, false, true)
|
||||
{
|
||||
: ALabel(config, "power-profiles-daemon", id, "{profile}", 0, false, true) {
|
||||
// NOTE: the DBus adresses are under migration. They should be
|
||||
// changed to org.freedesktop.UPower.PowerProfiles at some point.
|
||||
//
|
||||
|
@ -30,15 +27,15 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
|
|||
// adresses for compatibility sake.
|
||||
//
|
||||
// Revisit this in 2026, systems should be updated by then.
|
||||
power_profiles_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BusType::BUS_TYPE_SYSTEM,
|
||||
"net.hadess.PowerProfiles", "/net/hadess/PowerProfiles",
|
||||
power_profiles_proxy_ = Gio::DBus::Proxy::create_for_bus_sync(
|
||||
Gio::DBus::BusType::BUS_TYPE_SYSTEM, "net.hadess.PowerProfiles", "/net/hadess/PowerProfiles",
|
||||
"net.hadess.PowerProfiles");
|
||||
if (!power_profiles_proxy_) {
|
||||
spdlog::error("PowerProfilesDaemon: DBus error, cannot connect to net.hasdess.PowerProfile");
|
||||
} else {
|
||||
// Connect active profile callback
|
||||
powerProfileChangeSignal_ = power_profiles_proxy_->signal_properties_changed()
|
||||
.connect(sigc::mem_fun(*this, &PowerProfilesDaemon::profileChanged_cb));
|
||||
powerProfileChangeSignal_ = power_profiles_proxy_->signal_properties_changed().connect(
|
||||
sigc::mem_fun(*this, &PowerProfilesDaemon::profileChanged_cb));
|
||||
populateInitState();
|
||||
dp.emit();
|
||||
}
|
||||
|
@ -94,10 +91,14 @@ PowerProfilesDaemon::~PowerProfilesDaemon() {
|
|||
}
|
||||
}
|
||||
|
||||
void PowerProfilesDaemon::profileChanged_cb(const Gio::DBus::Proxy::MapChangedProperties& changedProperties,
|
||||
void PowerProfilesDaemon::profileChanged_cb(
|
||||
const Gio::DBus::Proxy::MapChangedProperties& changedProperties,
|
||||
const std::vector<Glib::ustring>& invalidatedProperties) {
|
||||
if (auto activeProfileVariant = changedProperties.find("ActiveProfile"); activeProfileVariant != changedProperties.end()) {
|
||||
std::string activeProfile = Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second).get();
|
||||
if (auto activeProfileVariant = changedProperties.find("ActiveProfile");
|
||||
activeProfileVariant != changedProperties.end()) {
|
||||
std::string activeProfile =
|
||||
Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second)
|
||||
.get();
|
||||
switchToProfile_(activeProfile);
|
||||
update();
|
||||
}
|
||||
|
@ -123,7 +124,6 @@ auto PowerProfilesDaemon::update () -> void {
|
|||
ALabel::update();
|
||||
}
|
||||
|
||||
|
||||
bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
|
||||
if (e->type == GdkEventType::GDK_BUTTON_PRESS && power_profiles_proxy_) {
|
||||
activeProfile_++;
|
||||
|
@ -134,7 +134,8 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
|
|||
using VarStr = Glib::Variant<Glib::ustring>;
|
||||
using SetPowerProfileVar = Glib::Variant<std::tuple<Glib::ustring, Glib::ustring, VarStr>>;
|
||||
VarStr activeProfileVariant = VarStr::create(activeProfile_->name);
|
||||
auto call_args = SetPowerProfileVar::create(std::make_tuple("net.hadess.PowerProfiles", "ActiveProfile", activeProfileVariant));
|
||||
auto call_args = SetPowerProfileVar::create(
|
||||
std::make_tuple("net.hadess.PowerProfiles", "ActiveProfile", activeProfileVariant));
|
||||
auto container = Glib::VariantBase::cast_dynamic<Glib::VariantContainerBase>(call_args);
|
||||
power_profiles_proxy_->call_sync("org.freedesktop.DBus.Properties.Set", container);
|
||||
|
||||
|
@ -143,4 +144,4 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
|
|||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
|
Loading…
Reference in New Issue