Created
May 31, 2023 16:37
-
-
Save christian-oudard/485f06833d2468c4179147d13563b594 to your computer and use it in GitHub Desktop.
handler.sh for acpid in Arch Linux, handling pactl permissions and environment variable issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /etc/acpi/handler.sh | |
TARGET_UID=1000 | |
my_pactl() { | |
setpriv --reuid $TARGET_UID sh -c "XDG_RUNTIME_DIR=/run/user/$TARGET_UID pactl $*" | |
} | |
case "$1" in | |
button/power) | |
case "$2" in | |
PBTN|PWRF) | |
logger 'PowerButton pressed' | |
;; | |
*) | |
logger "ACPI action undefined: $2" | |
;; | |
esac | |
;; | |
button/sleep) | |
case "$2" in | |
SLPB|SBTN) | |
logger 'SleepButton pressed' | |
;; | |
*) | |
logger "ACPI action undefined: $2" | |
;; | |
esac | |
;; | |
ac_adapter) | |
case "$2" in | |
AC|ACAD|ADP0) | |
case "$4" in | |
00000000) | |
logger 'AC unplugged' | |
;; | |
00000001) | |
logger 'AC plugged' | |
;; | |
esac | |
;; | |
*) | |
logger "ACPI action undefined: $2" | |
;; | |
esac | |
;; | |
battery) | |
case "$2" in | |
BAT0) | |
case "$4" in | |
00000000) | |
logger 'Battery online' | |
;; | |
00000001) | |
logger 'Battery offline' | |
;; | |
esac | |
;; | |
CPU0) | |
;; | |
*) logger "ACPI action undefined: $2" ;; | |
esac | |
;; | |
button/lid) | |
case "$3" in | |
close) | |
logger 'LID closed' | |
;; | |
open) | |
logger 'LID opened' | |
;; | |
*) | |
logger "ACPI action undefined: $3" | |
;; | |
esac | |
;; | |
button/mute) | |
my_pactl set-sink-mute @DEFAULT_SINK@ toggle | |
logger 'Mute button pressed' | |
;; | |
button/volumeup) | |
my_pactl set-sink-mute @DEFAULT_SINK@ 0 | |
my_pactl set-sink-volume @DEFAULT_SINK@ +5% | |
logger 'Volume up' | |
;; | |
button/volumedown) | |
my_pactl set-sink-volume @DEFAULT_SINK@ -5% | |
logger 'Volume down' | |
;; | |
video/brightnessup) | |
brightnessctl --min-value=1 --exponent set 5%+ | |
logger "Brightness up, $(brightnessctl get)" | |
;; | |
video/brightnessdown) | |
brightnessctl --min-value=1 --exponent set 5%- | |
logger "Brightness down, $(brightnessctl g)" | |
;; | |
*) | |
# logger "ACPI group/action undefined: $1 / $2" | |
;; | |
esac | |
# vim:set ts=4 sw=4 ft=sh et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment