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 24.04)
-
Create file /etc/acpi/laptop-lid.sh with the following contents:
1234567$ sudo install acpid$ sudo mkdir /etc/acpi$ sudo install vim$ sudo vim /etc/acpi/laptop-lid.sh12345678910111213141516#!/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 mask fprintdsystemctl stop fprintdelif [ -f "$lock" ]thensystemctl unmask fprintdsystemctl start fprintdrm "$lock"fi -
Make the file executable with
1$ sudo chmod +x /etc/acpi/laptop-lid.sh -
Create file /etc/acpi/events/laptop-lid with the following contents:
1$ sudo mkdir /etc/acpi/events12event=button/lid.*action=/etc/acpi/laptop-lid.sh -
Restart the acpid service with:
1$ sudo 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
1$ sudo systemctl daemon-reload -
Start the service with
1$ sudo systemctl start laptop-lid.service -
Enable the service so that it starts automatically on boot
1$ sudo 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: