Libinput in asynchronous compositor
I'm writing an asynchronous Wayland compositor. By this I mean that there are no blocking operations. (Some components such as the graphics drivers might perform blocking operations but this is out of my control.) In particular there is no way for me to call out to logind to acquire a device file descriptor without returning to the main loop.
At this point I have written an embedded X backend and I am now trying to write a native backend using libinput. Based on the libinput documentation my first intention was to use a udev context that discovers devices on its own. However, this requires me to call out to logind in the callbacks which is not possible as described above.
Instead, my intention now is to use udev manually to discover devices. Once udev reports a device I call out to logind to take the device. When logind returns successfully, I use a libinput path context to add the device. In the callback I would then look up the file descriptor in my list of opened devices.
I have not yet implemented this but it seems that it should work.
On the other hand, it might be better to enhance the libinput api to better support asynchronous application. For example, instead of using callbacks, libinput could inform the application of devices that need to be opened by providing a new event type. The application could then open the device at its own pace and later call back into libinput with the already opened file descriptor.
Are you aware of other users of libinput that have encountered and solved this problem? Do you think my solution using a path context is workable and future proof? What do you think about my suggested api enhancement?