Skip to content

feat(power): add controls for power button behavior#2014

Open
gsboylan wants to merge 2 commits into
pop-os:masterfrom
gsboylan:master
Open

feat(power): add controls for power button behavior#2014
gsboylan wants to merge 2 commits into
pop-os:masterfrom
gsboylan:master

Conversation

@gsboylan
Copy link
Copy Markdown

@gsboylan gsboylan commented May 26, 2026

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 #1664

  • I have disclosed use of any AI generated code in my commit messages.
    • If you are using an LLM, and do not fully understand the changes it is making to the code base, do not create a PR.
    • In our experience, AI generated code often results in overly complex code that lacks enough context for a proper fix or feature inclusion. This results in considerably longer code reviews. Due to this, AI authored or partially authored PRs may be closed without comment.
  • I understand these changes in full and will be able to respond to review comments.
  • My change is accurately described in the commit message.
  • My contribution is tested and working as described.
  • I have read the Developer Certificate of Origin and certify my contribution under its conditions.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

@gsboylan gsboylan May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing power button and lid close behavior controls in Power settings

2 participants