To disable fingerprint authentication when the laptop lid is closed, and re-enable when it is reopened, we will use acpid to bind to the button/lid.* event to a custom script that will stop and mask the fprintd service on lid close, and unmask and start the fprintd service on lid open.
We also check that the HDMI cable is connected by testing the contents of /sys/class/drm/card1-HDMI-A-1/status.
Follow the steps below: (ThinkPad T440 ubunu 22.04)
-
Create file /etc/acpi/laptop-lid.sh with the following contents:
12345678910111213141516#!/bin/bashlock=$HOME/fprint-disabledif grep -Fq closed /proc/acpi/button/lid/LID/state &&grep -Fxq connected /sys/class/drm/card1-HDMI-A-1/statusthentouch "$lock"systemctl stop fprintdsystemctl mask fprintdelif [ -f "$lock" ]thensystemctl unmask fprintdsystemctl start fprintdrm "$lock"fi -
Make the file executable with
1chmod +x /etc/acpi/laptop-lid.sh -
Create file /etc/acpi/events/laptop-lid with the following contents:
12event=button/lid.*action=/etc/acpi/laptop-lid.sh -
Restart the acpid service with:
1sudo service acpid restart
Now the fingerprint will be used only when the lid is open.
In order to restore the correct state of the fprintd service if you disconnect/reconnect while the laptop is off, you may call the above script from a systemd init file. The steps to do this are the following:
-
Create a file named /etc/systemd/system/laptop-lid.service with the following contents:
12345678910[Unit]Description=Laptop LidAfter=suspend.target[Service]ExecStart=/etc/acpi/laptop-lid.sh[Install]WantedBy=multi-user.targetWantedBy=suspend.target -
Reload the systemd config files with
1sudo systemctl daemon-reload -
Start the service with
1sudo systemctl start laptop-lid.service -
Enable the service so that it starts automatically on boot
1sudo systemctl enable laptop-lid.serviceNow the status should be correct even after connecting/disconnecting when the computer is off.
References used for creating the code in the answer:
- How to run a script when the lid is closed?
- Laptop doesn't hibernate when I close the lid in Ubuntu 14.04
- Catch lid close and open events
参考链接