June 15, 2016 - Chris Michael
Elput: A Libinput Abstraction for EFL
Input is something generally taken for granted, but it’s not without issues. While working on a new EFL library for Direct Rendering, the community decided that having the same libinput code duplicated across multiple internal subsystems like Ecore_Fb, Ecore_Drm, etc. would be a great effort to maintain in the future. To reduce this effort, Elput was created.
Elput is a library designed to abstract all the gory details of using libinput, and it provides a central API that can be used to initialize, iterate, and manipulate various input devices found on a system. These can include keyboards, pointers, touch screens, and any other input device that libinput supports.
Elput is also multi-seat aware, meaning that when a new input device gets attached to the system and belongs to a different seat, Elput will automatically create a new seat internally and do any setup required for that new input device to function. This library will also handle udev event processing. This means that when the mouse is moved or a button or keyboard key is pressed, Elput will automatically handle parsing that information from udev and sending out events to let other subsystems know that an input event has occurred. This makes application development easier since it’s possible to setup listeners for these events and to catch keypress events, etc.
Elput is designed to support various system interfaces such as systemd-logind, direct manipulation, or any other type of interface that may be needed in the future. This library provides a general “Manager” that is responsible for getting session and seat information from the system along with any other setup that a given interface may require. Currently, Elput provides an interface with systemd-logind and dbus integration out of the box; other interfaces can be easily added if needed.
The Components of Elput
A typical Elput interface would need to supply pointers to various functions which are required in order to support inputs on a given system. The Elput_Interface structure contains these possible function pointers:
typedef struct _Elput_Interface
Eina_Bool (*connect)(Elput_Manager **manager, const char *seat, unsigned int tty);
void (*disconnect)(Elput_Manager *manager);
int (*open)(Elput_Manager *manager, const char *path, int flags);
void (*open_async)(Elput_Manager *manager, const char *path, int flags);
void (*close)(Elput_Manager *manager, int fd);
Eina_Bool (*vt_set)(Elput_Manager *manager, int vt);
When designing a new Elput_Interface, function pointers should be provided for connect, disconnect, open, and close. Without these functions, an Elput_Interface would be pretty useless since it wouldn’t be possible to connect to the system backend nor open/close any input devices. Function pointers to open_async and vt_set are optional. These 2 functions provide the ability to open an input device asynchronously and switch virtual terminals from code (possibly in reaction to a keybinding).
Elput also provides various API functions to manipulate or retrieve information about an input device, as well as support for manually setting pointer position, left-handed pointer mode, keyboard key remapping, and input device calibration.
With this new library in place, we can now greatly reduce duplicated input code across multiple subsystems. This makes dealing with input much easier and provides one central place where input devices can be handled. There are still some existing subsystems inside EFL that have not been ported to use Elput yet, so we may still need to add some API functions to the Elput library. For this reason, the Elput API is marked as a beta api and may change in the future; as a result, there’s no documentation for this quite yet, but this will be generated once EFL 1.18 is released. For now, if you are interested in trying this out, take a look at the EFL documentation.
About Chris Michael
Chris Michael has been an EFL/Enlightenment developer for over 13 years and is now working for the Samsung Open Souce Group. Among his many ongoing projects include his work to port the Enlightenment Foundation Libraries to the Wayland protocol, porting the Tizen Window Manager to use the Wayland protocol, and writing an IRC client which will function using the Wayland protocol. He has given several talks at various LinuxCon events all around the globe, generally focused on Wayland.
Image Credits: EFL Project