Configuring X Window input and output devices
Tailor-Made
An X Window System provides several components to allow users to interact with a graphical interface. An X server lets applications, also known as X clients, use a graphical display within windows. The window manager determines the look and feel of such an interface, as well as takes care of how the windows are handled (e.g., enlarging, reducing, or closing them). A desktop manager, which is ultimately responsible for bringing order to this kind of graphical interface, displays icons, menus, panels, and other elements on the desktop.
Even though various graphical tools exist to optimally adapt your existing hardware to the X Window System, you can also do this from a terminal using command-line tools. You simply need to use the right tool to make the setting you need. In this article, I will show how to adjust some typical display settings from the terminal using xandr
and xinput
.
Setting up the Display
One problem that occurs time and time again relates to the correct display resolution. If you use several monitors or also use a projector, it is often difficult to determine the correct order of the devices so that you can use a mouse to easily switch between the windows of the different devices. You may also need to rotate the image shown on a display – for instance, if you have installed a projector upside down on the ceiling or want to use a monitor in portrait mode. To solve all of these problems, you can use the xrandr
tool.
With xrandr
, you can configure the X Window System's Resize and Rotate (RandR) extension to adjust the main window, which the X clients use for display purposes, to suit your needs. Using xrandr --listmonitors
gives you an overview of all the monitors connected to the system and their current configurations:
xrandr --listmonitors Monitors: 3 0: +*eDP-1 1920/309x1080/174+3000+0 eDP-1 1: +DP-2-2 1080/510x1920/287+0+0 DP-2-2 2: +DP-2-3 1920/598x1080/336+1080+0 DP-2-3
You can use xrandr -q
to see which modes the individual devices support. You can then set the desired mode for a device as follows:
xrandr --output DP-2-2 --left-of eDP-1 --mode 1920x1080
This command ensures that the monitor DP-2-2, which is connected to the computer's DisplayPort, uses a resolution of 1920x1080 pixels and says that the device is located to the left of the laptop's internal display (eDP-1). You can easily move the mouse to the left to switch from the internal display to the external monitor. If you operate the monitor in portrait mode, simply extend the command to include the --rotate left
or --rotate right
option as follows:
xrandr --output DP-2-2 --rotate left --left-of eDP-1 --mode 1920x1080
The following command is useful if you use a projector connected to an HDMI interface and you want to display an inverted image:
xrandr --output HDMI-1 --rotate inverted --mode 1920x1080
Setting up the Mouse and Touchpad
Another popular X Window System setting is the configuration for natural scrolling. Often on Linux, the default setting for the connected mouse and the internal touchpad behaves like a scroll bar, which differs from the behavior on a device with a touchscreen. In other words, scrolling up causes the screen to scroll up, and scrolling down causes it to scroll down. However, on a smartphone or tablet touchscreen, it is the other way around, which means that many users will want to adjust this setting on their laptops or desktops.
In the X Window System, the libevent
library is responsible for processing a user's input events and reacting to them accordingly. The configuration for the individual input devices relies on the xinput
tool. An overview of the available devices can be displayed using the xinput list
command (Figure 1).
The natural scrolling setting relates to the mouse and touchpad. All the available configuration settings for these devices can be displayed with the help of
xinput list-props <ID>
where you replace the ID with the device name (Figure 2). This is also recommended, since the ID is not static and may well change. The following two commands give you the same results for both the mouse and the touchpad:
xinput list-props 14 xinput list-props 'MOSART Semi. 2.4G Wireless Mouse' xinput list-props 17 xinput list-props 'Elan Touchpad'
To change the setting, you can go back to the ID as well as to the name of the respective setting:
xinput set-prop 14 326 1 xinput set-prop 'MOSART Semi. 2.4G Wireless Mouse''libinput Natural Scrolling Enabled' 1 xinput set-prop 17 326 1 xinput set-prop 'Elan Touchpad' 'libinput Natural Scrolling Enabled' 1
The xinput
command displays all input devices.
Persistent Settings
Keep in mind that the settings you make with xrandr
and xinput
are not persistent. To fix this problem, you have a variety of options. In the simplest case, you can create a startup file in which you enter the respective commands and then ensure that this file is called automatically by your desktop or window manager.
If you are looking for an approach that is independent of your desktop or window manager, you can also store the settings in the configuration file for the X server. Listing 1 shows an example for the libevent
system. Another option is to create a script with the respective commands for each new X session. The advantage here is that you can also use the xrandr
and xinput
tools (and others) in this script without having to worry about the special syntax of the configuration file for the X Window System (see Listing 2).
Listing 1
/etc/X11/xorg.conf.d/99-libinput.conf
Section "InputClass" Identifier "MOSART Wireless Mouse" MatchProduct "MOSART Semi. 2.4G Wireless Mouse" Option "Natural Scrolling " "true" EndSection Section "InputClass" Identifier "Elan Touchpad" MatchProduct "Elan Touchpad" Option "Natural Scrolling" "true" EndSection
Listing 2
/etc/X11/Xsession.d/99-libinput-xrandr.conf
xrandr --output eDP-1 --right-of DP-2-2 --mode 1920x1080 xrandr --output DP-2-2 --rotate left --left-of eDP-1 --mode 1920x1080 xinput set-prop 'MOSART Semi. 2.4G Wireless Mouse' 'libinput Natural Scrolling Enabled' 1 xinput set-prop 'Elan Touchpad' 'libinput Natural Scrolling Enabled' 1
Buy this article as PDF
(incl. VAT)