I have a laptop and I often use a Logitech G5 mouse with it. I don't like acceleration while using the mouse. Thus I have to disable the acceleration every time I plug the mouse. Is there a way to automatically disable mouse acceleration, whenever I plug my mouse?

  • @Braiam isn't it harder for people to find the question lacking those tags? – Nicolay Doytchev Dec 26 '13 at 3:22
  • 1
    Please, read the last 4 questions of this Meta Question meta.askubuntu.com/q/7819/169736 – Braiam Dec 26 '13 at 3:26
  • I see. Yeah, also search finds it reasonably well without the tags. Thanks! – Nicolay Doytchev Dec 26 '13 at 4:04
up vote 3 down vote accepted

Yes it can be done and it's relatively easy to do. You need to create 3 files - a udev rule, and two scripts.

UDEV Rule

A UDEV rule would detect a mouse plug event and trigger a script whenever the event happens. Create a file under /etc/udev/rules.d:

sudo gedit /etc/udev/rules.d/42-kill-mouse-accel.rules

Paste the following line in it:

ACTION=="add", ATTRS{bInterfaceClass}=="03", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/[YOUR_USER_NAME]/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/usr/local/bin/kill-mouse-accel.sh"

Note the part that says [YOUR_USER_NAME], you have to replace it with your user name.
Save and exit Gedit.

Acceleration Script

The acceleration script would be the code triggered by the UDEV rule, which in turn would fork a worker script in the background. The background script would do the actual work. We do that since we want to wait a bit before changing acceleration but we don't want to block UDEV. Create a file under /usr/local/bin:

sudo gedit /usr/local/bin/kill-mouse-accel.sh 

Paste the following code in it:

#!/bin/bash 

export DISPLAY=${DISPLAY} 
/usr/local/bin/kill-mouse-accel-worker.sh &

Save and exit Gedit.

Background Acceleration Script

This script is where the command disabling mouse acceleration is called. Create a file under /usr/local/bin:

sudo gedit /usr/local/bin/kill-mouse-accel-worker.sh

Paste the following code in it:

#!/bin/bash 

sleep 2 

for i in $(xinput list | grep [Mm]ouse | sed -e 's/^.*id=\([0-9]*.\).*$/\1/') 
do 
    echo "Found device: $i" 

    # The command disabling mouse acceleration
    xinput set-ptr-feedback $i 10 1 1 
done

Save and exit Gedit.

Finalization and Testing

Make both scripts executable:

sudo chmod +x /usr/local/bin/kill-mouse-accel.sh /usr/local/bin/kill-mouse-accel-worker.sh

Restart UDEV:

sudo service udev restart

Finally, re-plug your USB mouse and wait for a few seconds. Mouse acceleration should be disabled.

Credits

Credit goes to the author of the following blog post: http://granjow.net/udev-rules.html

  • I don't see difference. – emrecnl Nov 6 '15 at 18:42

I have a similar issue and I have developed a different solution.

I've written a Python script that listens for udev events and runs some commands whenever a device is plugged or unplugged. In my case, one of the commands disables mouse acceleration. I've choosen this solution because it does not require root permissions, and thus can be applied on any Linux system. I just leave the Python script running in background and don't worry about it anymore.

All the scripts are available at https://bitbucket.org/denilsonsa/small_scripts/src/default/ , and they are also copied/mirrored below, for reference.


auto_configure_upon_usb_device_change.py

#!/usr/bin/env python3

import functools
import os.path
import pyudev
import subprocess
import time

def main():
    BASE_PATH = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
    path = functools.partial(os.path.join, BASE_PATH)
    call = lambda x, *args: subprocess.call([path(x)] + list(args))

    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by(subsystem='usb')
    monitor.start()

    call('xinput_disable_mouse_acceleration.sh')

    for device in iter(monitor.poll, None):
        # Wait a short amount of time to let the device get ready.
        time.sleep(0.250)

        call('xinput_disable_mouse_acceleration.sh')

if __name__ == '__main__':
    main()

xinput_disable_mouse_acceleration.sh

#!/bin/sh

xsp_microsoft() {
    xinput set-prop 'Microsoft  Microsoft Basic Optical Mouse v2.0 ' "$@"
}
xsp_logitech() {
    xinput set-prop 'Logitech USB Laser Mouse' "$@"
}

xsp_microsoft 'Device Accel Profile' -1
xsp_logitech 'Device Accel Profile' -1

xsp_microsoft 'Device Accel Constant Deceleration' 1.5

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.