That's caused by the latest gnome-settings-daemon
updates...
There is no such option in power settings because it was removed by the GNOME devs (the shutdown/power off
action is considered "too destructive").
Bottom line: you can no longer power off your laptop by pressing the power off button.
You could however add a new dconf
/gsettings
option (i.e.shutdown
) to the settings daemon power plugin if you're willing to patch and rebuild gnome-settings-daemon
:
--- gnome-settings-daemon-3.18.2/data/gsd-enums.h 2015-11-10 09:07:12.000000000 -0500
+++ gnome-settings-daemon-3.18.2/data/gsd-enums.h 2015-11-11 18:43:43.240794875 -0500
@@ -114,7 +114,8 @@
{
GSD_POWER_BUTTON_ACTION_NOTHING,
GSD_POWER_BUTTON_ACTION_SUSPEND,
- GSD_POWER_BUTTON_ACTION_HIBERNATE
+ GSD_POWER_BUTTON_ACTION_HIBERNATE,
+ GSD_POWER_BUTTON_ACTION_SHUTDOWN
} GsdPowerButtonActionType;
typedef enum
--- gnome-settings-daemon-3.18.2/plugins/media-keys/gsd-media-keys-manager.c 2015-11-10 09:07:12.000000000 -0500
+++ gnome-settings-daemon-3.18.2/plugins/media-keys/gsd-media-keys-manager.c 2015-11-11 18:47:52.388602012 -0500
@@ -1849,6 +1849,9 @@
action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
switch (action_type) {
+ case GSD_POWER_BUTTON_ACTION_SHUTDOWN:
+ do_config_power_action (manager, GSD_POWER_ACTION_SHUTDOWN, in_lock_screen);
+ break;
case GSD_POWER_BUTTON_ACTION_SUSPEND:
do_config_power_action (manager, GSD_POWER_ACTION_SUSPEND, in_lock_screen);
break;
Once you install the patched version, a new shutdown
option will be available in dconf-editor
under org > gnome > settings-daemon > plugins > power > power-button-action:
so select that to shutdown via power button or, if you prefer CLI, run in terminal:
gsettings set org.gnome.settings-daemon.plugins.power power-button-action shutdown
Sure, for the above to work you also need the right settings in /etc/systemd/logind.conf
:
HandlePowerKey=poweroff
PowerKeyIgnoreInhibited=yes
Keep in mind that pressing the power button will shutdown your system without any warning.
It turns out that you can determine the status of the system by checking the output of
systemctl is-system-running # See man 1 systemctl for more info
In your case, I recommend wrapping the part responsible for turning off your lamps with:
if [[ "$(systemctl is-system-running || true)" == "stopping" ]]; then
# RUN THE COMMANDS OR EXECUTABLES FOR TURNING OFF THE LAMP HERE
fi
Of course, you could always inline the check directly in ExecStop if you don't want to maintain a separate wrapper (i.e ExecStop=sh -c 'if ... fi
).
Best Answer
systemd
can handle this. I think this is what you need:Open the
/etc/systemd/logind.conf
(manual):HandlePowerKey
: action on power key is pressed;HandleSuspendKey
: action on suspend key is pressed.HandleHibernateKey
: action on hibernate key is pressed.HandleLidSwitch
: action when the lid is closed.The action can be one of
ignore
,poweroff
,reboot
,halt
,suspend
,hibernate
orkexec
.If no configuration, default values used:
HandlePowerKey=poweroff
HandleSuspendKey=suspend
HandleHibernateKey=hibernate
HandleLidSwitch=suspend