当前位置: 首页 > backend >正文

Linux系统配置屏幕旋转和触摸旋转

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


  1. 输入以下命令查看当前连接的显示器及其名称
root@teamhd: xrandrScreen 0: minimum 320 x 200, current 800 x 1280, maximum 8192 x 8192HDMI-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*+
  1. 可使用 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
  1. 执行 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)]
  1. 使用 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
  1. 使用文本编辑器打开或创建 ~/.xprofile 文件(设置持久生效)
sudo vim ~/.xprofile
  1. 在 ~/.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" ]; thenxinput set-prop $TOUCHSCREEN_ID "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
elseecho "Touchscreen not found"
fi
  1. 赋予.xprofile 文件可执行权限,并更新配置使其立即生效
sudo chmod +x ~/.xprofilesource ~/.xprofile

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


  1. 执行 xrandr 命令查看当前连接的显示器及其名称
root@teamhd: xrandrScreen 0: minimum 320 x 200, current 800 x 1280, maximum 8192 x 8192HDMI-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*+
  1. 创建并编辑 /etc/X11/xorg.conf.d/20-screen-and-touchscreen.conf 文件
sudo vim /etc/X11/xorg.conf.d/20-screen-and-touchscreen.conf
  1. 添加以下内容,屏幕/触摸旋转 90 度(旋转角度参数设置请参考方法一)
# /etc/X11/xorg.conf.d/10-screen-and-touchscreen.confSection "Monitor"Identifier "DSI-1"Option "Rotate" "left"  # 根据需要,值可以是 "normal", "left", "right", "inverted"
EndSectionSection "InputClass"Identifier "calibration"MatchProduct "goodix-ts"  # 这里是你的触摸屏设备名称Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"  # 假设旋转 90 度
EndSection
  1. 重启 X11 服务,让配置生效
sudo systemctl restart lightdm  # 对于使用 LightDM 的系统sudo systemctl restart gdm      # 对于使用 GDM(GNOME)的系统
http://www.xdnf.cn/news/10524.html

相关文章:

  • 从冷上电到main()函数,Bootloader都做了什么?
  • 数据类型检测有哪些方式?
  • robot_lab学习笔记【MDP综述】
  • QuickJS 如何计算黄金分割率 ?
  • barker-OFDM模糊函数原理及仿真
  • Linux防火墙:全面解析IPTables的表、链、规则!
  • Cypress + TypeScript + Vue3
  • 数据库管理与高可用-MySQL全量,增量备份与恢复
  • 劫持进程注入
  • C语言进阶--程序的编译(预处理动作)+链接
  • 数据结构:递归(Recursion)
  • 基于TMC5160堵转检测技术的夹紧力控制系统设计与实现
  • 输入ifconfig,发现ens33不见了,无法连接至虚拟机
  • Golang——3、流程控制语句
  • C++实现伽罗华域生成及四则运算(三)
  • Python----目标检测(《SSD: Single Shot MultiBox Detector》论文和SSD的原理与网络结构)
  • CppCon 2014 学习:C++ in Huge AAA Games
  • STM32F407寄存器操作(多通道单ADC+DMA)
  • 前端面试准备-5
  • Mask_RCNN 环境配置及训练
  • QT中子线程触发主线程弹窗并阻塞等待用户响应-传统信号槽实现
  • DRW - 加密市场预测
  • 考研系列—操作系统:第四章、文件管理(part.2)
  • 利用DeepSeek编写能在DuckDB中读PostgreSQL表的表函数
  • 多任务——进程
  • 基于机器学习的心脏病预测模型构建与可解释性分析
  • WIN11+VSCODE搭建的c/c++环境调试报错解决
  • vue+mitt的简便使用
  • API异常信息如何实时发送到钉钉
  • 重读《人件》Peopleware -(14)Ⅱ 办公环境 Ⅶ 把门带上