Skip to content

power-profiles-daemon: split driver into cpu driver and platform driver #3994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/modules/power_profiles_daemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace waybar::modules {

struct Profile {
std::string name;
std::string driver;
std::string cpuDriver;
std::string platformDriver;

Profile(std::string n, std::string d) : name(std::move(n)), driver(std::move(d)) {}
Profile(std::string n, std::string cd, std::string pd) : name(std::move(n)), cpuDriver(std::move(cd)), platformDriver(std::move(pd)) {}
};

class PowerProfilesDaemon : public ALabel {
Expand Down
6 changes: 3 additions & 3 deletions man/waybar-power-profiles-daemon.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $XDG_CONFIG_HOME/waybar/config
:[ Message displayed on the bar. {icon} and {profile} are respectively substituted with the icon representing the active profile and its full name.
|[ *tooltip-format*
:[ string
:[ "Power profile: {profile}\\nDriver: {driver}"
:[ "Power profile: {profile}\\nCPU driver: {cpu_driver}\\nPlatform driver: {platform_driver}"
:[ Messaged displayed in the module tooltip. {icon} and {profile} are respectively substituted with the icon representing the active profile and its full name.
|[ *tooltip*
:[ bool
Expand All @@ -51,7 +51,7 @@ Compact display (default config):
```
"power-profiles-daemon": {
"format": "{icon}",
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
"tooltip-format": "Power profile: {profile}\nCPU driver: {cpu_driver}\nPlatform driver: {platform_driver}",
"tooltip": true,
"format-icons": {
"default": "",
Expand All @@ -67,7 +67,7 @@ Display the full profile name:
```
"power-profiles-daemon": {
"format": "{icon} {profile}",
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
"tooltip-format": "Power profile: {profile}\nCPU driver: {cpu_driver}\nPlatform driver: {platform_driver}",
"tooltip": true,
"format-icons": {
"default": "",
Expand Down
2 changes: 1 addition & 1 deletion resources/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
},
"power-profiles-daemon": {
"format": "{icon}",
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
"tooltip-format": "Power profile: {profile}\nCPU driver: {cpu_driver}\nPlatform driver: {platform_driver}",
"tooltip": true,
"format-icons": {
"default": "",
Expand Down
27 changes: 21 additions & 6 deletions src/modules/power_profiles_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
if (config_["tooltip-format"].isString()) {
tooltipFormat_ = config_["tooltip-format"].asString();
} else {
tooltipFormat_ = "Power profile: {profile}\nDriver: {driver}";
tooltipFormat_ = "Power profile: {profile}\nCpuDriver: {cpu_driver}";
}
// Fasten your seatbelt, we're up for quite a ride. The rest of the
// init is performed asynchronously. There's 2 callbacks involved.
Expand Down Expand Up @@ -95,15 +95,29 @@ void PowerProfilesDaemon::populateInitState() {
powerProfilesProxy_->get_cached_property(profilesVariant, "Profiles");
for (auto& variantDict : profilesVariant.get()) {
Glib::ustring name;
Glib::ustring driver;
Glib::ustring cpuDriver;
Glib::ustring platformDriver;
if (auto p = variantDict.find("Profile"); p != variantDict.end()) {
name = p->second.get();
}
if (auto d = variantDict.find("Driver"); d != variantDict.end()) {
driver = d->second.get();
if (auto cd = variantDict.find("CpuDriver"); cd != variantDict.end()) {
cpuDriver = cd->second.get();
}
if (auto pd = variantDict.find("PlatformDriver"); pd != variantDict.end()) {
platformDriver = pd->second.get();
}

if (cpuDriver.empty()) {
cpuDriver = "Unavailable";
spdlog::warn("Cannot find power profiles daemon cpu driver.");
}
if (platformDriver.empty()) {
platformDriver = "Unavailable";
spdlog::warn("Cannot find power profiles daemon platform driver.");
}

if (!name.empty()) {
availableProfiles_.emplace_back(std::move(name), std::move(driver));
availableProfiles_.emplace_back(std::move(name), std::move(cpuDriver), std::move(platformDriver));
} else {
spdlog::error(
"Power profiles daemon: power-profiles-daemon sent us an empty power profile name. "
Expand Down Expand Up @@ -153,7 +167,8 @@ auto PowerProfilesDaemon::update() -> void {
// Set label
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.push_back(fmt::arg("profile", profile.name));
store.push_back(fmt::arg("driver", profile.driver));
store.push_back(fmt::arg("cpu_driver", profile.cpuDriver));
store.push_back(fmt::arg("platform_driver", profile.platformDriver));
store.push_back(fmt::arg("icon", getIcon(0, profile.name)));
label_.set_markup(fmt::vformat(format_, store));
if (tooltipEnabled()) {
Expand Down