This article explains changing various options for an input device being handled by the libinput library. To check and configure available options, a command line tool called “xinput” will be used.
Note that this guide works with X display server only. For Wayland, you have to rely on system settings provided by the distribution or use a centralized configuration utility like gsettings.
List Input Devices
Xinput comes pre-installed by default on Ubuntu. If for some reason it is not installed on your system, run the command below to install it:
$ sudo apt install xinputTo list all built-in and external input devices connected to your system, run the command below:
$ xinput --listYou will see some output in terminal like this:
The entry under “Virtual core pointer” (highlighted by red arrows) is a wired USB mouse connected to my system. You will have to use exact name or id shown in the screenshot above to configure mouse or touchpad settings through the xinput command line tool.
Note that in the screenshot above, xinput is showing properties of devices connected to my system. Device names and IDs will be different for your system depending on your hardware configuration and external devices connected via USB, Bluetooth, or wireless receivers.
View Properties of a Connected Device
To see current status and various options active for the device listed above, run a command in the following format:
$ xinput --list-props “id”For the Dell mouse listed above, the command would be:
$ xinput --list-props 8There is a limitation with using this command. IDs shown in the terminal output tend to change when you connect a listed device to a different port. As the IDs keep changing, there is always a chance of accidentally changing settings for a different device. To overcome this issue, it is better to use full device name as identifier instead of its id. So for the Dell mouse listed above, the better command would be:
$ xinput --list-props "PixArt Dell MS116 USB Optical Mouse"The area highlighted below in red rectangle shows current configuration for the device. You can only change options that are shown in the output. Depending on the capabilities of your device, some extra options may be listed while others can be omitted altogether.
Change Properties of a Connected Device
Now that you know how to check the properties of a connected input device, settings for it can be easily changed using some simple commands.
For instance, to enable or disable natural scrolling, you have to run commands in the following format:
$ xinput set-prop "PixArt Dell MS116 USB Optical Mouse" 285 0$ xinput set-prop "PixArt Dell MS116 USB Optical Mouse" 285 1
“285” is the id for natural scrolling, as shown in the screenshot above. “0” disables natural scrolling while “1” enables it. Once again, using IDs is not a reliable way to change these settings. A better approach is to use the full property identifier.
$ xinput set-prop "PixArt Dell MS116 USB Optical Mouse""libinput Natural Scrolling Enabled" 0
$ xinput set-prop "PixArt Dell MS116 USB Optical Mouse"
"libinput Natural Scrolling Enabled" 1
Note that you are not supposed to touch property identifiers having the word “Default” in it. These are reference fallback values and any attempt to change them will result in xinput throwing an error.
To know more about other options and those listed in the terminal output above, visit the following page.
Making the Changes Persistent
The method explained above changes settings for active session only. When you reboot the system, these changes will be gone. To make them persistent, two approaches can be used.
The first method requires you to add these commands to startup applications. You can add as many entries as you want using a nice graphical interface. No root permissions are required to create these entries, plus changing them later is super easy.
To add the command to startup applications, launch “Startup Applications” app from the application launcher. Click on “Add” button to add an entry. Set a description and enter appropriate xinput command as per your needs. Make sure that checkbox is checked once you have saved the entry.
That's it, the xinput command you have entered will run automatically on system startup. I have added a little bit of delay to the command to wait for the session to load properly. For reference, here is the command used below in the screenshot below:
$ sleep 3 && xinput set-prop "PixArt Dell MS116 USB Optical Mouse""libinput Natural Scrolling Enabled" 1
The second method requires you to run some commands as root and edit a text file. The advantage of using this method is that you don't have to create separate entries for each option in a GUI and everything just resides in one text file, making it easier to share it between devices.
Run the commands below to create required directory and the conf file:
$ sudo mkdir -p /etc/X11/xorg.conf.d$ sudo touch /etc/X11/xorg.conf.d/99-libinput.conf
Notice the “99” part in the filename. It indicates the load order of the files that exist in “xorg.conf.d” folder. A file that has the highest number as prefix will be loaded last, overriding any options specified in previous files in case there are duplicates. By specifying “99” or any other number as a prefix, you can ensure that it is loaded after other files.
Open “99-libinput.conf” file with root access in your favorite text editor. Enter the code snippet below after making necessary changes as per your requirements.
Section "InputClass"Identifier "Dell Mouse"
MatchProduct "PixArt Dell MS116 USB Optical Mouse"
Option "NaturalScrolling" "true"
EndSection
Where:
- Identifier “Dell Mouse” can be any name that you assign to the device to identify it (change as needed)
- MatchProduct “PixArt Dell MS116 USB Optical Mouse” is the exact device name you found in the “xinput -list” command used above (change as needed)
- Option “NaturalScrolling” “true” enables natural scrolling system wide (change as needed)
By correctly specifying “MatchProduct”, you will be able to limit the configuration options to a specific device only. Changes made in the conf file will take effect when you reboot next time. You can add any number of options in the “InputClass” section. A list of various options that can be added to the file is available here.
Conclusion
The method explained above is especially useful when you want to use per device configuration rules. Default system settings interface in GNOME and KDE provide only some of the most commonly used options available for various input devices. To configure advanced options for an input device, you have no choice but to either use “xinput” or create a dedicated configuration file.