Merge pull request #3994 from jeevithakannan2/ppd-split-driver
power-profiles-daemon: split driver into cpu driver and platform driver
This commit is contained in:
@@ -9,9 +9,18 @@ namespace waybar::modules {
|
|||||||
|
|
||||||
struct Profile {
|
struct Profile {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
// Legacy driver field, kept for backward compatibility with the
|
||||||
|
// `{driver}` format placeholder and with older power-profiles-daemon
|
||||||
|
// versions that only expose a single `Driver` DBus property.
|
||||||
std::string driver;
|
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 d, std::string cd, std::string pd)
|
||||||
|
: name(std::move(n)),
|
||||||
|
driver(std::move(d)),
|
||||||
|
cpuDriver(std::move(cd)),
|
||||||
|
platformDriver(std::move(pd)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PowerProfilesDaemon : public ALabel {
|
class PowerProfilesDaemon : public ALabel {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ $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.
|
:[ Message displayed on the bar. {icon} and {profile} are respectively substituted with the icon representing the active profile and its full name.
|
||||||
|[ *tooltip-format*
|
|[ *tooltip-format*
|
||||||
:[ string
|
:[ 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.
|
:[ Messaged displayed in the module tooltip. {icon} and {profile} are respectively substituted with the icon representing the active profile and its full name. {cpu_driver} and {platform_driver} are substituted with the CPU and platform drivers reported by recent power-profiles-daemon versions. {driver} is kept for backward compatibility: it resolves to the legacy single driver on older daemons and falls back to the CPU driver on recent ones.
|
||||||
|[ *tooltip*
|
|[ *tooltip*
|
||||||
:[ bool
|
:[ bool
|
||||||
:[ true
|
:[ true
|
||||||
@@ -51,7 +51,7 @@ Compact display (default config):
|
|||||||
```
|
```
|
||||||
"power-profiles-daemon": {
|
"power-profiles-daemon": {
|
||||||
"format": "{icon}",
|
"format": "{icon}",
|
||||||
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
|
"tooltip-format": "Power profile: {profile}\nCPU driver: {cpu_driver}\nPlatform driver: {platform_driver}",
|
||||||
"tooltip": true,
|
"tooltip": true,
|
||||||
"format-icons": {
|
"format-icons": {
|
||||||
"default": "",
|
"default": "",
|
||||||
@@ -67,7 +67,7 @@ Display the full profile name:
|
|||||||
```
|
```
|
||||||
"power-profiles-daemon": {
|
"power-profiles-daemon": {
|
||||||
"format": "{icon} {profile}",
|
"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,
|
"tooltip": true,
|
||||||
"format-icons": {
|
"format-icons": {
|
||||||
"default": "",
|
"default": "",
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
},
|
},
|
||||||
"power-profiles-daemon": {
|
"power-profiles-daemon": {
|
||||||
"format": "{icon}",
|
"format": "{icon}",
|
||||||
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
|
"tooltip-format": "Power profile: {profile}\nCPU driver: {cpu_driver}\nPlatform driver: {platform_driver}",
|
||||||
"tooltip": true,
|
"tooltip": true,
|
||||||
"format-icons": {
|
"format-icons": {
|
||||||
"default": "",
|
"default": "",
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
|
|||||||
if (config_["tooltip-format"].isString()) {
|
if (config_["tooltip-format"].isString()) {
|
||||||
tooltipFormat_ = config_["tooltip-format"].asString();
|
tooltipFormat_ = config_["tooltip-format"].asString();
|
||||||
} else {
|
} else {
|
||||||
tooltipFormat_ = "Power profile: {profile}\nDriver: {driver}";
|
tooltipFormat_ =
|
||||||
|
"Power profile: {profile}\nCPU driver: {cpu_driver}\nPlatform driver: {platform_driver}";
|
||||||
}
|
}
|
||||||
// Fasten your seatbelt, we're up for quite a ride. The rest of the
|
// Fasten your seatbelt, we're up for quite a ride. The rest of the
|
||||||
// init is performed asynchronously. There's 2 callbacks involved.
|
// init is performed asynchronously. There's 2 callbacks involved.
|
||||||
@@ -95,15 +96,51 @@ void PowerProfilesDaemon::populateInitState() {
|
|||||||
powerProfilesProxy_->get_cached_property(profilesVariant, "Profiles");
|
powerProfilesProxy_->get_cached_property(profilesVariant, "Profiles");
|
||||||
for (auto& variantDict : profilesVariant.get()) {
|
for (auto& variantDict : profilesVariant.get()) {
|
||||||
Glib::ustring name;
|
Glib::ustring name;
|
||||||
|
// Legacy single `Driver` property, still exposed by older
|
||||||
|
// power-profiles-daemon versions.
|
||||||
Glib::ustring driver;
|
Glib::ustring driver;
|
||||||
|
Glib::ustring cpuDriver;
|
||||||
|
Glib::ustring platformDriver;
|
||||||
if (auto p = variantDict.find("Profile"); p != variantDict.end()) {
|
if (auto p = variantDict.find("Profile"); p != variantDict.end()) {
|
||||||
name = p->second.get();
|
name = p->second.get();
|
||||||
}
|
}
|
||||||
if (auto d = variantDict.find("Driver"); d != variantDict.end()) {
|
if (auto d = variantDict.find("Driver"); d != variantDict.end()) {
|
||||||
driver = d->second.get();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recent power-profiles-daemon versions split the single `Driver`
|
||||||
|
// property into `CpuDriver` and `PlatformDriver`. When talking to an
|
||||||
|
// older daemon that only exposes `Driver`, fall back to it so the new
|
||||||
|
// {cpu_driver}/{platform_driver} placeholders still resolve.
|
||||||
|
if (cpuDriver.empty()) {
|
||||||
|
cpuDriver = driver;
|
||||||
|
}
|
||||||
|
if (platformDriver.empty()) {
|
||||||
|
platformDriver = driver;
|
||||||
|
}
|
||||||
|
// Conversely, keep the legacy {driver} placeholder working against a
|
||||||
|
// recent daemon that no longer exposes `Driver` by deriving it from
|
||||||
|
// the CPU driver.
|
||||||
|
if (driver.empty()) {
|
||||||
|
driver = cpuDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (driver.empty()) {
|
||||||
|
driver = "Unavailable";
|
||||||
|
cpuDriver = "Unavailable";
|
||||||
|
platformDriver = "Unavailable";
|
||||||
|
spdlog::warn("Cannot find power profiles daemon driver.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
availableProfiles_.emplace_back(std::move(name), std::move(driver));
|
availableProfiles_.emplace_back(std::move(name), std::move(driver), std::move(cpuDriver),
|
||||||
|
std::move(platformDriver));
|
||||||
} else {
|
} else {
|
||||||
spdlog::error(
|
spdlog::error(
|
||||||
"Power profiles daemon: power-profiles-daemon sent us an empty power profile name. "
|
"Power profiles daemon: power-profiles-daemon sent us an empty power profile name. "
|
||||||
@@ -153,7 +190,10 @@ auto PowerProfilesDaemon::update() -> void {
|
|||||||
// Set label
|
// Set label
|
||||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
||||||
store.push_back(fmt::arg("profile", profile.name));
|
store.push_back(fmt::arg("profile", profile.name));
|
||||||
|
// Legacy placeholder, kept for backward compatibility with existing configs.
|
||||||
store.push_back(fmt::arg("driver", profile.driver));
|
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)));
|
store.push_back(fmt::arg("icon", getIcon(0, profile.name)));
|
||||||
label_.set_markup(fmt::vformat(format_, store));
|
label_.set_markup(fmt::vformat(format_, store));
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user