参考以下内容,翻译自:Login | InCareer
###########################################################################
现如今有各种各样的基于GUI(图形用户界面)的工具来编辑你的synaptics触摸板配置,这些工具绝大多数已在发行版本中被预先配置好。然而,在某些情况下,你可能想手动编辑这些配置。这可能因为你试图保持系统尽可能小,换句话说避免臃肿,也可能只是你想学习Xorg一节的不同输入设备是如何被配置的。本文将带你贯穿整个过程,包括:决定synaptics输入标识,在用户共享路径下创建一个配置文件备份,和定制化你的触摸板响应的不同选项。
在开始编辑配置文件之前,我们必须先决定是否一个“xorg.conf.d”目录存在于“/etc/X11”下。要找到是否此目录存在,改变路径命令可以被使用:
$ cd /etc/X11/xorg.conf.d/
如果目录不存在,不会导致任何错误,并且你将被引导到有问题的目录。然而,如果目录不存在,你将收到如下提示:
bash: cd: /etc/X11/xorg.conf.d/: No such file or directory
如果发生此问题,使用“mkdir”命令简单地创建目录即可,确保你首先已经获得了超级用户权限:
$ mkdir /etc/X11/xorg.conf.d/
Once it is created, it is time to check out the contents of ‘xorg.conf.d’ in the shared user directory. To do so, simply list the files within it using:
一旦目录被创建,是时候检查在用户共享目录下的“xorg.conf.d”目录的内容了。为此,简单列出其下的文件:
$ ls /usr/share/X11/xorg.conf.d/
假设你已经安装了synaptics驱动和“libinput”包,“/usr/share/X11/xorg.conf.d”目录应该显示以下文件,或者类似的内容:
40-libinput.conf 70-synaptics.conf
目录中感兴趣的两个地方是“40-libinput.conf”和“70-synaptics.conf”。前一个文件是libinput服务的配置文件,其处理系统中的多个输入设备,如键盘和操纵杆。另一个是synaptics驱动的配置文件,包含了触摸板相关配置。
如果你碰巧同时有了这两个文件,它意味着你有libinput和synaptics可安装和配置。注意所有的配置文件前面有不同的数字,这些数字决定了文件的数字顺序以优先级的形式,意味着在此场景中,synaptics文件将获得优先权。
Now that the location of the synaptics config file has been specified, you might be inclined to immediately attempt to edit its contents. However, editing this file is of no use as it is simply a template for reference that isn’t actually processed. You are now presented with two options, either create a symbolic link of this file in the directory ‘/etc/X11/xorg.conf.d/’, or simply copy the file over to it. The difference is that a symbolic link is simply a link to the file in ‘/usr/share/X11/xorg.conf.d/’, and while this allows you to sync edits in both locations, your system might overwrite the file in the shared user directory, thus rendering both files useless. Because of this, we’ll copy the file over instead, using the following command, under superuser permissions:
cp /usr/share/X11/xorg.conf.d/70-synaptics.conf /etc/X11/xorg.conf.d/70-synaptics.conf
With the synaptics configuration file prepared for editing, it is time to go over the structure of the file and how it is interpreted. The contents of this file can be viewed by using the ‘cat’ command, which should return multiple lines of code. You should find a code block similar to the one below, at the beginning of your file:
- Section "InputClass"
- Identifier "touchpad catchall"
- Driver "synaptics"
- MatchIsTouchpad "on"
- Option "Parameter" "Value"
- EndSection
The code block contains an identifier for the input device along with a line that specifies the driver used. The fifth line shows how an option sentence looks, which begins with the word ‘Option’, followed by the ‘Parameter’ to be configured, and its chosen variable. There are a set of parameters to check from and each are unique to the touchpad model you’re using. For reference, the Arch Linux documentation page titled Touchpad Synaptics contains some of the most used parameters in addition to a detailed description of each. Of course, in order to apply these settings, you’d have to reboot or simply reload the X session, in order words, log out and log back in.
###########################################################################
以上方法写得很细致,甚至有点“啰嗦”。其实就是修改/usr/share/X11/xorg.conf.d/70-synaptics.conf文件的内容,之后将其拷贝或者软链接到/etx/X11/xorg.conf.d/下。这样就可以按照用户需要的方式修改触摸板的默认选项了。
按照以上方法确实能够修改触摸板的默认行为,但是存在问题:如果不通过图形界面进行触摸板默认行为的修改,则此方法确实能够起作用。但是一旦通过图形界面进行了设置,重启或者重新登录后就会按照图形界面的设置进行配置了,70-synaptics.conf文件中修改的内容不再起作用,无论是在/usr/share/X11/xorg.conf.d/下还是/etc/X11/xorg.conf.d/下。
70-synaptics.conf文件的内容示例和注释如下:
- Section "InputClass"
- Identifier "touchpad catchall"
- Driver "synaptics"
- MatchIsTouchpad "on"
-
- Option "TapButton1" "1" #单指敲击产生左键事件
- Option "TapButton2" "2" #双指敲击产生中键事件
- Option "TapButton3" "3" #三指敲击产生右键事件
-
- Option "VertEdgeScroll" "on" #滚动操作:横向、纵向、环形
- Option "VertTwoFingerScroll" "on"
- Option "HorizEdgeScroll" "on"
- Option "HorizTwoFingerScroll" "on"
- Option "CircularScrolling" "on"
- Option "CircScrollTrigger" "2"
-
- Option "EmulateTwoFingerMinZ" "40" #精确度
- Option "EmulateTwoFingerMinW" "8"
- Option "CoastingSpeed" "20" #触发快速滚动的滚动速度
-
- Option "PalmDetect" "1" #避免手掌触发触摸板
- Option "PalmMinWidth" "3" #认定为手掌的最小宽度
- Option "PalmMinZ" "200" #认定为手掌的最小压力值
- EndSection
比如我已经做了如下配置:
- Section "InputClass"
- Identifier "touchpad catchall"
- Driver "synaptics"
- MatchIsTouchpad "on"
- Option "TapButton1" "1" #单指敲击产生左键事件
- EndSection
也就是说单指轻触触摸板时,相当于单击鼠标左键。按照如此设置后,放不放到/etc/X11/xorg.conf.d/下,重启后都可以看到图形界面下确实按照文件中的设置改变了,如下图所示:

