Skip to content

Instantly share code, notes, and snippets.

@nick-andren
Last active January 25, 2021 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nick-andren/ddb4fc41d6daf1c8d4a4a285fa448c79 to your computer and use it in GitHub Desktop.
Save nick-andren/ddb4fc41d6daf1c8d4a4a285fa448c79 to your computer and use it in GitHub Desktop.
Disable mouse acceleration and adjust mouse speed in Linux (used on a Mint install)
#!/bin/bash
# Mouse Speed Fix by Nick Andren, January 2021
# How fast we want the pointer to move
mouseSpeed=8.0
# One of the problems that I've had with many Linux window managers is that they
# don't allow adjustments to *only* the mouse speed without mouse acceleration.
# This solution might not work for all types of mice, but in my case, it works
# with my Microsoft IntelliMouse. Even if you don't have one of these, this
# might help someone else who is like me and prefers a constant high speed with
# no acceleration.
# xinput will list the machine's various input devices along with their IDs
# It can also show the properties of each device. In our case, we want to see
# the main pointer's acceleration and coordinate transformation matrix. Other
# mice may have these listed differently, or may not have them available at all.
# Your mileage may vary.
# First, let's grab the mouse ID
mouseId=$(xinput --list --short | sed -n 's/^.*Microsoft Microsoft® Classic IntelliMouse®.*id=\([0-9]\+\).*/\1/p')
if [ -z "$mouseId" ]
then
exit 0;
fi
# Next, we'll look up the coordinate transformation matrix and the acceleration
# speed. The matrix is used to determine the speed of the pointer.
coordinateTransformationMatrix=$(xinput list-props "$mouseId" | grep "Coordinate Transformation Matrix" | sed -n 's/^.*Coordinate Transformation Matrix (\([0-9]\+\)):.*/\1/p')
libinputAccelSpeed=$(xinput list-props "$mouseId" | grep 'libinput Accel Speed (' | sed -n 's/^.*libinput Accel Speed (\([0-9]\+\)).*/\1/p')
# Disable mouse acceleration
xinput set-prop "$mouseId" "$libinputAccelSpeed" -1
# Set the pointer speed
# Note the two instances of mouseSpeed here for the X and Y coordinates
xinput set-prop "$mouseId" "$coordinateTransformationMatrix" "$mouseSpeed", 0, 0, 0, "$mouseSpeed", 0, 0, 0, 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment