Devices

如何完全抑制蓋子開關事件?

  • July 26, 2018

語境:

由於我的 2 合 1 敞篷車缺少驅動程序,將螢幕向後折疊只會觸發蓋子開關事件。這會導致筆記型電腦掛起,或者當在 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

嘗試:

方法1:,systemd-inhibit取自關閉筆記型電腦蓋時如何禁用自動掛起?

# systemd-inhibit --what=handle-lid-switch sleep 1m

然後在定時器結束前翻轉螢幕。蓋子開關事件仍然由 記錄systemd-logind,我可以看到/dev/input/event0正在寫入(並且其他輸入設備仍然被禁用)。

方法 2:ACPI

$ echo "LID0" | sudo tee /proc/acpi/wakeup

並檢查它是否確實被禁用:

LID0      S3    *disabled  platform:PNP0C0D:00

使用相同的systemd-logind日誌並且/dev/input/event0仍然被寫入。

方法3:蠻力

# 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

您可以測試取消綁定父設備上的驅動程序。這將刪除子設備以及存在的任何其他子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 在此處描述了此功能:手動驅動程序綁定和解除綁定

引用自:https://unix.stackexchange.com/questions/458486