2024-02-26 13:40:28 +00:00
|
|
|
#pragma once
|
2024-02-18 21:06:21 +00:00
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
#include "ALabel.hpp"
|
|
|
|
#include "giomm/dbusproxy.h"
|
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2024-02-26 14:07:21 +00:00
|
|
|
struct Profile {
|
2024-02-18 21:06:21 +00:00
|
|
|
std::string name;
|
|
|
|
std::string driver;
|
Add explicit constructor to struct Profile
Not adding the constructor causes a compilation error on Ubuntu 22.04
with both clang 14 and gcc 11:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/alloc_traits.h:518:4: error: no matching function for call to 'construct_at'
std::construct_at(__p, std::forward<_Args>(__args)...);
^~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/vector.tcc:117:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<waybar::modules::Profile>>::construct<waybar::modules::Profile, Glib::ustring, Glib::ustring>' requested here
_Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
^
../src/modules/power_profiles_daemon.cpp:106:26: note: in instantiation of function template specialization 'std::vector<waybar::modules::Profile>::emplace_back<Glib::ustring, Glib::ustring>' requested here
availableProfiles_.emplace_back(std::move(name), std::move(driver));
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = waybar::modules::Profile, _Args = <Glib::ustring, Glib::ustring>]: no matching constructor for initialization of 'waybar::modules::Profile'
construct_at(_Tp* __location, _Args&&... __args)
^
2024-06-21 13:30:12 +00:00
|
|
|
|
2024-06-21 14:43:21 +00:00
|
|
|
Profile(std::string n, std::string d) : name(std::move(n)), driver(std::move(d)) {}
|
2024-02-26 14:07:21 +00:00
|
|
|
};
|
2024-02-18 21:06:21 +00:00
|
|
|
|
2024-02-26 13:40:28 +00:00
|
|
|
class PowerProfilesDaemon : public ALabel {
|
2024-02-18 21:06:21 +00:00
|
|
|
public:
|
2024-03-01 11:33:36 +00:00
|
|
|
PowerProfilesDaemon(const std::string &, const Json::Value &);
|
2024-02-18 21:06:21 +00:00
|
|
|
auto update() -> void override;
|
2024-03-01 11:33:36 +00: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 21:06:21 +00:00
|
|
|
void populateInitState();
|
2024-03-01 11:33:36 +00:00
|
|
|
bool handleToggle(GdkEventButton *const &e) override;
|
2024-02-26 13:40:28 +00:00
|
|
|
|
2024-02-18 21:06:21 +00:00
|
|
|
private:
|
2024-03-01 11:33:36 +00:00
|
|
|
// True if we're connected to the dbug interface. False if we're
|
|
|
|
// not.
|
|
|
|
bool connected_;
|
2024-02-18 21:06:21 +00:00
|
|
|
// Look for a profile name in the list of available profiles and
|
|
|
|
// switch activeProfile_ to it.
|
2024-03-01 11:33:36 +00:00
|
|
|
void switchToProfile(std::string const &);
|
2024-02-18 21:06:21 +00: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 18:37:20 +00:00
|
|
|
// Format string
|
2024-03-01 10:13:57 +00:00
|
|
|
std::string tooltipFormat_;
|
2024-02-18 21:06:21 +00:00
|
|
|
// DBus Proxy used to track the current active profile
|
2024-02-26 14:07:21 +00:00
|
|
|
Glib::RefPtr<Gio::DBus::Proxy> powerProfilesProxy_;
|
2024-02-18 21:06:21 +00:00
|
|
|
};
|
|
|
|
|
2024-02-26 13:40:28 +00:00
|
|
|
} // namespace waybar::modules
|