本文已参与 [新人创作礼] 活动,一起开启掘金创作之路。
接前篇文章《Linux下修改触摸板默认行为的方法、所遇问题及解决》,地址:
修改触摸板行为的方法找到了,但是如何能够在编译及生成镜像的时候就已经将70-synaptics.conf文件修改过来了,而不需要用户通过脚本或者GUI手动进行修改?
为此,需要找到是哪个包中产生的70-synaptics.conf文件。在笔者的ubuntu22.04环境下,看一下/usr/share/X11/xorg.conf.d/目录下的内容,如下所示:
$ ls /usr/share/X11/xorg.conf.d/
10-amdgpu.conf 10-quirks.conf 10-radeon.conf 40-libinput.conf 70-wacom.conf
虽然没有看到70-synaptics.conf文件,但是有个70-wacom.conf文件。看名字也能知道,和synaptics是类似的。通过dpkg -S命令看一下它属于哪个包:
$ dpkg -S /usr/share/X11/xorg.conf.d/
xserver-xorg-core, xserver-xorg-input-wacom, xserver-xorg-input-libinput, xserver-xorg-video-amdgpu, xserver-xorg-video-radeon: /usr/share/X11/xorg.conf.d
$ dpkg -S /usr/share/X11/xorg.conf.d/70-wacom.conf
xserver-xorg-input-wacom: /usr/share/X11/xorg.conf.d/70-wacom.conf
根据以上信息可以看到,70-wacom.conf属于xsever-xorg-input-wacom包。那么这个包又是通过哪个源码包安装的呢?我们需要在BLFS中寻找答案,见以下链接:
www.linuxfromscratch.org/blfs/view/s…
其页面下有这样一段内容:
编辑
编辑
有人也许会问,你怎么知道是这个Xorg Wacom Driver生成的xsever-xorg-input-wacom包?你可以观察它的名字。前半部分是xserver-xorg,说明与xserver-xorg相关并且在其下;后半部分为input-wacom,这就能定位到页面中的具体位置了。
至此,我们找到了70-wacom.conf文件对应的源码包。这就离70-synaptics.conf不远了。实际上wacom对应的是wacom公司的触摸板,那么显而易见地,synaptics对应的就是synaptics公司的触摸板了。
仍然还是上面的链接:www.linuxfromscratch.org/blfs/view/s…
在其中找到synaptics相关的内容,其实就在wacom的上边(笔者再贴图中留了个线索,仔细观察上边wacom的图会看到蛛丝马迹)。
编辑
编辑
可以看到,产生70-synaptics.conf文件的源码包是xf86-input-synaptics-xx.xx.xx.tar.gz(其中:xx代表版本号)。
下载对应的源码包,解压后内容如下:
$ ls xf86-input-synaptics-1.9.2
aclocal.m4 compile config.guess config.sub configure.ac depcomp INSTALL ltmain.sh Makefile.in missing src xorg-synaptics.pc.in
ChangeLog conf config.h.in configure COPYING include install-sh Makefile.am man README.md tools
在其中查找“70-synaptics”相关的内容:
$ grep -rn "70-synaptics" ./xf86-input-synaptics-1.9.2
./xf86-input-synaptics-1.9.2/ChangeLog:234: conf: rename to 70-synaptics.conf
./xf86-input-synaptics-1.9.2/conf/Makefile.am:23:dist_config_DATA = 70-synaptics.conf
./xf86-input-synaptics-1.9.2/conf/Makefile.in:141:am__dist_config_DATA_DIST = 70-synaptics.conf
./xf86-input-synaptics-1.9.2/conf/Makefile.in:328:@HAS_XORG_CONF_DIR_TRUE@dist_config_DATA = 70-synaptics.conf
./xf86-input-synaptics-1.9.2/man/synaptics.man:926:.I ${sourcecode}/conf/70-synaptics.conf
可以看到,70-synaptics文件位于config文件夹下。查看其内容:
$ cat conf/70-synaptics.conf
# Example xorg.conf.d snippet that assigns the touchpad driver
# to all touchpads. See xorg.conf.d(5) for more information on
# InputClass.
# DO NOT EDIT THIS FILE, your distribution will likely overwrite
# it when updating. Copy (and rename) this file into
# /etc/X11/xorg.conf.d first.
# Additional options may be added in the form of
# Option "OptionName" "value"
#
Section "InputClass"
Identifier "touchpad catchall"
Driver "synaptics"
MatchIsTouchpad "on"
# This option is recommend on all Linux systems using evdev, but cannot be
# enabled by default. See the following link for details:
# http://who-t.blogspot.com/2010/11/how-to-ignore-configuration-errors.html
# MatchDevicePath "/dev/input/event*"
EndSection
Section "InputClass"
Identifier "touchpad ignore duplicates"
MatchIsTouchpad "on"
MatchOS "Linux"
MatchDevicePath "/dev/input/mouse*"
Option "Ignore" "on"
EndSection
# This option enables the bottom right corner to be a right button on clickpads
# and the right and middle top areas to be right / middle buttons on clickpads
# with a top button area.
# This option is only interpreted by clickpads.
Section "InputClass"
Identifier "Default clickpad buttons"
MatchDriver "synaptics"
Option "SoftButtonAreas" "50% 0 82% 0 0 0 0 0"
Option "SecondarySoftButtonAreas" "58% 0 0 15% 42% 58% 0 15%"
EndSection
# This option disables software buttons on Apple touchpads.
# This option is only interpreted by clickpads.
Section "InputClass"
Identifier "Disable clickpad buttons on Apple touchpads"
MatchProduct "Apple|bcm5974"
MatchDriver "synaptics"
Option "SoftButtonAreas" "0 0 0 0 0 0 0 0"
EndSection
这就是最终系统中的/usr/share/X11/xorg.conf.d/70-synaptics.conf文件。
经过一番努力,文件找到了,如何自动向文件中添加需要的内容?利用sed命令。在这里假设需要事触摸板的默认行为变为轻触触摸板表示左键单击,则需要添加以下一行命令:
sed -i '/This option is recommend on all Linux systems using evdev/i \ \ \ \ \ \ \ \ Option "TapButton1" "1"' ./conf/70-synaptics.conf
完整的示例脚本如下:
tar -xf xf86-input-synaptics-1.9.1.tar.bz2
cd xf86-input-synaptics-1.9.1
sed -i '/This option is recommend on all Linux systems using evdev/i \ \ \ \ \ \ \ \ Option "TapButton1" "1"' ./conf/70-synaptics.conf
./configure $XORG_CONFIG
make -j32
make install
这样修改后,经过编译生成镜像并烧录,系统中的/usr/share/X11/70-synaptics.conf文件内容就是修改后的了,触摸板的默认行为就改变过来了。