命令行设置触摸板轻触为点击

起因

在 Linux 下使用触摸板的时候总是需要重按下去才是点击操作,个人更喜欢轻触点击的中操作方式,网上搜索基本都是依靠 GDM/KDM 这种桌面管理其实现的修改方式,自己使用的 i3-wm 的平铺式桌面,基本上就只有修改对应的配置文件或者命令行方式了,就研究了一番,把对应的命令操作记录下来,在 Archlinux 上我用到的就 xinput 这一条命令了。

实现方式

首先查看设备列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
xinput           
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Mouse id=16 [slave pointer (2)]
⎜ ↳ Touchpad id=17 [slave pointer (2)]
⎜ ↳ SONiX USB DEVICE Consumer Control id=11 [slave pointer (2)]
⎜ ↳ USB Optical Mouse id=21 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Video Bus id=8 [slave keyboard (3)]
↳ Power Button id=9 [slave keyboard (3)]
↳ Sleep Button id=10 [slave keyboard (3)]
↳ HD WebCam: HD WebCam id=18 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=19 [slave keyboard (3)]
↳ Acer WMI hotkeys id=20 [slave keyboard (3)]
↳ SONiX USB DEVICE Consumer Control id=12 [slave keyboard (3)]
↳ SONiX USB DEVICE Keyboard id=13 [slave keyboard (3)]
↳ SONiX USB DEVICE System Control id=14 [slave keyboard (3)]
↳ SONiX USB DEVICE id=15 [slave keyboard (3)]

其中 id=16 的设备则为笔记本上的触摸板模拟鼠标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
xinput list-props 17
Device ' Touchpad':
Device Enabled (169): 1
Coordinate Transformation Matrix (171): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
libinput Tapping Enabled (324): 0
libinput Tapping Enabled Default (325): 0
libinput Tapping Drag Enabled (326): 1
libinput Tapping Drag Enabled Default (327): 1
libinput Tapping Drag Lock Enabled (328): 0
libinput Tapping Drag Lock Enabled Default (329): 0
libinput Tapping Button Mapping Enabled (330): 1, 0
libinput Tapping Button Mapping Default (331): 1, 0
libinput Natural Scrolling Enabled (304): 0
libinput Natural Scrolling Enabled Default (305): 0
libinput Disable While Typing Enabled (332): 1
libinput Disable While Typing Enabled Default (333): 1
libinput Scroll Methods Available (308): 1, 1, 0
libinput Scroll Method Enabled (309): 1, 0, 0
libinput Scroll Method Enabled Default (310): 1, 0, 0
libinput Click Methods Available (334): 1, 1
libinput Click Method Enabled (335): 1, 0
libinput Click Method Enabled Default (336): 1, 0
libinput Middle Emulation Enabled (315): 0
libinput Middle Emulation Enabled Default (316): 0
libinput Accel Speed (317): 0.000000
libinput Accel Speed Default (318): 0.000000
libinput Left Handed Enabled (322): 0
libinput Left Handed Enabled Default (323): 0
libinput Send Events Modes Available (289): 1, 1
libinput Send Events Mode Enabled (290): 0, 0
libinput Send Events Mode Enabled Default (291): 0, 0
Device Node (292): "/dev/input/event8"
Device Product ID (293): 1739, 10608
libinput Drag Lock Buttons (306): <no items>
libinput Horizontal Scroll Enabled (307): 1

其中属性 libinput Tapping Enabled (324) 和 325 则是轻触点击,当前值均为0,被禁用,将对应值设置为1即可启用轻触点击。

1
xinput set-prop 17 324 1

device id 会在重启后变更,因此可以使用对应字符串获取对应 device id,然后再获取到对应的属性,将其开启:

1
deviceid=`xinput | grep "Touchpad" | awk -F" " {'print $4'} | awk -F"=" {'print $2'}`

获取到 device id。

1
2
3
4
propid=`xinput list-props ${deviceid} | grep "libinput Tapping Enabled (" | awk -F" " {'print $4'}
propid=${propid:1:3}
echo $propid
324

再获取到属性 id。

接着就可以直接对 device id 和其对应的属性 id 设置值。

1
xinput set-prop ${deviceid} ${propid} 1

然后把这些组成 shell 脚本,再添加开机启动任务就可以生效了。