power: Automatically determine whether systemctl or loginctl should be used

This commit is contained in:
elenapan 2025-04-05 17:45:58 +03:00
parent ba4b40cb2a
commit 21c2379bbe
2 changed files with 15 additions and 5 deletions

View file

@ -9,22 +9,28 @@ fi
action=$1
if command -v systemctl >/dev/null; then
ctl=systemctl
else
ctl=loginctl
fi
poweroff() {
loginctl poweroff
"$ctl" poweroff
}
reboot() {
loginctl reboot
"$ctl" reboot
}
suspend() {
"${eww}/manage" hide powermenu
loginctl suspend
"$ctl" suspend
}
hibernate() {
"${eww}/manage" hide powermenu
loginctl hibernate
"$ctl" hibernate
}
exit() {

View file

@ -21,7 +21,11 @@ notify() {
wait_countdown_suspend() {
if ! zenity --icon-name battery-empty --question --timeout=10 --text="Keep machine on?\n\nIt will suspend if no answer is given in 10 seconds"; then
notify-send.sh -s "$(</tmp/countdown-notifications-file)"
loginctl suspend
if command -v systemctl >/dev/null; then
systemctl suspend
else
loginctl suspend
fi
fi
}