How to Change Mouse and Touchpad Settings Using Xinput in Linux

29/12/2020
Chưa phân loại
Most Linux distributions ship with “libinput” library by default to handle input events on a system. It can process input events on both Wayland and X and can handle a variety of input devices including touchscreen displays and stylus pens.

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 xinput

To list all built-in and external input devices connected to your system, run the command below:

$ xinput –list

You 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-propsid

For the Dell mouse listed above, the command would be:

$ xinput –list-props 8

There 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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

VIM Spell Check

Spell checkers are nothing more than a software that keeps on checking the spelling of whatever word you’re typing against...
29/12/2020

Tổng quan về OMD – Checkmk

Các bạn đang phân vân phầm về phần mềm giám sát và muốn tìm kiểm một phần mềm giám sát hiệu...
30/12/2020

CentOS Wget Install and Usage

When working with Linux, especially on the professional and enterprise environment, there’s always the necessity of downloading...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

mua Proxy riêng ở đâu, và nó đem lại lợi ích gì cho người sử dụng
22/11/2022

Hướng dẫn sử dụng Proxy Helper Fakeip khi thuê proxy
21/11/2022

PROXY NUÔI TÀI KHOẢN FACEBOOK – KINH NGHIỆM FAKE IP – THUÊ PROXY GIÁ RẺ
14/11/2022

Mua Proxy Nuôi Zalo Giá Rẻ Tại Onet.com.vn
14/11/2022

BẢNG GIÁ MUA PROXY VIỆT NAM và PROXY US Onet.com.vn
14/11/2022