Read and set power profiles over D-Bus

This commit is contained in:
SirBlob committed 2026-10-03 17:42:52 -04:00
1 parent 7e747d18bf
commit 00e6038706
3 files changed
+13 -9

No files matched your search

+10 -7
View File
@@ -8,10 +8,13 @@ if [[ ${1:-} != "" && ${1:-} != "--active-state" ]]; then
exit 1
fi
powerprofilesctl list 2>/dev/null |
awk -v with_state="${1:+1}" '/^\s*[* ]\s*[a-zA-Z0-9-]+:$/ {
active = ($1 == "*") ? 1 : 0
gsub(/^[*[:space:]]+|:$/, "")
print $0 (with_state ? "\t" active : "")
}' |
tac
service=org.freedesktop.UPower.PowerProfiles
object=/org/freedesktop/UPower/PowerProfiles
profiles_json=$(busctl --json=short get-property "$service" "$object" "$service" Profiles 2>/dev/null) || exit 0
active_profile=$(busctl --json=short get-property "$service" "$object" "$service" ActiveProfile 2>/dev/null | jq -r '.data // ""')
jq -r --arg active "$active_profile" --arg with_state "${1:+1}" '
.data[].Profile.data
| if $with_state == "1" then "\(.)\t\(if . == $active then 1 else 0 end)" else . end
' <<<"$profiles_json"
+2 -1
View File
@@ -55,7 +55,8 @@ if [[ -z ${profile:-} ]] || ! profile_available "$profile"; then
fi
fi
powerprofilesctl set "$profile" || exit
busctl set-property org.freedesktop.UPower.PowerProfiles /org/freedesktop/UPower/PowerProfiles \
org.freedesktop.UPower.PowerProfiles ActiveProfile s "$profile" || exit
if [[ -n $requested_profile ]]; then
mkdir -p "$state_dir"
+1 -1
View File
@@ -274,7 +274,7 @@ Item {
actionFor: function(value) { return "blob-font-set " + Util.shellQuote(value) }
},
"power-profiles": {
script: "current=$(powerprofilesctl get 2>/dev/null); blob-power-list 2>/dev/null | while read -r p; do [[ -z $p ]] && continue; printf '%s\\t%s\\t%s\\n' \"$p\" \"$p\" \"$current\"; done",
script: "current=$(blob-power-list --active-state 2>/dev/null | awk -F '\\t' '$2 == 1 { print $1 }'); blob-power-list 2>/dev/null | while read -r p; do [[ -z $p ]] && continue; printf '%s\\t%s\\t%s\\n' \"$p\" \"$p\" \"$current\"; done",
icon: "\udb81\udc0b",
actionFor: function(value) { return "blob-power-set autodetect " + Util.shellQuote(value) }
}