Fix: Leave logind alone while a desktop session is running

This commit is contained in:
Gabriel Brown
2026-09-22 14:04:32 -04:00
parent 9022847971
commit 05054afdc9
+23 -3
View File
@@ -38,13 +38,33 @@ if [[ -f /etc/udev/rules.d/99-panama-gpu.rules ]]; then
fi fi
# The power-key drop-in lands via the same copy; logind reads its config only # The power-key drop-in lands via the same copy; logind reads its config only
# at start, so without this the button keeps hard-powering-off until the next # at start. Restarting logind under a running Wayland or X11 session drops that
# boot. Restarting logind is what Fedora's own updates do and current systemd # session and takes the desktop down with it, so the restart happens only when
# preserves sessions across it. # logind is not already honouring the drop-in AND no graphical session is live.
# Otherwise the change waits for the next boot, which is harmless: the answer
# is usually already "ignore" from an earlier run.
graphical_session_active() {
local id
for id in $(loginctl list-sessions --no-legend 2>/dev/null | awk '{ print $1 }'); do
case "$(loginctl show-session "$id" -p Type --value 2>/dev/null)" in
wayland|x11) return 0 ;;
esac
done
return 1
}
if [[ -f /etc/systemd/logind.conf.d/panama-power-key.conf ]]; then if [[ -f /etc/systemd/logind.conf.d/panama-power-key.conf ]]; then
power_key="$(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 \
org.freedesktop.login1.Manager HandlePowerKey 2>/dev/null)" || power_key=""
if [[ "$power_key" == 's "ignore"' ]]; then
log "logind already leaves the power button to the power menu"
elif graphical_session_active; then
log "A desktop session is running; the power-button change applies at next boot"
else
log "Reloading logind so the power button opens the menu instead of powering off" log "Reloading logind so the power button opens the menu instead of powering off"
sudo systemctl try-restart systemd-logind 2>/dev/null \ sudo systemctl try-restart systemd-logind 2>/dev/null \
|| log "Could not restart logind; the power-button change applies at next boot" || log "Could not restart logind; the power-button change applies at next boot"
fi
fi fi
# The document-portal drop-in lands via the same copy. A user unit's drop-ins # The document-portal drop-in lands via the same copy. A user unit's drop-ins