Same action is forced for lid-close on AC and lid-close on battery
Submitted by Kim Nguyen
Link to original bug (#790607)
Description
Created attachment 364040 Custom Suspend action
Since the action to perform on lid-closed has been transferred from gsd-power to logind, one has lost the ability to differentiate between the action to perform when on battery from the one to perform when on AC (admittedly because systemd-logind has no knowledge of ACPI events but gets the lid close/open from the input layer).
I only realised this recently when ubuntu switched to gnome-shell. Previously, ubuntu was using unity-settings-daemon by default (fork of an older version of gsd) which handled power policy itself.
This is a regression of a useful feature. For sure if you have a laptop you want to suspend when the lid is closed and on battery (and not plugged to external monitor or dock etc…).
But most of the time, when plugged on AC you don't want your background actions to stop when you close the lid (e.g. download, software update etc…).
The situation is a bit confusing because the corresponding gsettings still exist:
- org.gnome.settings-daemon.plugins.power lid-close-ac-action
- org.gnome.settings-daemon.plugins.power lid-close-battery-action
in but don't do anything.
As a reference, macos and windows 10 still allow the user to define a different lid close action for battery and AC (through their main UI none the less, it's not a hidden setting).
There is nothing that prevent the behaviour from being restored. I'm attaching a python script (lightly tested) to be launched with: systemd-inhibit --who=me --why=because --mode=block --what=handle-lid-switch /path/to/custom_suspend.py
That take whatever is in the gsettings mentioned above and performs the action (through systemd).
It's just a proof of concept. I think there is now a proliferation of systemd inhibitors to handle various cases that obviously systemd-logind cannot handle:
- inhibit when fullscreen application running
- handle battery/ac differently
- inhibit and handle the doc/screen/external peripherials correctly
Maybe systemd is the right place to have the suspend primitive enabled but the power-policy seems higher level than logind and centralized in a component (systemd-powerd ?), or have logind gain real power management policy handling.
Attachment 364040, "Custom Suspend action":
custom_suspend.py
Version: 3.26.x