2024-02-26 14:40:28 +01:00
|
|
|
#pragma once
|
2024-02-18 22:06:21 +01:00
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
|
|
#include "ALabel.hpp"
|
|
|
|
|
#include "giomm/dbusproxy.h"
|
|
|
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
|
2024-02-26 15:07:21 +01:00
|
|
|
struct Profile {
|
2024-02-18 22:06:21 +01:00
|
|
|
std::string name;
|
|
|
|
|
std::string driver;
|
2024-06-21 15:30:12 +02:00
|
|
|
|
2024-06-21 16:43:21 +02:00
|
|
|
Profile(std::string n, std::string d) : name(std::move(n)), driver(std::move(d)) {}
|
2024-02-26 15:07:21 +01:00
|
|
|
};
|
2024-02-18 22:06:21 +01:00
|
|
|
|
2024-02-26 14:40:28 +01:00
|
|
|
class PowerProfilesDaemon : public ALabel {
|
2024-02-18 22:06:21 +01:00
|
|
|
public:
|
2026-02-04 09:24:14 +01:00
|
|
|
PowerProfilesDaemon(const std::string&, const Json::Value&);
|
2024-02-18 22:06:21 +01:00
|
|
|
auto update() -> void override;
|
2026-02-04 09:24:14 +01:00
|
|
|
void profileChangedCb(const Gio::DBus::Proxy::MapChangedProperties&,
|
|
|
|
|
const std::vector<Glib::ustring>&);
|
|
|
|
|
void busConnectedCb(Glib::RefPtr<Gio::AsyncResult>& r);
|
|
|
|
|
void getAllPropsCb(Glib::RefPtr<Gio::AsyncResult>& r);
|
|
|
|
|
void setPropCb(Glib::RefPtr<Gio::AsyncResult>& r);
|
2024-02-18 22:06:21 +01:00
|
|
|
void populateInitState();
|
2026-02-04 09:24:14 +01:00
|
|
|
bool handleToggle(GdkEventButton* const& e) override;
|
2024-02-26 14:40:28 +01:00
|
|
|
|
2024-02-18 22:06:21 +01:00
|
|
|
private:
|
2024-03-01 12:33:36 +01:00
|
|
|
// True if we're connected to the dbug interface. False if we're
|
|
|
|
|
// not.
|
|
|
|
|
bool connected_;
|
2024-02-18 22:06:21 +01:00
|
|
|
// Look for a profile name in the list of available profiles and
|
|
|
|
|
// switch activeProfile_ to it.
|
2026-02-04 09:24:14 +01:00
|
|
|
void switchToProfile(std::string const&);
|
2024-02-18 22:06:21 +01:00
|
|
|
// 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_;
|
2024-03-01 19:37:20 +01:00
|
|
|
// Format string
|
2024-03-01 11:13:57 +01:00
|
|
|
std::string tooltipFormat_;
|
2024-02-18 22:06:21 +01:00
|
|
|
// DBus Proxy used to track the current active profile
|
2024-02-26 15:07:21 +01:00
|
|
|
Glib::RefPtr<Gio::DBus::Proxy> powerProfilesProxy_;
|
2024-02-18 22:06:21 +01:00
|
|
|
};
|
|
|
|
|
|
2024-02-26 14:40:28 +01:00
|
|
|
} // namespace waybar::modules
|