2

On all Ubuntu systems I set mouse pointer speed to the slowest, but it still moves too fast. (Now I use Ubuntu 16.04.) I did some research and found out that this command solves my problem:

xinput --set-prop "Logitech USB Laser Mouse" "Device Accel Constant Deceleration" 1.75

But when I unplug the mouse and plug it back, its speed returns to the system's settings. So I have to run this command all the time. What should I do?

2 Answers 2

2

We can fix this issue by writing a udev rule.

Identify your mouse

First we should identify our mouse device, there are different ways to do this, I ran lsusb and it outputs:

...
Bus 002 Device 011: ID 104f:0003  WB Electronics
...

then I used vendor id 104f, find to look for my mouse device node:

$ find /dev/input -iname *104f* -ls
540  0  lrwxrwxrwx   1  root ... /dev/input/by-id/usb-104f-mouse -> ../mouse2

so my mouse device is /dev/input/mouse2.

Gather identical data about the device

Use udevadm info /dev/input/mouse2 --attribute-walk to get a list of details about the device so we can use them to write a udev rule.

Select a single section which contains: ATTRS{idProduct} & ATTRS{idVendor}.

Write udev rule

Then create a file here:

sudo nano /etc/udev/rules.d/95-mymouse.rules

with a content chosen similar to:

SUBSYSTEMS=="usb", ATTRS{idProduct}=="xxxx", ATTRS{idVendor}=="xxxx", RUN+="/bin/touch /tmp/my.udev"

Don't forget to change xxxx with your own device and product code.

Now run:

sudo udevadm control --reload

What we done till now?

Each times you connect your mouse to the system udev will run a command, and the command will touch a file at /tmp/my.udev.

Why we just don't run the xinput? After a udev rule runs, "X" resets some details so we can't simply run a xinput command as a udev command.

so install inotify-tools:

sudo apt install inotify-tools

then write a script and put it anywhere you want:

#!/bin/bash
touch /tmp/my.udev
inotifywait -m -e attrib --format '%w%f' /tmp/my.udev 2>/dev/null | while read event
do
sleep 2
xinput --set-prop "Logitech USB Laser Mouse" "Device Accel Constant Deceleration" 1.75
done

How to get it work?

Run the last script after login, you can put it in startup scripts, or even .profile file, each time you connect your mouse, udev will touch the /tmp/my.udev and inotifywait triggers the xinput.

inotifywait idea comes from here

2

1/ Short version : (checked on Ubuntu 16.04)

Update .xinputrc file in your $HOME directory and put your xinput commands inside (one by line). It will be read each time you'll open your session. If it does not exists, create it : (should have been generated by im-config)

Mine :

# im-config(8) generated on Wed, 15 Feb 2017 19:29:43 +0100
run_im ibus
# im-config signature: 90bece1e5f840b27085989abd900276a  -

#BYME# Put your xinput commands here
#BYME#With DRI2 : Device Accel Constant Deceleration (267)
xinput --set-prop 11 267 2
#BYME#With DRI3 : Device Accel Constant Deceleration (264)
xinput --set-prop 11 264 2

This .xinputrc works for both cases (if DRI3 is enabled or not)

By the way, I'm using multiple screens (mixing 4K and old fashion 16:9 screens) and I feel comfortable having only set Device Accel Constant Deceleration to 2. Feel free to change this (or other) value.

2/ Wrong way to do it :

(DO NOT) add it to your .bashrc or another profile specific file (which can be read many more times and can lead to misinterpretation of what mouse behaviour is actually really applied)

3/ Long version : (working on distributions supporting xinput commands)

To determine which options you should use :

$ xinput --list --short

