Files
waybar/include/modules/power_profiles_daemon.hpp
Félix Baylac Jacqué c38d05b04f Introduce power-profiles-daemon module
We introduce a module in charge to display and toggle on click the
power profiles via power-profiles-daemon.

https://gitlab.freedesktop.org/upower/power-profiles-daemon

This daemon is pretty widespread. It's the component used by Gnome and
KDE to manage the power profiles. The power management daemon is a
pretty important software component for laptops and other
battery-powered devices.

We're using the daemon DBus interface to:

- Fetch the available power profiles.
- Track the active power profile.
- Change the active power profile.

The original author recently gave up maintenance on the project. The
Upower group took over the maintenance burden… …and created a new
DBus name for the project. The old name is still advertised for now.
We use the old name for compatibility sake: most distributions did not
release 0.20, which introduces this new DBus name. We'll likely revisit
this in the future and point to the new bus name. See the inline
comment for more details.

Given how widespread this daemon is, I activated the module in the
default configuration.
2024-02-26 14:44:14 +01:00

39 lines
1.1 KiB
C++

# pragma once
#include <fmt/format.h>
#include "ALabel.hpp"
#include "giomm/dbusproxy.h"
namespace waybar::modules {
typedef struct {
std::string name;
std::string driver;
} Profile;
class PowerProfilesDaemon : public ALabel {
public:
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 populateInitState();
virtual bool handleToggle(GdkEventButton* const& e);
private:
// Look for a profile name in the list of available profiles and
// switch activeProfile_ to it.
void switchToProfile_(std::string);
// Used to toggle/display the profiles
std::vector<Profile> availableProfiles_;
// Points to the active profile in the profiles list
std::vector<Profile>::iterator activeProfile_;
// Current CSS class applied to the label
std::string currentStyle_;
// DBus Proxy used to track the current active profile
Glib::RefPtr<Gio::DBus::Proxy> power_profiles_proxy_;
sigc::connection powerProfileChangeSignal_;
};
}