RawMotion的XInput 2错误(具有较高值的XISelectEvents上的BadValue)

tpgth1q7  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(133)

我正在编写一个纯Xlib应用程序,并希望使用XInput2扩展RawMotion事件。如果我使用XISelectEvents,当我将掩码设置为高于XI_PropertyEvent的任何XI2事件时,就会出现问题。因此,例如,如果我使用XISetMask(mask, XI_Motion);,它可以正常工作,不像XISetMask(mask, XI_RawMotion);。此外,无论传递的deviceid如何,也无论其他事件类型是否设置为mask,都会出现错误。为什么会发生吗
代码示例:

#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>

int main() {
    Display* display = XOpenDisplay(nullptr);

    int screen_num = DefaultScreen(display);

    Window window = XCreateSimpleWindow(
            display,
            RootWindow(display, screen_num),
            0, 0,
            640, 480,
            4,
            16711680,
            WhitePixel(display, screen_num)
    );
    XSelectInput(display, window, KeyPressMask);

    int major_opcode, first_event, first_error;
    XQueryExtension(display, "XInputExtension", &major_opcode, &first_event, &first_error);

    unsigned char mask[XIMaskLen(XI_LASTEVENT)] = {0, };
    XISetMask(mask, XI_RawMotion);

    XIEventMask event_mask;
    event_mask.deviceid = XIAllDevices;
    event_mask.mask_len = sizeof(mask);
    event_mask.mask = mask;

    XISelectEvents(display, window, &event_mask, 1);

    XMapWindow(display, window);
    XFlush(display);

    while (true) {
        XEvent ev;
        XNextEvent(display, &ev);
        if (ev.type == KeyPress && ev.xkey.keycode == 9) {
            break;
        }
    }
    XUnmapWindow(display, window);
    XFlush(display);
    XDestroyWindow(display, window);
    XCloseDisplay(display);
    return 0;
}

字符串
错误:

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  131 (XInputExtension)
  Minor opcode of failed request:  46 ()
  Value in failed request:  0xd
  Serial number of failed request:  16
  Current serial number in output stream:  17

mnemlml8

mnemlml81#

问题是XInput2调用XISelectEvents的原始事件只有在根窗口通过时才有效。

相关问题