From 00e60387069a09f236627c883356a0f0f1f61ca4 Mon Sep 17 00:00:00 2001 From: SirBlob Date: Sat, 3 Oct 2026 17:42:37 -0400 Subject: [PATCH] Read and set power profiles over D-Bus --- bin/blob-power-list | 17 ++++++++++------- bin/blob-power-set | 3 ++- shell/plugins/menu/Menu.qml | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/blob-power-list b/bin/blob-power-list index 59c51cc..6fc494d 100755 --- a/bin/blob-power-list +++ b/bin/blob-power-list @@ -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" diff --git a/bin/blob-power-set b/bin/blob-power-set index 66516ff..4308749 100755 --- a/bin/blob-power-set +++ b/bin/blob-power-set @@ -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" diff --git a/shell/plugins/menu/Menu.qml b/shell/plugins/menu/Menu.qml index cb68ac5..0a72734 100644 --- a/shell/plugins/menu/Menu.qml +++ b/shell/plugins/menu/Menu.qml @@ -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) } }