Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
The mouse scroll wheel is a handy tool for quickly scrolling through documents, web pages, and other content. Nevertheless, the default scroll speed may not always be ideal. However, if the scroll wheel is too slow or fast, we can adjust it to our liking. Indeed, Linux offers a variety of methods to fine-tune this setting to our preferences.
Generally, one of the solutions to adjust mouse scroll speed is to use Solaar. However, this approach is confined to Logitech mice.
In this tutorial, we’ll see how to adjust the mouse scroll speed using the imwheel utility. We’ll discuss two methods:
We used a Ubuntu 22.04 system for this tutorial. However, it should work with other Debian and RedHat-based Linux distributions with little adjustments.
imwheel is a command-line tool for handling the mouse wheel scroll behavior. Before we dive in to see how to use imwheel, let’s install it.
imwheel can be installed on Ubuntu using the usual apt and sudo commands:
$ sudo apt install imwheel
To use imwheel, we create a configuration file .imwheelrc in the home directory:
$ cat ~/.imwheelrc
".*"
None, Up, Button4, 8
None, Down, Button5, 8
Control_L, Up, Control_L|Button4
Control_L, Down, Control_L|Button5
Shift_L, Up, Shift_L|Button4
Shift_L, Down, Shift_L|Button5
As the cat command shows, this file will be used to set the scroll speed of our mouse:
Let’s now turn to the use of imwheel for setting mouse scroll speed.
Let’s start imwheel from the command line:
$ imwheel -b "4 5"
INFO: imwheel started (pid=5363)
The option -b targets the buttons corresponding to the wheel up and down actions in the imwheelrc file.
This command implicitly makes imwheel use the default configuration file .imwheelrc and apply the specified scroll speed. We can now see a new process, imwheel, with the pid=5363.
Of course, if we want to change the scroll speed, we can also put that value in the imwheelrc file.
Additionally, we use the –kill option to restart imwheel and apply any new settings:
$ imwheel -kill
INFO: imwheel(pid=6356) killed.
INFO: imwheel(pid=6364) killed.
INFO: imwheel started (pid=6373)
The above code kills the older processes and restarts a new instance of imwheel.
We can also use imwheel in a graphical manner when combined with another tool. Let’s explore this approach.
To use imwheel with a makeshift graphical user interface, we can create a script file mousewheel.sh:
$ cat > mousewheel.sh
#!/bin/bash
if [ ! -f ~/.imwheelrc ]
then
cat >~/.imwheelrc<<EOF
".*"
None, Up, Button4, 1
None, Down, Button5, 1
Control_L, Up, Control_L|Button4
Control_L, Down, Control_L|Button5
Shift_L, Up, Shift_L|Button4
Shift_L, Down, Shift_L|Button5
EOF
fi
CURRENT_VALUE=$(awk -F 'Button4,' '{print $2}' ~/.imwheelrc)
NEW_VALUE=$(zenity --scale --window-icon=info --ok-label=Apply --title="Wheelies" --text "Mouse wheel speed:" --min-value=1 --max-value=100 --value="$CURRENT_VALUE" --step 1)
if [ "$NEW_VALUE" == "" ]; then exit 0; fi
cat ~/.imwheelrc
imwheel -kill
Let’s analyze this script.
In the code above, we start by checking whether the imwheelrc file exists via -f within the [] test construct. In case it doesn’t exist, we create one using the if block statement. The contents of this file are enclosed within a heredoc as indicated by << and surrounded by EOF.
Further, we use the CURRENT_VALUE variable to store the current value of the mouse scroll speed.
Let’s break down the above code after CURRENT_VALUE:
In essence, we extract the value from the configuration file via awk.
Furthermore, the variable NEW_VALUE gets a new value for the scroll speed from the user.
To facilitate the GUI, we’ve used the zenity tool. Basically, it provides a graphical dialog box for GUI interactions.
So, let’s explore the various options used with zenity:
Further, the if statement causes the script to exit if the user cancels the dialog box. Otherwise, it prints the contents of the imwheelrc file. Finally, the script kills all old imwheel processes.
Let’s provide execute permission to mousewheel.sh via chmod:
$ chmod +x mousewheel.sh
Now, we can run the script:
$ ./mousewheel.sh
Consequently, a dialog box with a slider appears:
We can now set the scroll speed via a convenient slider.
In some cases, while using the GUI approach, we can get an error This option is not available. Please see –help for all possible usages. This error is possibly due to the fact that the imwheelrc file is empty.
In this situation, we can pre-populate imwheelrc with the content we used earlier:
".*"
None, Up, Button4, 8
None, Down, Button5, 8
Control_L, Up, Control_L|Button4
Control_L, Down, Control_L|Button5
Shift_L, Up, Shift_L|Button4
Shift_L, Down, Shift_L|Button5
Next time we run the script, the scroll slider should pop up.
However, the final settings won’t be stored between reboots.
To ensure imwheel settings persist across reboots, we can add the imwheel command to our startup applications.
For example, let’s do it on Ubuntu with the GNOME desktop environment:
As a result, every time we log in, imwheel runs with our specified scroll speed settings. Naturally, we can also choose to spawn our script.
In this article, we discussed how to adjust the mouse scroll speed. Particularly, we focused on using imwheel. First, we used imwheel as a command utility. Then we saw how to use imwheel in a GUI approach.
In conclusion, if we’re comfortable using the graphical user interface, then the second method is a good option.