一、首先需要涉及到的配置文件有:
1.桌面旋转配置文件:/etc/X11/xorg.conf
Section "Monitor"
Identifier "DSI-1"
#配置rotate 正常-normal, 左90°-left, 右90°-right, 翻转180°-inverted
Option "Rotate" "right"
EndSection
2.触控屏校准配置文件:/usr/share/X11/xorg.conf.d/40-libinput.conf
Section "InputClass"
Identifier "libinput touchscreen catchall"
#转置矩阵
Option "TransformationMatrix" "1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0"
#校准矩阵
Option "CalibrationMatrix" "-1.219822 0.0 1.124682 0.0 1.492537 -0.229478 0.0 0.0 1.0"
MatchIsTouchscreen "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
二、校准用到的工具
1.xinput_calibrator 这个工具输出的参数不能直接使用,需要根据校准坐标自己技术校准矩阵值
2.xinput.py 网上扒来的校准矩阵计算脚本,源码如下:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
def usage():
info = "Usage: " + sys.argv[0]
info += " <screen_width> <screen_height>"
info += " <click_0_x> <click_0_y>"
info += " <click_3_x> <click_3_y>"
print(info)
print("\tScreen width/hight by the command 'xrandr|grep screen' got")
print("\tClick x/y by the command 'xinput_calibrator -v' got")
sys.exit(0)
def convert(screen_x, screen_y, c0_x, c0_y, c3_x, c3_y):
a = (screen_x * 6 / 8) / (c3_x - c0_x)
c = ((screen_x / 8) - (a * c0_x)) / screen_x
e = (screen_y * 6 / 8) / (c3_y - c0_y)
f = ((screen_y / 8) - (e * c0_y)) / screen_y
print("%.6f 0.0 %.6f 0.0 %.6f %.6f 0.0 0.0 1.0" % (a,c,e,f))
if __name__ == "__main__":
if len(sys.argv) != 7:
usage()
convert(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]),int(sys.argv[5]),int(sys.argv[6]))
3.xrander 调试时用于临时旋转屏幕
4.xinput 获取和设置输入设备id和属性
三、最关键的步骤来了
1、常用参数说明
#查看当前的屏幕
xrandr -q
DSI-1:mipi屏
HDMI-1:HDMI屏
小编在用DSI-1,后面以DSI-1作为屏幕修改配置
#旋转屏幕-正常
xrandr --output DSI-1 --rotate normal
#旋转屏幕-向左90度
xrandr --output DSI-1 --rotate left
#旋转屏幕-向右90度
xrandr --output DSI-1 --rotate right
#旋转屏幕-旋转180度
xrandr --output DSI-1 --rotate inverted
# 根据名字列出输入设备变量
xinput list-props 'pointer:Goodix Capacitive TouchScreen' | grep "Coordinate Transformation Matrix"
# 根据id列出输入设备变量
xinput list-props 10 | grep "Coordinate Transformation Matrix"
#修改触摸方向(可根据名字修改) 默认方向
xinput set-prop 10 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
#修改触摸方向(可根据名字修改) 向左90度
xinput set-prop 10 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1
#修改触摸方向(可根据名字修改) 向右90度
xinput set-prop 10 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1
#修改触摸方向(可根据名字修改) 旋转180度
xinput set-prop 10 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1ordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1
2.校准坐标
#第一步 获取需要校准的输入设备id
xinput_calibrator --list
#第二步 旋转屏幕(要永久生效需要改上面提到的配置文件)
xrandr --output DSI-1 --rotate left
#第三歩 重置转置矩阵和校准矩阵,这里非常关键,转置矩阵需要根据屏幕旋转,校准矩阵设置默认值即可
xinput set-prop $id --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
xinput set-prop $id --type=float "libinput Calibration Matrix" 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
#第四步 开始校准
/usr/bin/xinput_calibrator -v --device $DEVICE
#第五步 根据上面显示的坐标技术校准矩阵(下面是计算脚本)
CALIBRATOR=$(/usr/bin/xinput_calibrator -v --device $DEVICE)
#calibrationMatrix click 0 3
CALIBRATOR_CLICK0=$(echo -e "$CALIBRATOR" | grep "click 0" | tail -1 | cut -d '(' -f2 | cut -d ')' -f1)
CALIBRATOR_CLICK3=$(echo -e "$CALIBRATOR" | grep "click 3" | tail -1 | cut -d '(' -f2 | cut -d ')' -f1)
#click 0 最后一行X Y
CLICK_0_X=$(echo -e "$CALIBRATOR_CLICK0" | awk -F ',' '{print $1}' | awk -F '=' '{print $2}')
CLICK_0_Y=$(echo -e "$CALIBRATOR_CLICK0" | awk -F ',' '{print $2}' | awk -F '=' '{print $2}')
#click 3 最后一行X Y
CLICK_3_X=$(echo -e "$CALIBRATOR_CLICK3" | awk -F ',' '{print $1}' | awk -F '=' '{print $2}')
CLICK_3_Y=$(echo -e "$CALIBRATOR_CLICK3" | awk -F ',' '{print $2}' | awk -F '=' '{print $2}')
#如果最后一点没有数据 则退出
if [ "$CLICK_3_Y" == "" ];then
exit
fi
xinput list-props $DEVICE > /dev/console
#计算校准参数
#xinput.py X Y CLICK_0_X CLICK_0_Y CLICK_3_X CLICK_3_Y
echo "CLICK_0[$CLICK_0_X,$CLICK_0_Y], CLICK_3[$CLICK_3_X,$CLICK_3_Y]" > /dev/console
XINPUT_PY=$(/usr/bin/xinput.py $X $Y $CLICK_0_X $CLICK_0_Y $CLICK_3_X $CLICK_3_Y)