feat(power): add controls for power button behavior#2014
Conversation
Adds a section to the power submenu allowing the user to select from the following power button behaviors: - Confirm Shutdown (default, existing behavior) - cosmic-osd shutdown - Confirm Log Out - cosmic-osd logout - Confirm Restart - cosmic-osd restart - Shutdown - systemctl poweroff - Log Out - loginctl terminate-user $USER - Restart - systemctl reboot - Suspend - systemctl suspend - Hibernate - systemctl hibernate The default option is 'Confirm Shutdown', unchanged from prior to this commit. If the value at ~/.config/cosmic/com.system76.CosmicSettings.Shortcuts/v1/system_actions has been customized to some command outside of this list, that value will not be overwritten unless the user selects an item in the list again. Closes pop-os#1664
| Some(cmd) if cmd == "systemctl reboot" => Some(Self::Restart), | ||
| Some(cmd) if cmd == "systemctl suspend" => Some(Self::Suspend), | ||
| Some(cmd) if cmd == "systemctl hibernate" => Some(Self::Hibernate), | ||
| // Only return None if the user has customized the command |
There was a problem hiding this comment.
The power button behavior is managed by logind on systemd systems so it should obtain the value from this. In /etc/systemd/logind.conf, there is a HandlePowerKey option which defaults to poweroff. But you should get the value of this key directly from the DBus service with https://docs.rs/logind-zbus/latest/logind_zbus/manager/struct.ManagerProxy.html#method.handle_power_key.
There was a problem hiding this comment.
When I was first looking into this, it seemed that cosmic-session inhibits logind from receiving the button press event so it can handle it internally. For my understanding, are you proposing that I retain the logind inhibitor in cosmic-session, but respect/update the logind configuration anyway?
If the goal is to respect logind.conf, I'm not entirely certain why we'd still want to take the inhibitor lock, and vice-versa if the goal is to handle the button event internally for compat with non-systemd systems then this would leave us with a behavior gap to reconcile. Alternately, maybe there needs to be a specific config option to not take the inhibitor and let the system handle the button press however it's configured.
Happy to make the tweak either way, just want to make sure I understand the desired functionality here. My initial approach was just to edit the existing cosmic shortcut configuration to keep things tidy.
There was a problem hiding this comment.
Just so we're on the same page, here's the source for the systemd/logind inhibitor that I'm referring to: https://github.com/pop-os/cosmic-session/blob/master/src/main.rs#L194-L199
Adds a section to the power submenu allowing the user to select from the
following power button behaviors:
The default option is 'Confirm Shutdown', unchanged from prior to this
commit.
If the value at ~/.config/cosmic/com.system76.CosmicSettings.Shortcuts/v1/system_actions
has been customized to some command outside of this list, that value
will not be overwritten unless the user selects an item in the list
again.
Closes #1664