Ubuntu扩展触摸屏触控错位修复

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 ]
    then
        echo $2
        exit
    fi
}

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个,退出
then
    outputErrorMsg 1 "There are currently three monitors, please reduce to two monitors!"
fi

if [ $ACTIVE_SCREEN_COUNTS -eq 1 ] # 如果只有一个活跃的显示器,退出
then
    outputErrorMsg 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" ]
then
    outputErrorMsg 1 "There is no touch device!"
fi

TOUCH_DEVICE_ID=$(echo ${TOUCH_DEVICE_ID#*id=})
TOUCH_DEVICE_ID=$(echo ${TOUCH_DEVICE_ID%% *})   # 最终获取id号

if [ -z "$TOUCH_DEVICE_ID" ]
then
    outputErrorMsg 1 "Device id is empty!"
fi

xinput map-to-output $TOUCH_DEVICE_ID ${SCREEN_NAME[1]}
xrandr --listactivemonitors
echo "Setting successful!"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FlyWine

你的鼓励将是我创作的做大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值