diff --git a/setup/scripts/change-settings b/setup/scripts/change-settings index 3687d17..9f80586 100755 --- a/setup/scripts/change-settings +++ b/setup/scripts/change-settings @@ -38,13 +38,33 @@ if [[ -f /etc/udev/rules.d/99-panama-gpu.rules ]]; then fi # 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 -# boot. Restarting logind is what Fedora's own updates do and current systemd -# preserves sessions across it. +# at start. Restarting logind under a running Wayland or X11 session drops that +# session and takes the desktop down with it, so the restart happens only when +# 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 - log "Reloading logind so the power button opens the menu instead of powering off" - sudo systemctl try-restart systemd-logind 2>/dev/null \ - || log "Could not restart logind; the power-button change applies at next boot" + 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" + sudo systemctl try-restart systemd-logind 2>/dev/null \ + || log "Could not restart logind; the power-button change applies at next boot" + fi fi # The document-portal drop-in lands via the same copy. A user unit's drop-ins