语境:
由于我的二合一敞篷车缺少驱动程序,向后折叠屏幕只会触发盖子开关事件。这会导致笔记本电脑挂起,或者当在 Gnome 中禁用“笔记本电脑盖关闭时挂起”时,仍然会导致所有输入设备被禁用(包括触摸屏,这使得平板电脑模式无用)。
作为解决方法,我想手动切换到平板电脑模式。这需要禁止所有盖子开关事件。
问题:
如何在 Linux 中完全抑制盖子开关事件?
或者,找到一种方法来列出/禁用响应盖子开关的进程可以解决该问题。
目前,在平板电脑模式下折叠屏幕并返回会记录以下事件:
Jul 25 23:58:54 jl-xps systemd-logind[816]: Lid closed.
Jul 25 23:58:58 jl-xps systemd-logind[816]: Lid opened.
盖子开关事件映射到/dev/input/event0
。/proc/bus/input/devices
列表(已截断):
I: Bus=0019 Vendor=0000 Product=0005 Version=0000
N: Name="Lid Switch"
P: Phys=PNP0C0D/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input0
U: Uniq=
H: Handlers=event0
B: PROP=0
B: EV=21
B: SW=1
尝试:
方法一:systemd-inhibit
, 取自如何禁用关闭笔记本电脑盖子时的自动暂停?
# systemd-inhibit --what=handle-lid-switch sleep 1m
然后在计时器结束之前翻转屏幕。盖子开关事件仍然由 记录systemd-logind
,并且我可以看到/dev/input/event0
正在写入(并且其他输入设备仍然被禁用)。
方法二:ACPI
$ echo "LID0" | sudo tee /proc/acpi/wakeup
并检查它是否确实被禁用:
LID0 S3 *disabled platform:PNP0C0D:00
具有相同的systemd-logind
日志并且/dev/input/event0
仍在写入。
方法三: 蛮力
# mv /dev/input/event0 /dev/input/event0-off
# ln -s /dev/null /dev/input/event0
盖子开关事件仍由 记录systemd-logind
。所以看来这/dev/input/event0
只是信息性的。
系统信息:
$ inxi -Fxmz
System: Host: jl-xps Kernel: 4.18.0-0.rc5.git4.1.fc29.x86_64 x86_64 bits: 64 compiler: gcc v: 8.1.1
Desktop: Gnome 3.28.3 Distro: Fedora release 28 (Twenty Eight)
Machine: Type: Laptop System: Dell product: XPS 15 9575 v: N/A serial: <filter>
Mobo: Dell model: 0C32VW v: A00 serial: <filter> UEFI: Dell v: 1.1.5 date: 05/30/2018
Battery: ID-1: BAT0 charge: 72.3 Wh condition: 72.3/75.0 Wh (96%) model: BYD DELL TMFYT84 status: Full
Memory: RAM Report: permissions: Unable to run dmidecode. Are you root?
CPU: Topology: Quad Core model: Intel Core i7-8705G bits: 64 type: MT MCP arch: Skylake rev: 9
L2 cache: 8192 KiB
flags: lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 49536
Speed: 900 MHz min/max: 800/4100 MHz Core speeds (MHz): 1: 900 2: 900 3: 900 4: 900 5: 900 6: 900
7: 900 8: 900
Graphics: Card-1: Intel driver: i915 v: kernel bus ID: 00:02.0
Card-2: Advanced Micro Devices [AMD/ATI] Polaris 22 [Radeon RX Vega M GL] driver: amdgpu v: kernel
bus ID: 01:00.0
Display: wayland server: Fedora Project X.org 11.0 driver: amdgpu resolution: 3840x2160~60Hz
OpenGL: renderer: Mesa DRI Intel HD Graphics 630 (Kaby Lake GT2) v: 4.5 Mesa 18.1.4
direct render: Yes
Audio: Card-1: Intel CM238 HD Audio driver: snd_hda_intel v: kernel bus ID: 00:1f.3
Card-2: N/A type: USB driver: snd-usb-audio bus ID: 3:2
Sound Server: ALSA v: k4.18.0-0.rc5.git4.1.fc29.x86_64
Network: Card-1: Qualcomm Atheros QCA6174 802.11ac Wireless Network Adapter driver: ath10k_pci v: kernel
bus ID: 02:00.0
IF: wlp2s0 state: up mac: <filter>
Card-2: Intel I210 Gigabit Network Connection driver: igb v: 5.4.0-k port: 2000 bus ID: 40:00.0
IF: enp64s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
Card-3: Realtek RTL8153 Gigabit Ethernet Adapter type: USB driver: r8152 bus ID: 10:3
IF: enp65s0u2u2 state: down mac: <filter>
IF-ID-1: tap0 state: unknown speed: 10 Mbps duplex: full mac: <filter>
IF-ID-2: virbr0 state: up speed: N/A duplex: N/A mac: <filter>
IF-ID-3: virbr0-nic state: down mac: <filter>
Drives: HDD Total Size: 232.89 GiB used: 77.91 GiB (33.5%)
ID-1: /dev/sda type: USB vendor: Samsung model: Portable SSD T3 size: 232.89 GiB
RAID: Hardware-1: Intel 82801 Mobile SATA Controller [RAID mode] driver: ahci v: 3.0 bus ID: 00:17.0
Partition: ID-1: / size: 114.35 GiB used: 77.69 GiB (67.9%) fs: ext4 dev: /dev/sda3
ID-2: /boot size: 975.9 MiB used: 202.9 MiB (20.8%) fs: ext4 dev: /dev/sda2
ID-3: swap-1 size: 16.00 GiB used: 0 KiB (0.0%) fs: swap dev: /dev/sda4
Sensors: System Temperatures: cpu: 50.0 C mobo: 37.0 C gpu: amdgpu temp: 49 C
Fan Speeds (RPM): cpu: 0
Info: Processes: 381 Uptime: 3h 01m Memory: 15.36 GiB used: 7.66 GiB (49.9%) Init: systemd runlevel: 5
Compilers: gcc: 8.1.1 Shell: fish v: 2.7.1 inxi: 3.0.14
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ xwayland-pointer:15 id=6 [slave pointer (2)]
⎜ ↳ xwayland-relative-pointer:15 id=7 [slave pointer (2)]
⎜ ↳ xwayland-touch:15 id=9 [slave pointer (2)]
⎜ ↳ xwayland-stylus:15 id=10 [slave pointer (2)]
⎜ ↳ xwayland-eraser:15 id=11 [slave pointer (2)]
⎜ ↳ xwayland-cursor:15 id=12 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ xwayland-keyboard:15 id=8 [slave keyboard (3)]
sudo libinput debug-events
以下是更改为平板电脑模式并返回笔记本电脑模式时的输出(禁用盖子开关设备):
-event3 DEVICE_ADDED Power Button seat0 default group1 cap:k
-event5 DEVICE_ADDED Video Bus seat0 default group2 cap:k
-event1 DEVICE_ADDED Power Button seat0 default group3 cap:k
-event2 DEVICE_ADDED Sleep Button seat0 default group4 cap:k
-event9 DEVICE_ADDED Integrated_Webcam_HD: Integrate seat0 default group5 cap:k
-event10 DEVICE_ADDED Integrated_Webcam_HD: Integrate seat0 default group5 cap:k
-event13 DEVICE_ADDED Wacom HID 486A Pen seat0 default group6 cap:T size 344x194mm calib
-event14 DEVICE_ADDED Wacom HID 486A Finger seat0 default group6 cap:t size 344x194mm ntouches 10 calib
-event12 DEVICE_ADDED DELL080D:00 06CB:7A13 Touchpad seat0 default group7 cap:pg size 102x77mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on
-event15 DEVICE_ADDED CalDigit, Inc. CalDigit Thunderbolt 3 Audio seat0 default group8 cap:k
-event16 DEVICE_ADDED Razer Razer Imperator seat0 default group9 cap:p left scroll-nat scroll-button
-event23 DEVICE_ADDED Razer Razer Imperator Keyboard seat0 default group9 cap:k
-event24 DEVICE_ADDED Razer Razer Imperator Consumer Control seat0 default group9 cap:kp scroll-nat
-event25 DEVICE_ADDED Razer Razer Imperator System Control seat0 default group9 cap:k
-event26 DEVICE_ADDED TypeMatrix.com USB Keyboard seat0 default group10 cap:k
-event27 DEVICE_ADDED TypeMatrix.com USB Keyboard System Control seat0 default group10 cap:k
-event28 DEVICE_ADDED TypeMatrix.com USB Keyboard Consumer Control seat0 default group10 cap:kp scroll-nat
-event8 DEVICE_ADDED Intel Virtual Button driver seat0 default group11 cap:kS
-event17 DEVICE_ADDED HDA Intel PCH Headphone Mic seat0 default group12 cap:
-event18 DEVICE_ADDED HDA Intel PCH HDMI/DP,pcm=3 seat0 default group12 cap:
-event19 DEVICE_ADDED HDA Intel PCH HDMI/DP,pcm=7 seat0 default group12 cap:
-event20 DEVICE_ADDED HDA Intel PCH HDMI/DP,pcm=8 seat0 default group12 cap:
-event21 DEVICE_ADDED HDA Intel PCH HDMI/DP,pcm=9 seat0 default group12 cap:
-event22 DEVICE_ADDED HDA Intel PCH HDMI/DP,pcm=10 seat0 default group12 cap:
-event6 DEVICE_ADDED Intel HID events seat0 default group13 cap:k
-event7 DEVICE_ADDED Intel HID 5 button array seat0 default group14 cap:k
-event11 DEVICE_ADDED Dell WMI hotkeys seat0 default group15 cap:k
-event4 DEVICE_ADDED AT Translated Set 2 keyboard seat0 default group16 cap:k
-event8 SWITCH_TOGGLE +3.90s switch tablet-mode state 1
event8 SWITCH_TOGGLE +5.44s switch tablet-mode state 0
有关此“英特尔虚拟按钮驱动程序”的更多详细信息,该驱动程序似乎负责切换到tablet-mode
:
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="Intel Virtual Button driver"
P: Phys=
S: Sysfs=/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/INT33D6:00/input/input8
U: Uniq=
H: Handlers=kbd event8
B: PROP=0
B: EV=33
B: KEY=2000000000000 0 0 0 0 1000000000000 0 201c000000000000 0
B: MSC=10
B: SW=2
$ find /sys/bus/ -name 'PNP0C09:00'
/sys/bus/platform/devices/PNP0C09:00
/sys/bus/acpi/devices/PNP0C09:00
/sys/bus/acpi/drivers/ec/PNP0C09:00
$ find /sys/devices/ -name 'PNP0C09:00'
/sys/devices/pci0000:00/0000:00:1f.0/PNP0C09:00
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:11/PNP0C09:00
$ udevadm info /sys/class/input/event8
P: /devices/pci0000:00/0000:00:1f.0/PNP0C09:00/INT33D6:00/input/input8/event8
N: input/event8
S: input/by-path/pci-0000:00:1f.0-platform-INT33D6:00-event
E: DEVLINKS=/dev/input/by-path/pci-0000:00:1f.0-platform-INT33D6:00-event
E: DEVNAME=/dev/input/event8
E: DEVPATH=/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/INT33D6:00/input/input8/event8
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_INPUT_SWITCH=1
E: ID_PATH=pci-0000:00:1f.0-platform-INT33D6:00
E: ID_PATH_TAG=pci-0000_00_1f_0-platform-INT33D6_00
E: MAJOR=13
E: MINOR=72
E: SUBSYSTEM=input
E: TAGS=:power-switch:
E: USEC_INITIALIZED=5811208
答案1
您可以在父设备上测试解除绑定驱动程序。这将删除子设备input0
-以及那里的任何其他子设备。
cd /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00
echo PNP0C0D:00 | sudo tee driver/unbind
第二个例子,基于您提到的其他输入设备:
cd /sys/devices/pci0000:00/0000:00:1f.0/PNP0C09:00/INT33D6:00
echo INT33D6:00 | sudo tee driver/unbind
(如果您安排这样的命令自动运行,您将需要确保它在驱动程序绑定后运行......在很多情况下,我认为您可以将其放入rc.local
)。
进一步阅读
LWN.net 在此描述了此功能:手动绑定和解绑驱动。
答案2
你可以坚持不懈地通过更改 中的 systemd-logind 配置来忽略盖子开关事件/etc/systemd/logind.conf
。
从我自己的系统来看:
[Login]
HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore
进行更改后,您可以systemctl restart systemd-logind
使其生效。