Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

xinput

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've made a script that turns this off. The script looks like this

#!/bin/bash # This script removes mouse acceleration, and lowers pointer speed # Suitable for gaming mice, I use the Logitech G700. # More info: http://www.x.org/wiki/Development/Documentation/PointerAcceleration/ xinput set-prop 11 'Device Accel Profile' -1 xinput set-prop 11 'Device Accel Constant Deceleration' 2.5 xinput set-prop 11 'Device Accel Velocity Scaling' 1.0 xinput set-prop 12 'Device Accel Profile' -1 xinput set-prop 12 'Device Accel Constant Deceleration' 2.5 xinput set-prop 12 'Device Accel Velocity Scaling' 1.0 

Another problem with the G700 mouse is that it shows up as two different devices in xinput. This is most likely because the mouse has a wireless adapter, and is usually also connected via a usb cable (for charging). This is my output from xinput --list (see id 11 and 12):

$ xinput --list ⎡ Virtual core pointer                              id=2    [master pointer  (3)] ⎜   ↳ Virtual core XTEST pointer                    id=4    [slave  pointer  (2)] ⎜   ↳ Logitech USB Receiver                         id=8    [slave  pointer  (2)] ⎜   ↳ Logitech USB Receiver                         id=9    [slave  pointer  (2)] ⎜   ↳ Logitech Unifying Device. Wireless PID:4003   id=10   [slave  pointer  (2)] ⎜   ↳ Logitech G700 Laser Mouse                     id=11   [slave  pointer  (2)] ⎜   ↳ Logitech G700 Laser Mouse                     id=12   [slave  pointer  (2)] ⎣ Virtual core keyboard                             id=3    [master keyboard (2)]     ↳ Virtual core XTEST keyboard                   id=5    [slave  keyboard (3)]     ↳ Power Button                                  id=6    [slave  keyboard (3)]     ↳ Power Button                                  id=7    [slave  keyboard (3)] 

This isn't usually a problem, since the id's are usually the same. But sometimes the id's of the mouse change, and that's where my question comes in.

What's the simplest way of writing a script/program that finds the id that belongs to the two listings named Logitech G700 Laser Mouse in the output from xinput --list, and then running the commands in the top script using those two ids?

like image 944
Filip S. Avatar asked Sep 12 '13 05:09

Filip S.


People also ask

How to use xinput in linux?

To add the command to startup applications, launch “Startup Applications” app from the application launcher. Click on “Add” button to add an entry. Set a description and enter appropriate xinput command as per your needs. Make sure that checkbox is checked once you have saved the entry.

What is xinput Ubuntu?

DESCRIPTION. xinput is a utility to list available input devices, query information about a device and change input device settings.


2 Answers

If the device name is always the same, in this case Logitech G700 Laser Mouse, you can search for matching device IDs by running

xinput list --id-only 'Logitech G700 Laser Mouse' 
like image 129
Vinson Chuong Avatar answered Sep 27 '22 22:09

Vinson Chuong


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.

like image 37
Raphael Ahrens Avatar answered Sep 27 '22 23:09

Raphael Ahrens