On my Ubuntu host (I'm using a KVM to switch between my computers), it returns :

Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ No brand Combo Free KVM                   id=11   [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)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ No brand Combo Free KVM                   id=10   [slave  keyboard (3)]

So instead of messing with strings (and making errors while typing it), I prefer to use (short) numeric identifiers (knowing now how to find them and their meanings).

In my case, my mouse is under Virtual core pointer, identified as No brand Combo Free KVM with numeric identifier 11. As explained previously, I'm now going to use this numeric identifier instead of the corresponding string but you can do as you want (both work).

To know which properties / capabilities are available with my mouse, I have to type : (adapt this command with the result of the previous one, your own identifier should be different)

$ xinput --list-props 11

Device 'No brand Combo Free KVM':
    Device Enabled (136):   1
    Coordinate Transformation Matrix (138): 1.000000, 0.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    Device Accel Profile (266): 0
    Device Accel Constant Deceleration (267):   1.000000
    Device Accel Adaptive Deceleration (268):   1.000000
    Device Accel Velocity Scaling (269):    10.000000
    Device Product ID (257):    4309, 20480
    Device Node (258):  "/dev/input/event16"
    Evdev Axis Inversion (270): 0, 0
    Evdev Axes Swap (272):  0
    Axis Labels (273):  "Rel X" (146), "Rel Y" (147), "Rel Horiz Wheel" (264), "
Rel Vert Wheel" (265)
    Button Labels (274):    "Button Left" (139), "Button Middle" (140), "Button Righ
t" (141), "Button Wheel Up" (142), "Button Wheel Down" (143), "Button Horiz Wheel Left" 
(144), "Button Horiz Wheel Right" (145), "Button Side" (262), "Button Extra" (263), "But
ton Unknown" (260), "Button Unknown" (260), "Button Unknown" (260), "Button Unknown" (26
0)
    Evdev Scrolling Distance (275): 1, 1, 1
    Evdev Middle Button Emulation (276):    0
    Evdev Middle Button Timeout (277):  50
    Evdev Third Button Emulation (278): 0
    Evdev Third Button Emulation Timeout (279): 1000
    Evdev Third Button Emulation Button (280):  3
    Evdev Third Button Emulation Threshold (281):   20
    Evdev Wheel Emulation (282):    0
    Evdev Wheel Emulation Axes (283):   0, 0, 4, 5
    Evdev Wheel Emulation Inertia (284):    10
    Evdev Wheel Emulation Timeout (285):    200
    Evdev Wheel Emulation Button (286): 4
    Evdev Drag Lock Buttons (287):  0
    

This is how we can identify which properties should be changed !

Accel Constant Deceleration (numeric identifier : 267) is doing the job quite well for me. Feel free to "play" with other properties to find the right behaviour for your own mouse.

So, that's why I've added the next line to my .xinputrc, changing value from 1.000000 to 2 (specifying a float is not required) because augmenting deceleration leads to slowing down mouse speed:

xinput --set-prop 11 267 2

4/ Warning : this identifiers can change if you have activated DRI3

DRI2 only, by default, under Ubuntu 16.04 (while it can lead to problems, like with last versions of Chrome, requiring DRI3 to support smooth multiwindow)

If you have enabled DRI3, identifiers should now be :

Device 'No brand Combo Free KVM':
    Device Enabled (133):   1
    Coordinate Transformation Matrix (135): 1.000000, 0.000000, 0.000000, 0.000000, 
1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    Device Accel Profile (263): 0
    Device Accel Constant Deceleration (264):   1.000000
    Device Accel Adaptive Deceleration (265):   1.000000
    Device Accel Velocity Scaling (266):    10.000000
    Device Product ID (254):    4309, 20480
    Device Node (255):  "/dev/input/event9"
    Evdev Axis Inversion (267): 0, 0
    Evdev Axes Swap (269):  0
    Axis Labels (270):  "Rel X" (143), "Rel Y" (144), "Rel Horiz Wheel" (261), "
Rel Vert Wheel" (262)
    Button Labels (271):    "Button Left" (136), "Button Middle" (137), "Button Righ
t" (138), "Button Wheel Up" (139), "Button Wheel Down" (140), "Button Horiz Wheel Left" 
(141), "Button Horiz Wheel Right" (142), "Button Side" (259), "Button Extra" (260), "But
ton Unknown" (257), "Button Unknown" (257), "Button Unknown" (257), "Button Unknown" (25
7)
    Evdev Scrolling Distance (272): 1, 1, 1
    Evdev Middle Button Emulation (273):    0
    Evdev Middle Button Timeout (274):  50
    Evdev Third Button Emulation (275): 0
    Evdev Third Button Emulation Timeout (276): 1000
    Evdev Third Button Emulation Button (277):  3
    Evdev Third Button Emulation Threshold (278):   20
    Evdev Wheel Emulation (279):    0
    Evdev Wheel Emulation Axes (280):   0, 0, 4, 5
    Evdev Wheel Emulation Inertia (281):    10
    Evdev Wheel Emulation Timeout (282):    200
    Evdev Wheel Emulation Button (283): 4
    Evdev Drag Lock Buttons (284):  0

Accel Constant Deceleration is now idenfified by 264. That's why I've also added (having same behaviour no matter if DRI3 is enabled or not) in my .xinputrc :

xinput --set-prop 11 264 2

Hope it will help you.

4
  • What if you unplug the mouse and plug it back? it's only works when mouse is plugged in at first of the session.
    – Ravexina
    Jul 6, 2017 at 17:12
  • Since you've modified your question (allowing hotplug during session) a udev approach, like the one provided by Ravexina, should be the way to go. Jul 6, 2017 at 17:33
  • The only thing that has been modified in the question is the style of code.
    – Ravexina
    Jul 6, 2017 at 18:01
  • 1
    Yep, that's right, my bad, misread, your answer is way more accurate ! Jul 6, 2017 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .