How to make a program that finds id's of xinput devices and sets xinput some settings

前端 未结 6 1866
天命终不由人
天命终不由人 2020-12-24 07:30

I have a G700 mouse connected to my computer. The problem with this mouse in Linux (Ubuntu) is that the sensitivity is very high. I also don\'t like mouse acceleration, so I

6条回答
  •  情书的邮戳
    2020-12-24 07:59

    You can do something like the following.

    if [ "$SEARCH" = "" ]; then 
        exit 1
    fi
    
    ids=$(xinput --list | awk -v search="$SEARCH" \
        '$0 ~ search {match($0, /id=[0-9]+/);\
                      if (RSTART) \
                        print substr($0, RSTART+3, RLENGTH-3)\
                     }'\
         )
    
    for i in $ids
    do
        xinput set-prop $i 'Device Accel Profile' -1
        xinput set-prop $i 'Device Accel Constant Deceleration' 2.5
        xinput set-prop $i 'Device Accel Velocity Scaling' 1.0
    done
    

    So with this you first find all the IDs which match the search pattern $SEARCH and store them in $ids. Then you loop over the IDs and execute the three xinput commands.

    You should make sure that $SEARCH does not match to much, since this could result in undesired behavior.

提交回复
热议问题