运行 X11 我可以安装 acpid 并修改 /etc/acpi/handler.sh 脚本以使用 xinput 来执行此操作:
button/lid)
case "$3" in
close)
#set variables so xinput can access the desktop session
XAUTHORITY=/home/netsplit/.Xauthority DISPLAY=:0 xinput disable 10
XAUTHORITY=/home/netsplit/.Xauthority DISPLAY=:0 xinput disable 11
logger 'LID closed'
;;
open)
XAUTHORITY=/home/netsplit/.Xauthority DISPLAY=:0 xinput enable 10
XAUTHORITY=/home/netsplit/.Xauthority DISPLAY=:0 xinput enable 11
logger 'LID opened'
然而 xinput 不适用于 Wayland。此外,xauthority 也与 Wayland 无关。我查看了 libinput 但它似乎没有提供从 shell 禁用/启用某些功能的方法。
睡眠不是一个选项,因为我更喜欢手动启用睡眠。有时我会在笔记本电脑盖上盖子的情况下处理一些事情。
有时,当盖子关闭时,触控板和键盘会关闭,所以回到一堆文本和窗口。在X下,当盖子关闭时禁用它们修复了这个问题。试图让 Wayland 工作。
答案1
好的,我找到了一个不仅仅适用于 Plasma 和 Wayland 的解决方案。
Linux 5.11 添加了抑制的输入设备的属性正是我想要的。
我所要做的就是:
cat /proc/bus/input/devices | more
然后查找输入设备 Sysfs=... 值。
例如键盘是:
I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input3
U: Uniq=
H: Handlers=sysrq kbd leds event3 rfkill
B: PROP=0
B: EV=120013
B: KEY=20000 20 0 0 1100f02100000 3803078f900d401 feffffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7
Sysfs=/devices/platform/i8042/serio0/input/input3 告诉我,如果我向 /sys/devices/platform/i8042/serio0/input/input3/inhibited 写入 1,那么内核将禁用键盘输入。如果不重新启动,这将很难修复,因此请小心执行此操作。
同样,触摸板的值 Sysfs=/devices/platform/i8042/serio1/input/input8。一样。 echo 1 > /sys/devices/platform/i8042/serio1/input/input8/inhibited 将禁用触摸板。
这里有这些部分就是如何做到这一点。
安装 acpid (确切的命令取决于您的包管理器)
将 /etc/acpi/handler.sh 修改为靠近底部的内容。如果输入设备的 sysfs 值不同,您可能需要更改路径:
button/lid)
case "$3" in
close)
echo 1 > /sys/devices/platform/i8042/serio1/input/input8/inhibited
echo 1 > /sys/devices/platform/i8042/serio0/input/input3/inhibited
logger 'LID closed'
;;
open)
echo 0 > /sys/devices/platform/i8042/serio1/input/input8/inhibited
echo 0 > /sys/devices/platform/i8042/serio0/input/input3/inhibited
logger 'LID opened'
;;
*)
logger "ACPI action undefined: $3"
;;
供参考我的完整 /etc/acpi/handler.sh 文件:
#!/bin/bash
# Default acpi script that takes an entry for all actions
case "$1" in
button/up)
;;
button/down)
;;
button/right)
;;
button/left)
;;
button/power)
case "$2" in
PBTN|PWRF)
logger 'PowerButton pressed'
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
button/sleep)
case "$2" in
SLPB|SBTN)
logger 'SleepButton pressed'
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
ac_adapter)
case "$2" in
AC|ACAD|ADP0)
case "$4" in
00000000)
logger 'AC unpluged'
;;
00000001)
logger 'AC pluged'
;;
esac
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
battery)
case "$2" in
BAT0)
case "$4" in
00000000)
logger 'Battery online'
;;
00000001)
logger 'Battery offline'
;;
esac
;;
CPU0)
;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
button/lid)
case "$3" in
close)
echo 1 > /sys/devices/platform/i8042/serio1/input/input8/inhibited
echo 1 > /sys/devices/platform/i8042/serio0/input/input3/inhibited
logger 'LID closed'
;;
open)
echo 0 > /sys/devices/platform/i8042/serio1/input/input8/inhibited
echo 0 > /sys/devices/platform/i8042/serio0/input/input3/inhibited
logger 'LID opened'
;;
*)
logger "ACPI action undefined: $3"
;;
esac
;;
*)
logger "ACPI group/action undefined: $1 / $2"
;;
esac
# vim:set ts=4 sw=4 ft=sh et: