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