Input: Add in-kernel input events transformation framework
Subsystems (2)
This new driver allows to perform various input events transformations in kernel, e.g. remap one key (or combination) to another key.
The driver uses configfs (/sys/kernel/config/input_xfrm) and includes this small readme:
The transformation files (map, modmap) accept writes in this form:
<+/-> <keycode-map-from> <keycode-map-to>
Plus sign to add, and minus sign to remove an entry. Keycodes can be found in /usr/include/linux/input.h
For example, to remap KEY_LEFTMETA (125) to KEY_LEFTALT (56):
# echo + 125 56 > map Special mappings with a modifier key can be also created. For example, to remap capslock+left to home key: # echo 58 42 > modkeys # echo + 105 102 > modmap The first commands maps KEY_CAPSLOCK (58) to a modifier key, the second command creates the mapping. The second argument (42, which is KEY_LEFTSHIFT) to modkeys specifies the unmodifier key: when pressed together with the modifier key, the mappings will temporary turn off. That is, pressing capslock+leftshift will let use capslock as normal again.
So far it's not possible to switch keys, but if/when needed, it's pretty easy to implement: just need to create a virtual input device, and pass events through it.
Note that the other approach of these transformations would be to export input filters to the userland, then intercept events there, and pass the transformed events back (or to the uinput instance). But this needlessly requires too much efforts for the simple task.
---
It started with opensuse 12.1 -> 12.2 upgrade, when my XKB keyboard setup got broken again.
For years I used a lengthy .xmodmap to remap keys, but the method was always unreliable, i.e. before the upgrade I pretty much knew that I'd need spend hours to fix my keys. Lately I switched to xkbcomp, but as it appears it wasn't a panacea. Latest firefox no longer respect my remappings, while xlib/qt apps still work.
Plus, it appears that some apps can ignore remappings altogether, e.g. running QEMU SDL backend never respected my mappings, which always annoyed me.
http://ix.io/30i -- That was my xkb setup, if anyone interested. It remaps capslock+arrows to home/end/pgup/pgdown, plus win key to alt.
Instead of introducing caps_level2 type I also tried iso level 3 shift, and then firefox seem to understand remappings, but then xlib and Qt apps break. Heh.
With this driver I can remap keys at the lowest possible level, and so it will work everywhere: X11, VTs, SDL, directfb, wayland, etc. It's like remapping keys physically, which is exactly what I want.
p.s. Note that I don't use gnome, so it is not the famous "gnome 3.4 killed my key bindings". :-) Although, maybe it's somehow related, dunno.
drivers/input/misc/Kconfig | 10 + drivers/input/misc/Makefile | 1 + drivers/input/misc/input_xfrm.c | 426 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 437 insertions(+) create mode 100644 drivers/input/misc/input_xfrm.c
drivers/input/misc/Kconfig +10 -0
@@ -600,4 +600,14 @@ config INPUT_XEN_KBDDEV_FRONTEND To compile this driver as a module, choose M here: the module will be called xen-kbdfront. +config INPUT_XFRM + tristate "Input events transformation framework" + depends on CONFIGFS_FS + help + This driver allows to perform various input events transformations + in kernel, e.g. remap one key (or combination) to another key. + + To compile this driver as a module, choose M here: the + module will be called input_xfrm. + endif
drivers/input/misc/Makefile +1 -0
@@ -55,4 +55,5 @@ obj-$(CONFIG_INPUT_UINPUT) += uinput.o obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o +obj-$(CONFIG_INPUT_XFRM) += input_xfrm.o obj-$(CONFIG_INPUT_YEALINK) += yealink.o
drivers/input/misc/input_xfrm.c new file +426 -0
426 lines not on this page · raw message
Signature · 1 line
1.7.11.5