+ qDebug() << "System supports XI2";
+
+
+ // Now let's listen to keypress events
+ XIEventMask eventmask;
+ unsigned char mask [1] = { 0 }; // will change
+ eventmask.deviceid = XIAllMasterDevices;
+ eventmask.mask_len = sizeof (mask); // in bytes, for whatever reason...
+ eventmask.mask = mask;
+ XISetMask(mask, XI_KeyPress);
+ XISelectEvents (dpy, winId(), &eventmask, 1);
+
+ // finally, grab all focuses
+ int ndevices;
+ XIDeviceInfo* devices = XIQueryDevice(dpy, XIAllMasterDevices, &ndevices);
+ for (int i = 0; i < ndevices; ++i) {
+ if (devices[i].use != XIMasterKeyboard) continue;
+ qDebug() << "Found master keyboard with ID" << devices[i].deviceid;
+ XISetFocus(dpy, devices[i].deviceid, winId(), CurrentTime);
+ }
+ XIFreeDeviceInfo(devices);
+
+ xiInited = true;
+
+ return false;
+ }
+ else if (xiInited && event->type == GenericEvent
+ && event->xcookie.type == GenericEvent && event->xcookie.extension == xiOpcode
+ && event->xcookie.evtype == XI_KeyPress) {
+
+ if (XGetEventData(dpy, &event->xcookie) != True) {
+ qCritical() << "Error getting event data";
+ // FIXME return true;
+ }
+
+ /* Handle XI event */