从 Xlib 转换为 xcb

Convert from Xlib to xcb

我目前正在将我的一个应用程序从 Xlib 移植到 libxcb,我在查找有关我有时使用的 XInput2 扩展的信息时遇到了一些麻烦。 libxcb 中是否有 XInput2 实现?如果是,我在哪里可以找到文档。

目前我在使用以下函数时遇到了问题:XIQueryDeviceXISelectEvents。这些主要是我用到的功能

也许有人可以为我指出文档或提供一个非常小的例子让我开始。

你基本上有两个选择:

选项 1

调用常规 XI* Xinput2 函数并在您的事件循环中使用通用事件轮询它们。事件循环可能看起来类似于:

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;
    }
}

也看看XCB Protocol Extension API

选项 2

您可以使用 xcb_input_* xcb-xinput 扩展函数。根据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.

看看xinput.h header