Tm2-touchkey

The tm2-touchkey are the Android touch buttons of some Samsung devices. Here are some information how they can be used.

Key mapping
The current state of key mapping can be checked as follows:
 * Kernel key names by command  (package evtest)
 * xkb key names by  (package xev)
 * Wayland key names by  (package wev)

The default kernel key mapping in the tm2-touchkey driver is  and.

In the device trees of e.g. samsung-a3 & -a5, samsung-klte and samsung-serranove, the kernel keys are set to  and. This is the correct mapping to meet the manufacturers intension. When running Android with this kernel (native or sandboxed), the left touch key  brings up the "recent apps" screen on a short click and splits the screen on a long click. The long click action is configurable in the Android settings.

has a kernel keycode of 580 (0x244). In xkb library this is keycode 588. Keycodes above 255 are not processed in X11 because X11 uses 8 bit keycodes. Therefore,  is not available in X11 UIs. Wayland uses 32 bit keycodes and does not have this limitation. However, the key isn't processed properly in Phosh, some parts of software don't handle it correctly. Also in Plasma Mobile the key can't be used for shortcut assignment.

In postmarketOS, the left touchkey is mapped to  and the right one to   by udev rule. The udev rule gets installed by package and applies to all devices using the tm2-touchkey driver that run on mainline kernel 5.16 or higher. The kernel version limitation is because of the key mapping via udev needing two patches on the tm2-touchkey driver that where implemented in upstream kernel v5.16-rc1. For qcom-msm8916 devices, these patches have been backported to v5.15-msm8916 kernel.

is kernel keycode 139 and xkb keycode 147, therefore available in the UIs. The key has no preset functionality (tested in Phosh, Plasma Mobile, Xfce4, MATE) but is available for assignment in the UIs settings.

A drawback is the behaviour in Waydroid "show-full-ui". The left touch key behaves differently as intended by the manufacturer. A short click calls the menu of the app. A long click calls the "recent apps" screen. The option to change the long click behaviour in the Android settings has no effect. (Additional note: Long click in Phosh seems to have a window focusing problem, it only works if the Waydroid window is not focused, e.g. when hitting the top black bar before. In Plasma Mobile, long click in Waydroid works flawless.)

Overriding the key mapping
The udev rule  can be copied to    and modified there. It will override the default key mapping. The syntax is like the kernel key names without "KEY_" and with lower case. Note that keys beyond kernel keycode 247 (KEY_RFKILL) don't work in X11 and only partially in Phosh and Plasma Mobile due to the limitation described further above (KEY_RFKILL is keycode 255 in xkb library).

Assigning commands to keys
Most user interfaces offer an option to assign commands to keys.
 * In Phosh this is in Settings -> Keyboard -> Keyboard Shortcuts.
 * On Plasma Mobile, the according settings windows need to be called by commands  and  . The fist one is for Application Shortcuts and the second brings up Custom Shortcuts.
 * In Xfce4 some are in Settings -> Keyboard -> Application Shortcuts and some more in Settings -> Window Manager -> Keyboard.

LEDs
The tm2-touchkey LEDs are disabled by default. Permissions are set to allow unpriviliged users (need to be in group ) to turn on/off the LEDs by e.g.  . The configuration is implemented in udev file. To change this configuration, another udev file can be placed to.

More information on LEDs handling can be found at: LEDs.