Ubuntu扩展触摸屏触控错位修复
当我们ubuntu外接一个触摸显示器的时候,会发现触摸扩展屏幕,发现操控的是主屏幕,我写了一个脚本去修复。
#! /bin/bash
#------------------------------------------------------------------------------
# Filename: repairTouchscreen.sh
# Usage: ./repairTouchscreen.sh
# Version: 1.0
# Date: 2018-03-29
# Author: vincent
# Email: N/A
# Description: 此脚本用于修复Ubuntu下,扩展触摸显示器,触摸扩展屏操作主屏的错误
# Notes: N/A
#-------------------------------------------------------------------------------outputErrorMsg()
{if [ $1 -ne 0 ]thenecho $2exitfi
}declare SCREEN_COUNTS # 当前显示器的总数
declare ACTIVE_SCREEN_COUNTS # 当前活跃的显示器数量
declare SCREEN_NAME # 显示器的输出名称
declare TOUCH_DEVICE_ID # 触摸设备ID号SCREEN_COUNTS=$(xrandr --listmonitors | wc -l)
outputErrorMsg $? "Get screen counts failed!"
SCREEN_COUNTS=`expr $SCREEN_COUNTS - 1`ACTIVE_SCREEN_COUNTS=$(xrandr --listactivemonitors | wc -l)
outputErrorMsg $? "Get active screen counts failed!"
ACTIVE_SCREEN_COUNTS=`expr $ACTIVE_SCREEN_COUNTS - 1`if [ $ACTIVE_SCREEN_COUNTS -ge 3 ] # 如果当前活跃的显示器数量多于2个,退出
thenoutputErrorMsg 1 "There are currently three monitors, please reduce to two monitors!"
fiif [ $ACTIVE_SCREEN_COUNTS -eq 1 ] # 如果只有一个活跃的显示器,退出
thenoutputErrorMsg 1 "There are only one monitor!"
fi
# 如果是两个屏幕,那么第一个是主屏幕,第二个是辅助屏幕
SCREEN_NAME=($(xrandr --listactivemonitors | awk '{if(NR > 1) {print $4}}'))
outputErrorMsg $? "Get screen name failed!"TOUCH_DEVICE_ID=$(xinput | grep -iw touch) # 获取可触摸设备if [ -z "$TOUCH_DEVICE_ID" ]
thenoutputErrorMsg 1 "There is no touch device!"
fiTOUCH_DEVICE_ID=$(echo ${TOUCH_DEVICE_ID#*id=})
TOUCH_DEVICE_ID=$(echo ${TOUCH_DEVICE_ID%% *}) # 最终获取id号if [ -z "$TOUCH_DEVICE_ID" ]
thenoutputErrorMsg 1 "Device id is empty!"
fixinput map-to-output $TOUCH_DEVICE_ID ${SCREEN_NAME[1]}
xrandr --listactivemonitors
echo "Setting successful!"