How to make hardware power button suspend the computer?

Using GNOME 48.2 on Debian testing.

I have:

$ gsettings get org.gnome.settings-daemon.plugins.power power-button-action
'suspend'

and yet when I press the power button on the laptop, the shutdown dialog appears. :frowning:

I looked in the tweak tool and cannot find a setting for this. This thread shows there used to be a “shell” section, but it’s not there for me. Here is what I see:

Hi, you can change power button behavior under the Power settings in the normal (not Tweaks) control center.

There is quite some logic to determine possible options, and it may be that the “suspend” option won’t be one of them in this case. This depends on the capabilitities of your system. But you can suspend from the Shell menu normally?

There is nothing in the general power settings about the button:

Also I noticed that suspending from the menu does not do anything other than the following message appearing in the log:

lip 03 15:56:36 tinkpad2 gnome-shell[6657]: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
                                            @resource:///org/gnome/gjs/modules/core/overrides/Gio.js:192:20
                                            suspend@resource:///org/gnome/shell/misc/loginManager.js:215:21
                                            activateSuspend@resource:///org/gnome/shell/misc/systemActions.js:465:28
                                            _init/<@resource:///org/gnome/shell/ui/status/system.js:177:33
                                            addAction/<@resource:///org/gnome/shell/ui/popupMenu.js:753:21
                                            activate@resource:///org/gnome/shell/ui/popupMenu.js:193:14
                                            _init/<@resource:///org/gnome/shell/ui/popupMenu.js:110:24
                                            @resource:///org/gnome/shell/ui/init.js:21:20

However the system suspends as expected when I simply close the lid.

How can I investigate this further?

The gnome-control-center section Matthijs tell you about only appears if any of CanSuspend or CanHibernate methods returned “yes”, so it seems both fail for you, you can confirm this by running them from terminal:

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.CanSuspend
and
dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.CanHibernate

The section also is not shown when you’re in a VM or a tablet or handset, the complete condition is this:

if ((can_hibernate || can_suspend) &&
      g_strcmp0 (self->chassis_type, "vm") != 0 &&
      g_strcmp0 (self->chassis_type, "tablet") != 0 &&
      g_strcmp0 (self->chassis_type, "handset") != 0)
    {

Code here.

The former yields challenge, the latter – na.

OTOH AFAICT polkit seems to think I should be able to suspend:

$ pkcheck -p $$ -a org.freedesktop.login1.suspend
$ echo $?
0

:man_shrugging:

And after a reboot, the former now returns yes. :man_shrugging:
Sometimes I miss the old times when Linux desktop was crude, but simpler and easier to understand… :frowning: