Solve a mouse movement issue on Linux

Solve a mouse movement issue on Linux

Linux Nov 18, 2022

After almost two years, I decided to install Linux again and after a little research, I found a distro named Pop!_OS. I liked It and after installing the distro I've found out that my mouse has an issue with movement. It wasn't a smooth movement, It was like something is blocking the way of the cursor. So after downloading Xubuntu which has an XFCE DE, I decided to use try Ubuntu to see if the problem is still there even in another DE. The answer was YES.

First Step: Find the event Files

So after a lot of research about the problem, and trying a lot of recommended solutions I finally find a StackExchange post about the curious case of two event files related to the same device causing a problem with Its functionality. After testing the event files one by one with:

evtest /dev/input/eventX

And moving the mouse to see if the event is going to print, I found that my mouse has two event files: event4 and event6.

Second Step: Install Rust

We need Rust Programming Language compiler to compile the tool we wan't for our soloution. So open rustup.rs in your browser, Copy the command from website into terminal and run it.

Install Rust Programming Language

Like the picture above, Enter 1 and then Enter. Wait until installation ends.

The Third step is to download the source code of evsieve which is a cli tool for working with event files. For that, Run the command below:

git clone https://github.com/KarsMulder/evsieve.git

Now run cd evsieve, and Build it with cargo build --release. Now we have to move it from target/release/ folder to /usr/local/bin so run this command:

sudo cp target/release/evsieve /usr/local/bin

Third Step: Test if solution works:

Open the Terminal, And then run the command from StackExchange:

evsieve --input /dev/input/event3 grab --input /dev/input/event6 grab --output

The result was just Wow! My mouse is working fine. Everything is beautiful 😂. But there is a problem, I have to run the command for the whole session and that means there is always a terminal that stays open.

What is the solution for this?

Create a file with the name mouse_fix.service in the /etc/systemd/system/:

sudo nano /etc/systemd/system/mouse_fix.service

And put these lines in it:

[Unit]
Description=Fix mouse movement issue

[Service]
Type=forking
ExecStart=evsieve --input /dev/input/event4 grab --input /dev/input/event6 grab --output
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

** Instead of event4 and event6 put your own event number.

Then save it with ctrl + o, Enter, ctrl + x, Enter. Now execute this command:

sudo systemctl enable mouse_fix
sudo systemctl start mouse_fix

And finally, You can use your mouse like normal.

** If nothing changed, Just reboot. Then you can see the miracle.

You can watch my Youtube video about this issue:

Tags

Benyamin Eskandari

Curious, Experienced Android Developer Also in love with Rust, DevOps, and System Programming Trying to read a lot of books and learn a lot of things, I will write posts about my path on this journey.