问题
I am currently porting one of my applications from Xlib to libxcb and I am having a bit trouble finding informations on the XInput2 extension I use at some point. Is there an XInput2 implementation in libxcb? If yes, where can I find the documentation.
Currently I am having trouble for example with this functions: XIQueryDevice
, XISelectEvents
. These are mainly the functions I use.
Maybe someone can point out the documentation for me or provide me a very small example to get started.
回答1:
You basically have 2 options:
Option 1
Call the regular XI*
Xinput2 functions and poll them in your event loop with a generic event. A event loop would probably look like similar to this:
xcb_generic_event_t *event;
while ((event = xcb_wait_for_event(connection))) {
xcb_ge_generic_event_t *generic_event = (xcb_ge_generic_event_t*)event;
if (generic_event->response_type == XCB_GE_GENERIC && generic_event->extension == xinput_ext_opcode && generic_event->event_type == XI_RawMotion) {
// Handle motion
continue;
}
}
Also take a look at the XCB Protocol Extension API.
Option 2
You can use the xcb_input_*
xcb-xinput extension functions. According to the official documentation:
When XCB added its API style to the mix, it followed the newer style and created a "libxcb"-prefixed library for each extension---libxcb-composite, libxcb-render, etc. Since XCB can generates the API code for an extension automatically from an XML description of the extension protocol, new extension API's are created by simply adding the extension description to the xcb-proto package and rebuilding.
Take a look at the xinput.h header.
来源:https://stackoverflow.com/questions/39363761/convert-from-xlib-to-xcb