原文地址:https://blog.csdn.net/m0_67559541/article/details/148357868

方法一、使用 xprofile 文件配置屏幕 / 触摸旋转

输入以下命令查看当前连接的显示器及其名称
root@teamhd: xrandr

Screen 0: minimum 320 x 200, current 800 x 1280, maximum 8192 x 8192

HDMI-1 disconnected primary (normal left inverted right x axis y axis)

DSI-1 connected 800x1280+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
800x1280      59.99*+

可使用 xrandr 命令临时旋转屏幕,确认是否可用(临时生效)
默认方向:xrandr --output DSI-1 --rotate normal

旋转180度:xrandr --output DSI-1 --rotate inverted

向左旋转90度:xrandr --output DSI-1 --rotate left

向右旋转90度:xrandr --output DSI-1 --rotate right

执行 xinput list 命令列出触摸设备,找到触摸屏设备的名称和ID(goodix-ts,ID为7)
root@teamhd: xinput list

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ goodix-ts                                 id=7    [slave  pointer  (2)]
⎜   ↳ SIGMACHIP Usb Mouse                       id=8    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ remotectl-gpio                            id=6    [slave  keyboard (3)]
智能体编程

使用 xinput 设置坐标转换矩阵
默认方向:xinput set-prop 7 "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1

旋转180度:xinput set-prop 7 "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1

向左旋转90度:xinput set-prop 7 "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1

向右旋转90度:xinput set-prop 7 "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1

使用文本编辑器打开或创建 ~/.xprofile 文件(设置持久生效)
sudo vim ~/.xprofile
智能体编程

在 ~/.xprofile 中添加以下内容,设备 ID 在每次重启或重新连接设备时可能会发生变化,所以需要创建动态脚本
# Rotate screen
xrandr --output DSI-1 --rotate right

# Find the device ID for the touch screen using its name
TOUCHSCREEN_ID=$(xinput list | grep -i 'goodix-ts' | awk -F'id=' '{print $2}' | awk '{print $1}')

# Check if the ID was found and set the coordinate transformation matrix
if [ -n "$TOUCHSCREEN_ID" ]; then
    xinput set-prop $TOUCHSCREEN_ID "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
else
    echo "Touchscreen not found"
fi

赋予.xprofile 文件可执行权限,并更新配置使其立即生效
sudo chmod +x ~/.xprofile

source ~/.xprofile
 

方法二、使用 xorg.conf 文件配置屏幕/触摸旋转

执行 xrandr 命令查看当前连接的显示器及其名称
root@teamhd: xrandr

Screen 0: minimum 320 x 200, current 800 x 1280, maximum 8192 x 8192

HDMI-1 disconnected primary (normal left inverted right x axis y axis)

DSI-1 connected 800x1280+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
800x1280      59.99*+

创建并编辑 /etc/X11/xorg.conf.d/20-screen-and-touchscreen.conf 文件
sudo vim /etc/X11/xorg.conf.d/20-screen-and-touchscreen.conf

添加以下内容,屏幕/触摸旋转 90 度(旋转角度参数设置请参考方法一)
# /etc/X11/xorg.conf.d/10-screen-and-touchscreen.conf

Section "Monitor"
    Identifier "DSI-1"
    Option "Rotate" "left"  # 根据需要,值可以是 "normal", "left", "right", "inverted"
EndSection

Section "InputClass"
    Identifier "calibration"
    MatchProduct "goodix-ts"  # 这里是你的触摸屏设备名称
    Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"  # 假设旋转 90 度
EndSection

重启 X11 服务,让配置生效
sudo systemctl restart lightdm  # 对于使用 LightDM 的系统

sudo systemctl restart gdm      # 对于使用 GDM(GNOME)的系统
 

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