1. Overview
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:
- using the command-line utility
- using a graphical user interface (GUI) in combination
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.
2. Using the imwheel Utility
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:
- the Up and Down identifiers map to the mouse wheel up and down actions respectively
- the Control_L and Shift_L create a combination of CTRL and SHIFT keys with the wheel up and down actions respectively
- Button4 and Button5 are mapped to the Up and Down actions respectively
- the values after Button4 and Button5 specify the scrolling speed
Let’s now turn to the use of imwheel for setting mouse scroll speed.
3. imwheel Command-Line Approach
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.
4. imwheel GUI 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.
4.1. Breakdown
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:
- awk: extracts data from text files (in this case, imwheelrc)
- -F ‘Button4,’: tells awk to use Button4 as the field separator
- ‘{print $2}’: specifies the second field from each line of the input file imwheelrc
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.
4.2. zenity
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:
- –scale: creates a scale widget for selecting values within a specified range
- –window-icon=info: specifies the icon to be used for the dialog window
- –ok-label=Apply: sets the label for the OK button in the dialog to Apply
- –title=”Wheelies”: sets the title of the dialog window to Wheelies
- –text “Mouse wheel speed:”: sets the text displayed above the scale widget in the dialog
- –min-value, –max-value: sets the range of values that the user can select on the scale
- –value=”$CURRENT_VALUE”: retrieves the initial value of the scale from CURRENT_VALUE
- –step 1: sets the step size of 1 on the scale
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.
4.3. Troubleshooting
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.
5. Making Changes Permanent
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:
- Search for Startup Applications in the Applications Menu
- Click Add and enter a name for the startup item
- In the Command field, enter the imwheel command imwheel -b “4 5”
- Save the startup program
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.
6. Conclusion
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.