但是一旦我在此界面下作了修改,比如把“左键”改为了“右键”,并点击“应用”,则重启后再次查看以上界面后就是“右键”,而非70-synaptics.conf文件中设置的“左键”了。
根据以上现象,初步分析是在70-synaptics.conf和最终系统设置中出现了一个“中间层”,可能是一个文件,也可能只是一个参数。当这个“中间层”也可以说是“缓冲”不存在时,使用70-synaptics.conf文件中的设置进行配置,当这个“缓冲”存在时,使用缓冲中的内容(掉电不丢失),此时70-synaptics文件中的设置就不起作用了。
经过一定排查后,发现机制实际上是这样的:
通过GUI设置触摸板相关选项后,点击“应用”,会在~/.config/下生成一个touchpadrc文件,其内容如下:
- [parameters]
- CircScrollDelta=5.73
- HorizScrollDelta=2.4
- MaxTapMove=3.7
- OneFingerTapButton=NoButton
- Tapping=false
- VertScrollDelta=2.4
这个文件就是上面提到的“中间层”、“缓冲区”。当通过图形界面按照上图所示设置后,该文件内容如下:
- [parameters]
- CircScrollDelta=5.73
- HorizScrollDelta=2.4
- MaxTapMove=3.7
- OneFingerTapButton=LeftButton
- Tapping=false
- VertScrollDelta=2.4
可以看到,“OneFingerTapButton一项的值由“NoButton”变为了“LeftButton”。当将再次在图形界面中修改为“中键”时,“OneFingerTapButton的值变为“MiddleButton”;当在图形界面中设置为“右键”时,注意,“OneFingerTapButton”的值变为“RightButton”。
问题虽然解决了,但是仍然有一件事情需要弄清楚:/usr/share/X11/xorg.conf.d/和/etc/X11/xorg.conf.d/下的70-synaptics.conf同时存在时,哪个优先级更高?
进行实验,将从/usr/share/X11/xorg.conf.d/下拷贝到/etc/X11/xorg.conf.d/下的70-synaptics.conf,修改为以下内容:
- Section "InputClass"
- Identifier "touchpad catchall"
- Driver "synaptics"
- MatchIsTouchpad "on"
- Option "TapButton1" "2" #单指敲击产生右键事件
- EndSection
/usr/share/X11/xorg.conf.d/下的70-synaptics.conf还是保持之前的内容:
- Section "InputClass"
- Identifier "touchpad catchall"
- Driver "synaptics"
- MatchIsTouchpad "on"
- Option "TapButton1" "1" #单指敲击产生左键事件
- EndSection
删除~/.config/文件夹下的touchpadrc。
重启或者注销重登录,最终发现界面中显示的是“中键”,即是按照/etc/X11/xorg.conf.d/下的70-synaptics.conf文件中的设定进行配置的。