简体   繁体   English

QT:在X11EventFilter中未获取XIDeviceEvent数据

[英]QT: Not getting XIDeviceEvent data in X11EventFilter

I have a Qt Application that works fine on Ubuntu 14.04 and Ubuntu 12.04.I need to redirect Touch and button press XEvents to my application. 我有一个Qt应用程序,可以在Ubuntu 14.04和Ubuntu 12.04上正常工作,我需要将Touch和按钮XEvents重定向到我的应用程序。 The piece of code that does this is as follows- 做到这一点的代码如下:

XIEventMask eventmask;
eventmask.deviceid = XIAllMasterDevices;
eventmask.mask_len = XIMaskLen(XI_LASTEVENT);
eventmask.mask = (unsigned char*) calloc(eventmask.mask_len, sizeof(char));
XISetMask(eventmask.mask, XI_TouchBegin);
XISetMask(eventmask.mask, XI_TouchUpdate);
XISetMask(eventmask.mask, XI_TouchEnd);
XISetMask(eventmask.mask, XI_ButtonPress);
XISetMask(eventmask.mask, XI_ButtonRelease);
XISetMask(eventmask.mask, XI_Motion);
printf("Return value from XISelectevents: %d\n",XISelectEvents(QX11Info::display(), viewer->winId(), &eventmask, 1));

The XISelectEvents() function returns 0 which I assume is the return value for success. XISelectEvents()函数返回0,我认为这是成功的返回值。 Then I have a oveeride function bool MainApplication::x11EventFilter(XEvent *event) to process the events. 然后,我有一个oveeride函数bool MainApplication::x11EventFilter(XEvent *event)处理事件。

XEvent ev = *event;
if (ev.xcookie.type == GenericEvent)
{
    //printf("event: %d\n", ev.xcookie.evtype);
    XIDeviceEvent* evData = (XIDeviceEvent*)(ev.xcookie.data);

    int id = 0;
    if(evData != 0)
        id = evData->detail;
    else{
        printf("Device Event data not coming\n");
       // return false;
    }
...

The above code works fine on Ubuntu but on Debian 8 the value of (XIDeviceEvent*)(ev.xcookie.data) is 0. Is there any reason why this shouldn't work on Debian 8? 上面的代码在Ubuntu上可以正常工作,但在Debian 8上, (XIDeviceEvent*)(ev.xcookie.data)值为0。是否有任何原因不能在Debian 8上使用?

I needed to call XGetEventData(QX11Info::display(),ev.xcookie) in order to get the event data. 我需要调用XGetEventData(QX11Info::display(),ev.xcookie)以获得事件数据。 This is what I found out after doing some digging. 这是我进行一些挖掘后发现的。 The cookie is simply a unique ID for every event. Cookie只是每个事件的唯一ID。 The XGenericEventCookie data structure is as follows- XGenericEventCookie数据结构如下-

typedef struct
{
    int            type;         /* of event. Always GenericEvent */
    unsigned long  serial;       /* # of last request processed */
    Bool           send_event;   /* true if from SendEvent request */
    Display        *display;     /* Display the event was read from */
    int            extension;    /* major opcode of extension that caused the event */
    int            evtype;       /* actual event type. */
    unsigned int   cookie;       /* unique event cookie */
    void           *data;        /* actual event data */
} XGenericEventCookie;

Turns out simply retrieving the event retrieves the event cookie with the data pointer NULL. 事实证明,简单地检索事件将使用数据指针NULL检索事件cookie。 XGetEventData has to be called in order to actually claim the cookie. 必须调用XGetEventData才能实际声明cookie。

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

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