简体   繁体   English

如何使用 libxcb-xinput 注册事件

[英]How to register events using libxcb-xinput

I'm trying to listen to touch events (TOUCH_BEGIN, TOUCH_UPDATE, TOUCH_END and TOUCH_OWNERSHIP) on the root window.我正在尝试侦听根窗口上的触摸事件(TOUCH_BEGIN、TOUCH_UPDATE、TOUCH_END 和 TOUCH_OWNERSHIP)。
Touch events aren't directly integrated into XCB, so I have to use the input extension (libxcb-xinput).触摸事件没有直接集成到 XCB 中,所以我必须使用输入扩展 (libxcb-xinput)。

I already managed to set up an event listener for events coming from the input extension, but I can't figure out how to register what events I want to listen to.我已经设法为来自输入扩展的事件设置了一个事件侦听器,但我不知道如何注册我想要侦听的事件。

I tried using xcb_input_xi_select_events(), however that function takes a parameter of type xcb_input_event_mask_t, while the enum containing the event masks is of type xcb_input_ xi _event_mask_t and there is no obvious way to cast them.我尝试使用 xcb_input_xi_select_events(),但是该函数采用类型为 xcb_input_event_mask_t 的参数,而包含事件掩码的枚举类型为 xcb_input_ xi _event_mask_t 并且没有明显的方法来转换它们。

For that reason I think that xcb_input_xi_select_events() is the wrong function, but I have no idea what function to use instead.出于这个原因,我认为 xcb_input_xi_select_events() 是错误的函数,但我不知道改用什么函数。

My non working code currently looks like that:我的非工作代码目前看起来像这样:

xcb_input_event_mask_t mask[] = {
    XCB_INPUT_XI_EVENT_MASK_TOUCH_BEGIN
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_END
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_UPDATE
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_OWNERSHIP
};
xcb_input_xi_select_events(dpy, root, 4, mask);

The core throws a "large integer implicitly truncated to unsigned type" warning at compile time and just a "Failed request: (null), (null): 0x000000D5" error at runtime.核心在编译时抛出“隐式截断为无符号类型的大整数”警告,并在运行时抛出“失败的请求:(空),(空):0x000000D5”错误。

(I'm pretty new to C and especially XCB, so please forgive any obvious errors) (我对 C 非常陌生,尤其是 XCB,所以请原谅任何明显的错误)

You need to use xcb_input_event_mask_t and xcb_input_xi_event_mask_t together, in the following way:您需要将xcb_input_event_mask_txcb_input_xi_event_mask_t一起使用,方法如下:

struct {
    xcb_input_event_mask_t head;      // describes the subsequent xcb_input_xi_event_mask_t (or an array thereof)
    xcb_input_xi_event_mask_t mask;
} mask;

mask.head.deviceid = XCB_INPUT_DEVICE_ALL;
mask.head.mask_len = sizeof(mask.mask) / sizeof(uint32_t);

mask.mask = XCB_INPUT_XI_EVENT_MASK_TOUCH_BEGIN
| XCB_INPUT_XI_EVENT_MASK_TOUCH_END
| XCB_INPUT_XI_EVENT_MASK_TOUCH_UPDATE
| XCB_INPUT_XI_EVENT_MASK_TOUCH_OWNERSHIP;

xcb_input_xi_select_events(dpy, root, 1, &mask.head);

Disclaimer: I have never used this.免责声明:我从未使用过这个。 I have found one single usage example on the 'net here .我在 'net here上找到了一个单一的用法示例。 I tried to verify this usage against the source of xcb_input_xi_select_events here but its code is expletive deleted unreadable.我试图验证对源这种用法xcb_input_xi_select_events 这里,但它的代码是脏话删除不可读。 I have not a slightest idea how exactly people should be able to use this library.我完全不知道人们应该如何使用这个库。

I found a solution to this.我找到了解决方案。
Big thanks to https://github.com/eemikula/touchwm .非常感谢https://github.com/eemikula/touchwm

const uint32_t mask[] = {
    XCB_INPUT_XI_EVENT_MASK_TOUCH_BEGIN
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_UPDATE
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_END
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_OWNERSHIP
};
const uint32_t modifiers[] = {XCB_INPUT_MODIFIER_MASK_ANY};

xcb_input_xi_passive_grab_device(
    dpy, 
    XCB_CURRENT_TIME, 
    root,
    XCB_CURSOR_NONE,
    0, // detail - as used by XIPassiveGrab
    XCB_INPUT_DEVICE_ALL_MASTER,
    1, // num_modifiers
    1, // mask_len
    XCB_INPUT_GRAB_TYPE_TOUCH_BEGIN,
    XCB_INPUT_GRAB_MODE_22_TOUCH,
    XCB_INPUT_GRAB_MODE_22_ASYNC,
    XCB_INPUT_GRAB_OWNER_NO_OWNER,
    mask,
    modifiers
);

It looks a bit cryptic, but it works.它看起来有点神秘,但它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM