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. 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. Then I have a oveeride function bool MainApplication::x11EventFilter(XEvent *event)
to process the events.
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?
I needed to call XGetEventData(QX11Info::display(),ev.xcookie)
in order to get the event data. This is what I found out after doing some digging. The cookie is simply a unique ID for every event. The XGenericEventCookie
data structure is as follows-
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. XGetEventData
has to be called in order to actually claim the cookie.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.